To explain the error in full detail, I have 2 scripts.
- Detects an entity being hurt which checks for the damageSource tag using 'hasTag' for player attacks and checks for the damageSource family using 'hasTypeFamily'
world.afterEvents.entityHurt.subscribe(({ hurtEntity, damageSource: { damagingEntity, damagingProjectile, cause } }) => {
const playerFamily = damagingEntity?.getComponent('minecraft:type_family');
const projectileFamily = damagingProjectile?.getComponent('minecraft:type_family');
if(damagingEntity?.hasTag('player_zero') && playerFamily.hasTypeFamily("player") & cause === "entityAttack" && hurtEntity.typeId == 'test:dummy'){
hurtEntity.runCommand("say I am hit by an ATTACK!");
}
if(projectileFamily?.hasTypeFamily('custom_projectile') && cause === "projectile" && hurtEntity.typeId == 'test:dummy'){
hurtEntity.runCommand("say I am hit by a PROJECTILE!");
}
});