• 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 onPrepareDeath problem

Moj mistrz

Monster Creator
Joined
Feb 1, 2008
Messages
932
Solutions
10
Reaction score
295
Location
Poland
Hiho, here's the code and problem it makes. I hope someone will help me out in solution :).
Code:
local condition = createConditionObject(CONDITION_REGENERATION)
setConditionParam(condition, CONDITION_PARAM_SUBID, 88888)
setConditionParam(condition, CONDITION_PARAM_TICKS, 15 * 60 * 1000)
setConditionParam(condition, CONDITION_PARAM_HEALTHGAIN, 0.01)
setConditionParam(condition, CONDITION_PARAM_HEALTHTICKS, 15 * 60 * 1000)

function onPrepareDeath(cid, lastHitKiller, mostDamageKiller)
    if isCreature(cid) == true and getCreatureName(cid) == "Zushuka" then
        if getCreatureCondition(cid, CONDITION_REGENERATION, 88888) == false then
            doAddCondition(cid, condition)
        local hp = math.random(7500, 7515)
            doCreatureAddHealth(cid, hp)
            return false
        end
    else
        return false
    end
    return true
end
So when creature reach 0 hp the script heals it once for 7500-7515 hp and it adds and exhaustion for using this again for next 15 mins, but the problem starts just after creature is healed once. Its hp cannot be downgraded to 0(means it cannot die), when it has for example 4k hp left and I will use spell which could damage it for 5k I wont damage it at all.
Thanks for any help.
 
Try this:

Code:
function onPrepareDeath(cid, lastHitKiller, mostDamageKiller)
local STORAGE = 7500 -- Storage used for exhaustion of this ability
local exhtime = 15*60 -- Exhaustion time (in seconds)
local hp = math.random(7500, 7515) -- Amount of healed HP

    if isCreature(cid) == true and getCreatureName(cid) == "Zushuka" then
        if not(exhaustion.check(cid,STORAGE)) then
        exhaustion.set(cid, STORAGE, exhtime)
        doCreatureAddHealth(cid, hp)   
        end 
    else
    return false
    end
   
return true
end
 
Try this:

Code:
function onPrepareDeath(cid, lastHitKiller, mostDamageKiller)
local STORAGE = 7500 -- Storage used for exhaustion of this ability
local exhtime = 15*60 -- Exhaustion time (in seconds)
local hp = math.random(7500, 7515) -- Amount of healed HP

    if isCreature(cid) == true and getCreatureName(cid) == "Zushuka" then
        if not(exhaustion.check(cid,STORAGE)) then
        exhaustion.set(cid, STORAGE, exhtime)
        doCreatureAddHealth(cid, hp)  
        end
    else
    return false
    end
  
return true
end
MEk-xph0.png

I'm using TFS 1.0 if it means anything.
 
MEk-xph0.png

I'm using TFS 1.0 if it means anything.
It cannot find exhaustion (nil value), add this to your global.lua
Code:
exhaustion =
{
    check = function (cid, storage)
        if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
            return false
        end

        return getPlayerStorageValue(cid, storage) >= os.time()
    end,

    get = function (cid, storage)
        if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
            return false
        end

        local exhaust = getPlayerStorageValue(cid, storage)
        if(exhaust > 0) then
            local left = exhaust - os.time()
            if(left >= 0) then
                return left
            end
        end

        return false
    end,

    set = function (cid, storage, time)
        setPlayerStorageValue(cid, storage, os.time() + time)
    end,

    make = function (cid, storage, time)
        local exhaust = exhaustion.get(cid, storage)
        if(not exhaust) then
            exhaustion.set(cid, storage, time)
            return true
        end

        return false
    end
}
 
