#How to detect when a player is attacked by a player with a tag?

1 messages · Page 1 of 1 (latest)

visual osprey
#

Please

lucid tide
#

Im still learning but would the EntityHitEntityAfterEvent Class do? It will give info about the hit entity and the attacking entity. You can check the entities' attributes there.

heady turret
# visual osprey Please

Here's an example with the entityHitEntity Event Listener.

import { world } from "@minecraft/server";

const attackerTag = "attacker";

world.afterEvents.entityHitEntity.subscribe(evd => {
  const { damagingEntity, hitEntity } = evd;

  // This returns if damagingEntity or hitEntity isn't a player.
  if (damagingEntity.typeId !== "minecraft:player" || hitEntity.typeId !== "minecraft:player") return;

  // If damagingEntity has the attackerTag, then it will run the code.
  if (damagingEntity.hasTag(attackerTag)) {
    world.sendMessage(`${hitEntity.nameTag} §7was attacked by §r${damagingEntity.nameTag} §7with the §r${attackerTag} §7tag.`);
  }
});
visual osprey
#

Thanks

visual osprey