#could you check if there is an error?
1 messages · Page 1 of 1 (latest)
I'd really like it, thank you
.
Documentation: https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/entityinventorycomponent?view=minecraft-bedrock-stable
//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