#could you check if there is an error?

1 messages · Page 1 of 1 (latest)

devout cradle
#

to get the players inventory container you have to use player.getComponent().container
to get every item in the players inventory you have to do a for loop through each slot...

#

I'll provide some code to help you out

chilly tartan
#

I'd really like it, thank you

chilly tartan
wooden spear
#
//return the total amount of specified item the player have in their inventory
export function getTotalItem(player,itemId) {
    const inv = player.getComponent("inventory")?.container;
    if (!inv) return 0
    let count = 0;
    for (let slot=0;slot<inv.size;slot++) {
        const item = inv.getItem(slot);
        if (!item) continue;
        if (item.typeId===itemId)
        count += item.amount;
    }
    return count;
}
#
//check if they have 6 diamonds or more using the function above

if (getTotalItem(player,"minecraft:diamond") >= 6)
//do something