#How can I add hearts to a player after they kill a mob or hostile mob?
33 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
you can do sth like this to manipulate maxhealth
#1360331556102864987 message
[➤](#1360331556102864987 message)
ItemEvents.foodEaten(event => {
if (event.item.id === 'kubejs:fruit_of_eternal_life') {
if (event.player) {
event.player.maxHealth += 2;
}
}
});
will this heal or grant extra hearts?
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
will this go in startup script
it's server one
so it didn't crash my game but didn't heal me either when equipped
Paste version of leeching.js from @tropic canopy
not sure exactly how to do that
it should be .heal(6)
oh thank you, unfortunately it still isn't healing me when killing a mob
how does the log say
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.
Like this
Paste version of leeching.js from @tropic canopy
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
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
Paste version of leeching.js from @tropic canopy
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)
})
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