#How can I add hearts to a player after they kill a mob or hostile mob?

33 messages · Page 1 of 1 (latest)

tropic canopy
#

I have a mod that has an effect that hurts you when you attack mobs, I want to use this effect but in reverse add hearts when killing mobs

quiet doveBOT
#

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

drowsy prawn
ocean bisonBOT
tropic canopy
#

will this heal or grant extra hearts?

drowsy prawn
#

or if you mean heal instead, there's also a player.heal method

#

And you can get the player causing entity death in EntityEvents.death with sth like
let killer = event.source?.player

#

the killer might be null or undefined if the death is not caused by a player

tropic canopy
#

will this go in startup script

drowsy prawn
#

it's server one

tropic canopy
#

so it didn't crash my game but didn't heal me either when equipped

ocean bisonBOT
#

Paste version of leeching.js from @tropic canopy

paper barn
#

try debugging with a console.log() inside the if

#

see if it triggers

tropic canopy
#

not sure exactly how to do that

drowsy prawn
tropic canopy
drowsy prawn
#

oh wait

#

it shouldn't be event.player here

#

there should be error about player being undefined

#

change the line 02 to killer.nbt

#

line 07 to killer.heal

#

insert one line
if(!killer) return; between the current line02 and line03.

tropic canopy
ocean bisonBOT
#

Paste version of leeching.js from @tropic canopy

drowsy prawn
# tropic canopy Like this

not right place to insert the line.
The null check is to prevent errors when an entity dies to things other than a player

#

but i think it should heal now

tropic canopy
#

i couldn't get it to work but I think I see where I placed it wrong, atleast I hope so, I'll work on this a bit more tomorrow its extremely late where Im at

ocean bisonBOT
#

Paste version of leeching.js from @tropic canopy

drowsy prawn
#
EntityEvents.death(event => {
    let killer = event.source?.player
    if(!killer) return;
    let curios = killer.nbt.ForgeCaps['curios:inventory'];
    let hasLeechingAmulet = curios.toString().contains("kubejs:leeching_amulet");
    if (!hasLeechingAmulet) return;
    killer.heal(6)
})
tropic canopy
#

oh ok i see, thank you for helping out, hopefully I can use this same formula to add a item drop chance for other amulets im currently working on