Hey, I need help with a script. I want the script to work as follows:
When the player attacks an entity, and he is holding a specific item, run a command on the entity and a command on the player...
world.afterEvents.entityHurt.subscribe((data) => {
if (data.damageSource.damagingEntity.typeId == 'minecraft:player') {
const attacker = data.damageSource.damagingEntity;
if (attacker.getComponent("minecraft: inventory").container.getItem(attacker.selectedSlot).typeId == 'minecraft:iron_sword') {
attacker.runCommandAsync("scoreboard players set @s ptw_atk_cd 12");
const target = data.hurtEntity;
target.runCommandAsync("kill @s");
};
};
});
I tried to use this code I made, but item detection didn't work.