#How to fix this log spam when I kill a entity with no item equipped in the mainhand slot
1 messages · Page 1 of 1 (latest)
world.afterEvents.entityDie.subscribe((fx) => {
const killer = fx.damageSource.damagingEntity
const killed = fx.deadEntity
if (killer.typeId === "minecraft:player") {
const itemEquipped = killer.getComponent("minecraft:equippable").getEquipment('Mainhand')
if (killed.typeId === "minecraft:player") {
if (itemEquipped.typeId === "fec:tenacity" || itemEquipped.typeId === "fec:tenacity_axe") {
killed.runCommand(`particle fec:tenacity_player_kill_fx ~~0.5~`)
killed.runCommand(`particle fec:tenacity_player_kill_flash ~~0.5~`)
}
} else {
if (itemEquipped.typeId === "fec:tenacity" || itemEquipped.typeId === "fec:tenacity_axe") {
killed.runCommand(`particle fec:tenacity_entity_kill_fx ~~0.5~`)
killed.runCommand(`particle fec:tenacity_entity_kill_flash ~~0.5~`)
}
}
} else return 0;
})
this is my code for that thing
just add ? After itemEquipped
or just add a && itemEquipped after your killed.typeId === "minecraft:player" if
Yeah I was about to say that lmao
Both works tho
wait let me try
idk where I should place the ? thing
I already said it, after the itemEquipped
So kind alike itemEquipped?.typeId === ''
ok that work
on my first try it failed because I didn't add the ? at the second condition of itemEquipped
that's why i asked twice 😐
sorry
thanks for the solution 🙂
"?." is the optional chaining operator, if you want to learn more about it, here.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining