1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Handle lua entity HP changes correctly (like punches)

fixes #11975
This commit is contained in:
sfan5 2022-05-26 21:32:51 +02:00
parent 85c824ed13
commit 303329f2d6
2 changed files with 21 additions and 10 deletions

View file

@ -337,19 +337,9 @@ u32 LuaEntitySAO::punch(v3f dir,
if (result.did_punch) {
setHP((s32)getHP() - result.damage,
PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher));
// create message and add to list
sendPunchCommand();
}
}
if (getHP() == 0 && !isGone()) {
clearParentAttachment();
clearChildAttachments();
m_env->getScriptIface()->luaentity_on_death(m_id, puncher);
markForRemoval();
}
actionstream << puncher->getDescription() << " (id=" << puncher->getId() <<
", hp=" << puncher->getHP() << ") punched " <<
getDescription() << " (id=" << m_id << ", hp=" << m_hp <<
@ -402,6 +392,20 @@ std::string LuaEntitySAO::getDescription()
void LuaEntitySAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
{
m_hp = rangelim(hp, 0, U16_MAX);
sendPunchCommand();
if (m_hp == 0 && !isGone()) {
clearParentAttachment();
clearChildAttachments();
if (m_registered) {
ServerActiveObject *killer = nullptr;
if (reason.type == PlayerHPChangeReason::PLAYER_PUNCH)
killer = reason.object;
m_env->getScriptIface()->luaentity_on_death(m_id, killer);
}
markForRemoval();
}
}
u16 LuaEntitySAO::getHP() const