• 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!

TFS 0.X onPrepareDeath; player dont die.

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
580
Solutions
2
Reaction score
58
Location
México
Hello, otlanders. im facing a problem trying a revive system with storages.
The script is suposse to work like this (green txt is achieved one, red is not):
-if "dies"(prepare death) and player have storage 9999 > 1 then
player teleport to a sanctuary.
after teleport, get heal

and after 5 seconds; player teleport back to death pos (i need help getting back)
player set storage 0
end

if player dies with storage 9999 < 1 then

player have 5 seconds to receive help (with special item that adds heal) <-- im working on it
if player wont get help then
player dies (here is the problem. the player wont die, just stay with 0 hp) <-- im getting crazy

end


And this is the script for tfs 0.4
Lua:
local config = {
    storage = 9999, --Use empty storage
    outfit = {lookType = 0}, --still working on the to turn into dead body
    time = 5, --How long will it take until he revives from the death
    text = "You will be revived in 5 seconds" --The text which appear when his dead
}

function onPrepareDeath(cid, deathList)
   if isPlayer(cid) and getPlayerStorageValue(cid, 9999) < 1 then
    -- "Create dead body, that can be healed with  doCreatureAddHealth(cid, getCreatureMaxHealth(cid))"
      addEvent(function()
   --doRemoveCreature(cid) <-- this must be replaced for something that make the player dies...
           end, 5*1000)
      print(0)
   
   end
function revive(cid)
    if isPlayer(cid) and getPlayerStorageValue(cid, config.storage) == 1 then
      print(1)
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
        doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
        doCreatureSetNoMove(cid, false)
        setPlayerStorageValue(cid, config.storage, 1)
        --doTeleportThing(cid, {x = 1073, y = 135, z = 10})
        return true
    end
end

function revivetext(cid)
   print(2)
    if isPlayer(cid) and getPlayerStorageValue(cid, config.storage) == 1 then
        doPlayerSendTextMessage(cid,21, config.text)
        addEvent(revive, config.time*1000, cid)
        return true
    end
end

    if isPlayer(cid) and getPlayerStorageValue(cid, config.storage) == 1 then
      print(3)
        if getCreatureHealth(cid) <= 0 then
            addEvent(revivetext, 1*1000, cid)
            doCreatureSetNoMove(cid, true)
            setPlayerStorageValue(cid, config.storage, -1)
            doCreatureChangeOutfit(cid, config.outfit)
            doAddCondition(cid, CONDITION_INFIGHT)
            return false
        end
    return true
    end
end
 
Solution
So it dies..I wonder why, another try (?

Code:
local config = {
    storage = 9999, --Use empty storage
    outfit = {lookType = 0}, --still working on the to turn into dead body
    time = 5, --How long will it take until he revives from the death
    text = "You will be revived in 5 seconds", --The text which appear when his dead
    sanctuaryPos = {x = , y = , z = }
}

function storageRevive(cid, originalPos)
    if isPlayer(cid) then
        doCreatureSetNoMove(cid, false)
        doTeleportThing(cid, originalPos)
        doSendMagicEffect(originalPos, CONST_ME_TELEPORT)
        return true
    else
        return false
    end
end

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) and value ==...
So it dies..I wonder why, another try (?

Code:
local config = {
    storage = 9999, --Use empty storage
    outfit = {lookType = 0}, --still working on the to turn into dead body
    time = 5, --How long will it take until he revives from the death
    text = "You will be revived in 5 seconds", --The text which appear when his dead
    sanctuaryPos = {x = , y = , z = }
}

function storageRevive(cid, originalPos)
    if isPlayer(cid) then
        doCreatureSetNoMove(cid, false)
        doTeleportThing(cid, originalPos)
        doSendMagicEffect(originalPos, CONST_ME_TELEPORT)
        return true
    else
        return false
    end
end

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) and value == getCreatureHealth(cid) and getPlayerStorageValue(cid, config.storage) == 1 then
            local originalPos = getThingPosition(cid)
            doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
            doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
            doTeleportThing(cid, config.sanctuaryPos)
            doPlayerSendTextMessage(cid,21, config.text)
            setPlayerStorageValue(cid, config.storage, 0)
            doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
            doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
            doCreatureSetNoMove(cid, true)
            addEvent(storageRevive, config.time * 1000, cid, originalPos)
            return false
    end
return true
end
 
Solution
So it dies..I wonder why, another try (?

Code:
local config = {
    storage = 9999, --Use empty storage
    outfit = {lookType = 0}, --still working on the to turn into dead body
    time = 5, --How long will it take until he revives from the death
    text = "You will be revived in 5 seconds", --The text which appear when his dead
    sanctuaryPos = {x = , y = , z = }
}

function storageRevive(cid, originalPos)
    if isPlayer(cid) then
        doCreatureSetNoMove(cid, false)
        doTeleportThing(cid, originalPos)
        doSendMagicEffect(originalPos, CONST_ME_TELEPORT)
        return true
    else
        return false
    end
end

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) and value == getCreatureHealth(cid) and getPlayerStorageValue(cid, config.storage) == 1 then
            local originalPos = getThingPosition(cid)
            doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
            doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
            doTeleportThing(cid, config.sanctuaryPos)
            doPlayerSendTextMessage(cid,21, config.text)
            setPlayerStorageValue(cid, config.storage, 0)
            doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
            doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
            doCreatureSetNoMove(cid, true)
            addEvent(storageRevive, config.time * 1000, cid, originalPos)
            return false
    end
return true
end
oh boy, seems it work nice! now im gonna make a spell that gives revival :D thank you very much boy

btw, do you know what was wrong? so i try to avoid these embarrassing scripting kek
 
There's more.

Code:
local config = {
    storage = 9999, --Use empty storage
    outfit = {lookType = 0}, --still working on the to turn into dead body
    time = 5, --How long will it take until he revives from the death
    text = "You will be revived in 5 seconds", --The text which appear when his dead
    sanctuaryPos = {x = , y = , z = }
}

function storageRevive(cid, originalPos)
    if isPlayer(cid) then
        doCreatureSetNoMove(cid, false)
        doTeleportThing(cid, originalPos)
        doSendMagicEffect(originalPos, CONST_ME_TELEPORT)
        return true
    else
        return false
    end
end

function deadMan(cid, originalPos)
    if isPlayer(cid) then
        doPlayerSetGroupId(cid, 1)
        doCreatureSetNoMove(cid, false)
        doCreatureAddHealth(cid, -getCreatureHealth(cid), 65535, 256, true)
        doSendMagicEffect(originalPos, CONST_ME_DRAWBLOOD)
        return true
    else
        return false
    end
end

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) and value == getCreatureHealth(cid) and getPlayerStorageValue(cid, config.storage) == 1 then
        local originalPos = getThingPosition(cid)
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
        doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
        doTeleportThing(cid, config.sanctuaryPos)
        doPlayerSendTextMessage(cid,21, config.text)
        setPlayerStorageValue(cid, config.storage, 0)
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
        doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
        doCreatureSetNoMove(cid, true)
        addEvent(storageRevive, config.time * 1000, cid, originalPos)
        return false
    elseif isPlayer(cid) and value == getCreatureHealth(cid) and getPlayerStorageValue(cid, config.storage) <= 0 then
        local originalPos = getThingPosition(cid)
        doCreatureAddHealth(cid, 1, 65535, 256, true)
        doCreatureSetNoMove(cid, true)
        doCreatureChangeOutfit(cid, config.outfit)
        doAddCondition(cid, CONDITION_INFIGHT)
        doPlayerSetGroupId(cid, 7)
        addEvent(deadMan, config.time * 1000, cid, originalPos)
    end
return true
end

Then add this group to data/xml/groups.xml
Code:
<group id="7" name="Dead Player" flags="3808558964575" customFlags="257215"/>