It cannot find exhaustion (nil value), add this to your global.lua
Code:
exhaustion =
{
    check = function (cid, storage)
        if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
            return false
        end

        return getPlayerStorageValue(cid, storage) >= os.time()
    end,

    get = function (cid, storage)
        if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
            return false
        end

        local exhaust = getPlayerStorageValue(cid, storage)
        if(exhaust > 0) then
            local left = exhaust - os.time()
            if(left >= 0) then
                return left
            end
        end

        return false
    end,

    set = function (cid, storage, time)
        setPlayerStorageValue(cid, storage, os.time() + time)
    end,

    make = function (cid, storage, time)
        local exhaust = exhaustion.get(cid, storage)
        if(not exhaust) then
            exhaustion.set(cid, storage, time)
            return true
        end

        return false
    end
}
Ztth-c9f.png

It's spell for monster, not for player.
 
Ztth-c9f.png

It's spell for monster, not for player.

Weird, that works for me. But you can try without using this exhaustion but storages instead.
I know it says "getPlayerStorageValue" but it should work for monsters too. Then again, I really don't know which changes TFS 1.0 has to this kind of stuff.

Code:
function onPrepareDeath(cid, lastHitKiller, mostDamageKiller)
local STORAGE = 7500 -- Storage used for exhaustion of this ability
local exhtime = 15*60 -- Exhaustion time (in seconds)
local hp = math.random(7500, 7515) -- Amount of healed HP

    if isCreature(cid) == true and getCreatureName(cid) == "Zushuka" then
        if getPlayerStorageValue(cid, STORAGE) == -1 then
        setPlayerStorageValue(cid, STORAGE, 1)
        doCreatureAddHealth(cid, hp)  
            addEvent(function()
            setPlayerStorageValue(cid, STORAGE, -1)
            end, 15*60*1000)
        end
    else
    return false
    end
  
return true
end
 
Weird, that works for me. But you can try without using this exhaustion but storages instead.
I know it says "getPlayerStorageValue" but it should work for monsters too. Then again, I really don't know which changes TFS 1.0 has to this kind of stuff.

Code:
function onPrepareDeath(cid, lastHitKiller, mostDamageKiller)
local STORAGE = 7500 -- Storage used for exhaustion of this ability
local exhtime = 15*60 -- Exhaustion time (in seconds)
local hp = math.random(7500, 7515) -- Amount of healed HP

    if isCreature(cid) == true and getCreatureName(cid) == "Zushuka" then
        if getPlayerStorageValue(cid, STORAGE) == -1 then
        setPlayerStorageValue(cid, STORAGE, 1)
        doCreatureAddHealth(cid, hp) 
            addEvent(function()
            setPlayerStorageValue(cid, STORAGE, -1)
            end, 15*60*1000)
        end
    else
    return false
    end
 
return true
end
It dies without getting healed. No errors in console.
 
It don't check for storage value, used this as an example -
Code:
function onPrepareDeath(cid, lastHitKiller, mostDamageKiller)
local STORAGE = 7500 -- Storage used for exhaustion of this ability
local exhtime = 15*60 -- Exhaustion time (in seconds)
local hp = math.random(7500, 7515) -- Amount of healed HP

    if isCreature(cid) == true and getCreatureName(cid) == "Zushuka" then
    doCreatureSay(cid, "I'm a creature and my name is Zushuka.", TALKTYPE_ORANGE_2)
        if getPlayerStorageValue(cid, STORAGE) == -1 then
        doCreatureSay(cid, "I don't have that storage.", TALKTYPE_ORANGE_2)
        setPlayerStorageValue(cid, STORAGE, 1)
        doCreatureSay(cid, "Now I have that storage.", TALKTYPE_ORANGE_2)
        doCreatureAddHealth(cid, hp)
        doCreatureSay(cid, "I recieved health.", TALKTYPE_ORANGE_2)      
            addEvent(function()
            setPlayerStorageValue(cid, STORAGE, -1)
            end, 15*60*1000)
            doCreatureSay(cid, "I've got removed storage", TALKTYPE_ORANGE_2)
        end
    else
    return false
    end

return true
end
It said only - "I'm a creature and my name is Zushuka." then died.
 
I think its something like

if (Player(cid):getStorageValue(7500) == -1) then

And for setting it

Player(cid):setStorageValue(7500, 1)
 
Last edited:
Back
Top