#How to detect when a player is attacked by a player with a tag?
1 messages · Page 1 of 1 (latest)
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.
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.`);
}
});
Thanks
I didn't see your message, sorry, that was what I was looking for hahahaha
I know the least about Minecraft scripts, with this information I could try to do it myself.