Should work, monster shouldn't be able to attack you and such, the only thing is that if server crashes or anything between those 5 seconds, the player will retain that groupId
You should add a check to login.lua, if player group is 7 then change it to 1. (As 7 only means the full script didn't get to run)
Also, for the spell, you only need to stop that event from happening (deadMan), restore the player's group ID to 1 and set his noMove to false so he can walk again

--EDIT--
What was wrong is what @Xikini pointed us out. Using onPrepareDeath was not the way to tackle this type of script that you required. Big thanks to him! I would encourage you to mark his post as best answer, else we would be still trying to fix something that was wrong from the very start.

On a sidenote, I know for sure this isn't the best solution (GroupIds and the like)
 
There's more.

Code:
local config = {
    storage = 9999, --Use empty storage
    outfit = {lookType = 0}, --still working on the to turn into dead body
    time = 5, --How long will it take until he revives from the death
    text = "You will be revived in 5 seconds", --The text which appear when his dead
    sanctuaryPos = {x = , y = , z = }
}

function storageRevive(cid, originalPos)
    if isPlayer(cid) then
        doCreatureSetNoMove(cid, false)
        doTeleportThing(cid, originalPos)
        doSendMagicEffect(originalPos, CONST_ME_TELEPORT)
        return true
    else
        return false
    end
end

function deadMan(cid, originalPos)
    if isPlayer(cid) then
        doPlayerSetGroupId(cid, 1)
        doCreatureSetNoMove(cid, false)
        doCreatureAddHealth(cid, -getCreatureHealth(cid), 65535, 256, true)
        doSendMagicEffect(originalPos, CONST_ME_DRAWBLOOD)
        return true
    else
        return false
    end
end

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) and value == getCreatureHealth(cid) and getPlayerStorageValue(cid, config.storage) == 1 then
        local originalPos = getThingPosition(cid)
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
        doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
        doTeleportThing(cid, config.sanctuaryPos)
        doPlayerSendTextMessage(cid,21, config.text)
        setPlayerStorageValue(cid, config.storage, 0)
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
        doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
        doCreatureSetNoMove(cid, true)
        addEvent(storageRevive, config.time * 1000, cid, originalPos)
        return false
    elseif isPlayer(cid) and value == getCreatureHealth(cid) and getPlayerStorageValue(cid, config.storage) <= 0 then
        local originalPos = getThingPosition(cid)
        doCreatureAddHealth(cid, 1, 65535, 256, true)
        doCreatureSetNoMove(cid, true)
        doCreatureChangeOutfit(cid, config.outfit)
        doAddCondition(cid, CONDITION_INFIGHT)
        doPlayerSetGroupId(cid, 7)
        addEvent(deadMan, config.time * 1000, cid, originalPos)
    end
return true
end

Then add this group to data/xml/groups.xml
Code:
<group id="7" name="Dead Player" flags="3808558964575" customFlags="257215"/>

