Skip to content

Instantly share code, notes, and snippets.

@salwador
Created November 4, 2020 13:14
Show Gist options
  • Save salwador/bab1a790a5b1ffc0e8067a8a5a74c1fd to your computer and use it in GitHub Desktop.
Save salwador/bab1a790a5b1ffc0e8067a8a5a74c1fd to your computer and use it in GitHub Desktop.
system.listenForEvent(ReceiveFromMinecraftServer.PlayerAttackedEntity,
function(en) {
setTimeout(
function() {
let entity = en.data.attacked_entity;
let entityActor = Actor.fromEntity(entity);
let entityHealth = entityActor.getAttribute(7);
let entityName = entity.__identifier__.substr(11, 64);
entityName = `${entity.__identifier__.substr(10, 1).toUpperCase()}${entityName}`;
let playerEntity = en.data.player;
let playerActor = Actor.fromEntity(playerEntity);
let playerHealth = playerActor.getAttribute(7);
let playerNetwork = playerActor.getNetworkIdentifier();
console.log(`PlayerAttackedEntity => ${entityName}, ${entityHealth} ❤, ${playerNetwork.getAddress()}`);
}, 10
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment