#Get entity, source, and player, on entity kill

5 messages · Page 1 of 1 (latest)

amber gyro
#

Hi Folks, I'm currently trying to build a function that will apply some NBT changes to items in a players inventory, on kill of certain entities, when using a certain tool.

I've been able to get the entity & damage source without any issues but I cannot work out how to get the player instance successfully.

This is what I have currently:

const addSoulsOnKill = (event) => {
  const entity = event.getEntity().type
  if ( entity === "player") return

  const source = event.getSource().type
  if (source !== "player") return

  const player = event.getPlayer() ?? event.getSource().getPlayer()
  // Error occurred while handling event 'EntityEvents.death': TypeError: dev.latvian.mods.rhino.Undefined@0 is not a function, it is undefined.
  // have also tried event.getServer().getPlayer() but get a similar error
  
}

EntityEvents.death(event => {
  addSoulsOnKill(event)
}
spring terraceBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

undone moth
#

try event.source.actual

#

that's what i'm doing in my 1.18 script that tampers with deaths, there's a decent chance it's the same in 1.19

amber gyro
#

Confirmed, that worked perfectly for me in 1.19.2