I'm trying to prevent a player's death under the conditions imposed in the code below. The problem is that after being teleported, the player dies and their health and mana are not restored. I've never used onPrepareDeath() properly and I have doubts about why this happens and how to work around it. I thought that just returning false would prevent the player from dying. Here the code
LUA:
function onPrepareDeath(cid, corpse, deathList)
if(not isPlayer(cid)) then
return true
end
for _, area in pairs(areasProctecteds) do
if checkProtectedArea(area[1], area[2], area[3], area[4], area[5], area[6], cid) then
print('MAXHEALTH: '..getCreatureMaxHealth(cid))
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
return false
end
end
return true
end