#get player name in EntityEvents
12 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
try event.source.actual.player.username
but you might want to put if (!event.source.actual.isPlayer()) return before that
returns undefined
hmm
i haven't worked with fabric much, you might want to wait a bit longer until someone can help
if youre soley trying to get the username of the player on the entity hurt event then it stands to reason you could also do it the other way around and use the player attack entity forge event ```js
ForgeEvents.onEvent('net.minecraftforge.event.entity.player.AttackEntityEvent', event => global.playerattack(event))
/**
*
- @param {Internal.AttackEntityEvent} event
- @returns
*/
global.playerattack = event => {
//You can edit anything in here and run /kubejs reload startup_scripts to reload without having to do a full game restart!
const {entity,target,entity:{persistentData,username},target:{type}} = event
//This persistent data is important, preventing the event from firing twice
if (persistentData.fireonce != 1){return}
//debug stuff
entity.tell(username)
entity.tell(type)
//here we give the player a diamond for hitting a cow :D
if(type == 'minecraft:cow'){
entity.give('minecraft:diamond')
}
}```
should let you do stuff to the target as you need to
crap im dumb, this is a fabric ticket

it is 🙂