Should work, monster shouldn't be able to attack you and such, the only thing is that if server crashes or anything between those 5 seconds, the player will retain that groupId
You should add a check to login.lua, if player group is 7 then change it to 1. (As 7 only means the full script didn't get to run)
Also, for the spell, you only need to stop that event from happening (deadMan), restore the player's group ID to 1 and set his noMove to false so he can walk again

--EDIT--
What was wrong is what @Xikini pointed us out. Using onPrepareDeath was not the way to tackle this type of script that you required. Big thanks to him! I would encourage you to mark his post as best answer, else we would be still trying to fix something that was wrong from the very start.

On a sidenote, I know for sure this isn't the best solution (GroupIds and the like)
thats why i added a teleport to sanctuary, setgroup is not the best way because player needs to logoff in order to reload the groupid to 1, also the script kills the player after teleport XD
 
Try this one and see if the errors stop

Code:
local config = {
    storage = 9999, --Use empty storage
    outfit = {lookType = 0}, --still working on the to turn into dead body
    time = 5, --How long will it take until he revives from the death
    text = "You will be revived in 5 seconds", --The text which appear when his dead
    sanctuaryPos = {x = , y = , z = }
}

function storageRevive(cid, originalPos)
    if isPlayer(cid) then
        doCreatureSetNoMove(cid, false)
        doTeleportThing(cid, originalPos)
        doSendMagicEffect(originalPos, CONST_ME_TELEPORT)
        return true
    else
        return false
    end
end

function deadMan(cid, originalPos)
    if isPlayer(cid) then
        doPlayerSetGroupId(cid, 1)
        doCreatureSetNoMove(cid, false)
        doCreatureAddHealth(cid, -getCreatureHealth(cid), 65535, 256, true)
        doSendMagicEffect(originalPos, CONST_ME_DRAWBLOOD)
        return true
    else
        return false
    end
end

function onStatsChange(cid, attacker, type, combat, value)
    if not isPlayer(cid) then
    return true
    end

    if isPlayer(cid) and value == getCreatureHealth(cid) and getPlayerStorageValue(cid, config.storage) == 1 then
        local originalPos = getThingPosition(cid)
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
        doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
        doTeleportThing(cid, config.sanctuaryPos)
        doPlayerSendTextMessage(cid,21, config.text)
        setPlayerStorageValue(cid, config.storage, 0)
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
        doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
        doCreatureSetNoMove(cid, true)
        addEvent(storageRevive, config.time * 1000, cid, originalPos)
        return false
    elseif isPlayer(cid) and value == getCreatureHealth(cid) and getPlayerStorageValue(cid, config.storage) <= 0 then
        local originalPos = getThingPosition(cid)
        doCreatureAddHealth(cid, 1, 65535, 256, true)
        doCreatureSetNoMove(cid, true)
        doCreatureChangeOutfit(cid, config.outfit)
        doAddCondition(cid, CONDITION_INFIGHT)
        doPlayerSetGroupId(cid, 7)
        addEvent(deadMan, config.time * 1000, cid, originalPos)
        return false
    end
end

thats why i added a teleport to sanctuary, setgroup is not the best way because player needs to logoff in order to reload the groupid to 1, also the script kills the player after teleport XD
Yes but you don't want them to get teleported if they don't have the storage, they MUST be waiting at that position to revive or die.
 
i guess i fixed it... no errors in console and works good, hope this is the final solution x.x

Lua:
function storageRevive(cid, originalPos)
    if isPlayer(cid) then
        doCreatureSetNoMove(cid, false)
        doTeleportThing(cid, originalPos)
        doSendMagicEffect(originalPos, CONST_ME_TELEPORT)
        return true
    else
        return false
    end
end

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) and value == getCreatureHealth(cid) and getPlayerStorageValue(cid, config.storage) == 1 then
            local originalPos = getThingPosition(cid)
            local playeroutfit = getCreatureOutfit(cid)
            addEvent(doCreatureChangeOutfit, 100, cid, config.outfit)
            addEvent(doCreatureChangeOutfit, config.time * 1000, cid, playeroutfit)
            doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
            doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
            doTeleportThing(cid, config.sanctuaryPos)
            doPlayerSendTextMessage(cid,21, config.text)
            setPlayerStorageValue(cid, config.storage, 0)
            doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
            doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
            doCreatureSetNoMove(cid, true)
            addEvent(storageRevive, config.time * 1000, cid, originalPos)
            return false
    end
return true
end
 
Need something like this to avoid loggin out causing that player have to open backpacks over and over for tfs 1.5
Lua:
function creatureevent.onPrepareDeath(player, killer)
 
    if player:getHealth() == 0 then
    player:teleportTo(town:getTemplePosition())
    doTeleportThing(isPlayer, getTownTemplePosition(getPlayerTown(isPlayer)))
        creature:setStorageValue(storage, 0)
        creature:setSkullTime(0)
        creature:setSkullTime(SKULL_NONE)
        creature:addSoul(-100)
    end
        return true
    end
all works but player are dying and not being teleported
Code:
--agregado war changemap
local config = {
    townIds = {
        [1] = "Thais",
        [2] = "Edron",
        [3] = "Carlin",
        [4] = "Venore"
    },

    globalStorage = 100
}
function onThink(interval, lastExecution)
    local players = Game.getPlayers()
    if #players == 0 then
        return true
    end

    Game.setStorageValue(config.globalStorage, math.max(1, Game.getStorageValue(config.globalStorage) or 1) + 1)

    local towns = config.townIds[Game.getStorageValue(config.globalStorage)]
    if not towns then
        Game.setStorageValue(config.globalStorage, 1)
        towns = config.townIds[Game.getStorageValue(config.globalStorage)]
    end

    local position, player = Town(Game.getStorageValue(config.globalStorage)):getTemplePosition()
    for i = 1, #players do
        player = players[i]
        player:teleportTo(position)
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "The map has been changed to ".. towns .." and all players have been teleported to the respective temple. Next map change will be in 30 minutes!")
    end

    position:sendMagicEffect(CONST_ME_TELEPORT)
    print("The map has been changed to ".. towns .." and all players have been teleported to the respective  temple. Next map change will be in 30 minutes!")
    return true
end
have this enabled at globalevents and this might be causing problem, my server is tfs 1.5
 
Back
Top