#Count how many items of a tag?

1 messages · Page 1 of 1 (latest)

grizzled flicker
#

I'm trying to make a scoreboard that sets it's number to the number of items with a certain tag the player has, how should I do this?

grizzled flicker
#
function typeIdAmountInContainer(container, hasTag) {
    let output = 0;
    for (let i = 0; i < container.size; i++) {
        const itemStack = container.getItem(i);
        if (itemStack?.hasTag !== hasTag) continue;
        output += itemStack.amount; 
    }
    return output;
}


system.runInterval(() => {
    world.getAllPlayers().forEach(player => {
            typeIdAmountInContainer(player.getComponent("inventory").container, "ec:cyberware");
            if (typeIdAmountInContainer > 5) {
                player.addEffect("wither", 21, { amplifier: 1 })
            }
    })
}, 20)