#Strugglin to detect an item in inventory <Resolved>
1 messages · Page 1 of 1 (latest)
instead of return use continue so it can keep looping through
return kind of just stops the whole loop after it sees the first slot as a different item
world.events.entityHitEntity.subscribe(({ sourceEntity, id }) => {
const view = sourceEntity.getViewDirection();
if (sourceEntity) {
switch (id) {
case 'cl:weapon_shot': {
} break;
case 'cl:reload_full': {
const magType = sourceEntity.getProperty('scp:mag_type');
const container = sourceEntity.getComponent('inventory').container;
for (let i = 0; i < container.size; i++) {
const getAmmoSlot = container.getItem(i);
console.warn(`Container: ${container.size}, ${i}`);
if (getAmmoSlot?.typeId === 'scp:ammol') {
sourceEntity.startItemCooldown('ak', (magType == 0 ? (20 * (akStats.reloadTime)) : (2)));
world.playSound(magType == 0 ? 'ak.reload.full' : 'ak.reload.drum.full', sourceEntity);
sourceEntity.setProperty('scp:reload', true);
;
getAmmoSlot.amount -= magType == 0 ? 1 : 2;
if (getAmmoSlot.amount <= 0) container.setItem(i, undefined);
else container.setItem(i, getAmmoSlot);
const obj = world.scoreboard.getObjective(akStats.scoreboardId) ?? world.scoreboard.addObjective(akStats.scoreboardId);
obj.setScore(sourceEntity, magType);
system.runTimeout(() => sourceEntity.setProperty('scp:reload', false), 2);
} else continue;
}
} break;
}
}
});```
Thank U 😄