• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua How to prevent a players death?

darkshin

New old member
Joined
Dec 14, 2010
Messages
231
Reaction score
22
Hello Guys,

Ive trying to prevent a players death based on a storage, but I just can't make this work. I use TFS 1.2.
When the player dies, the print I've made to check if its being called doesn't even is showed in serv console.
How can this work?
Here is the script so far:
Code:
TRY 1:
function onPrepareDeath(cid)
    print("TRIED TO SAVE")
    if cid:getStorageValue(6666) == 1 then
    local position = {x = 1052, y = 1465, z = 7 }
    doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
    doTeleportThing(cid, position)
    doRemoveCreature(cid)
    return false
    else
    return true
    end
end

TRY2:
function onHealthChange(cid)
         print("TRIED TO SAVE")

    if cid:getStorageValue(6666) == 1 then
    local position = {x = 1052, y = 1465, z = 7 }
   
    if cid:getHealth() <= 1 then
    doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
    doTeleportThing(cid, position)
    doRemoveCreature(cid)
    return false
    end
    end

    return true
end
 
you have not registered the scripts in creaturescripts.xml
<event type="preparedeath" name="onPrepareDeath" script="prevent_death.lua" />

Ive did..


If I understood correctly your script (very nice by the way), If I config to drop corpse and drop loot to false, it will only teleport the player to a Position, in the script case it gets the Temple pos. Also, I just have to edit to check if It has the storage I need, ins't it ?
 
<event type="preparedeath" name="onPrepareDeath" script="prevent_death.lua" />

Ive did..
if you have names written correctly and you have registered the event on player then you should get the print (player:registerEvent("onPrepareDeath"))
 
<event type="preparedeath" name="onPrepareDeath" script="prevent_death.lua" />

Ive did..



If I understood correctly your script (very nice by the way), If I config to drop corpse and drop loot to false, it will only teleport the player to a Position, in the script case it gets the Temple pos. Also, I just have to edit to check if It has the storage I need, ins't it ?
Does not matter if you put corpse or Loot on false or true. It will still teleport you to Temple, before death.
 
Everything is fine, just not working... strange..
then its not fine xD

Ok so you have:
1. correct names.
2. registered event in creaturescripts
3. registered event on player
4. correct path to file
Then only thing you havent done is reload server.
If you still don't get print.
go over these 5 steps until it does give you the print
 
then its not fine xD

Ok so you have:
1. correct names.
2. registered event in creaturescripts
3. registered event on player
4. correct path to file
Then only thing you havent done is reload server.
If you still don't get print.
go over these 5 steps until it does give you the print

Oh wait, I thin I didn't registered event on player. How I do that?
 
onpreparedeath doesn't mean ondeath will stop executing.
it might crash because you remove player before its done with scripts.
but then again who knows. no clue what these functions do you use .
 
onpreparedeath doesn't mean ondeath will stop executing.
it might crash because you remove player before its done with scripts.
but then again who knows. no clue what these functions do you use .

Its crashing at canSeeCreature, at creature.cpp. Strangely, when it tries to check if the target creature is invisible (after its dead), it crashes.
 
@whitevo , @Printer : Is there anyway to prevent the player from logging out after he dies?
huh? where did you get these scripts in first place. Clearly you didn't do them.
doRemoveCreature(cid)
My only guess this function is this:
Code:
function doRemoveCreature(cid)
local creature= Creature(cid)
if creature then creature:remove() end
end
What it does is: removes a player from game. For user it means it forces log out.
 
huh? where did you get these scripts in first place. Clearly you didn't do them.

My only guess this function is this:
Code:
function doRemoveCreature(cid)
local creature= Creature(cid)
if creature then creature:remove() end
end
What it does is: removes a player from game. For user it means it forces log out.

I've just used a random script as base, I thought that RemoveCreature meant that he would be removed from his pos. LOL xD. Btw I fixed the crash

EDIT: Its working now as I wanted. BIG THANKS @whitevo
 

Similar threads

Back
Top