• 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 Cancel event

Caio Cesar

Member
Joined
Nov 23, 2014
Messages
60
Reaction score
6
Location
Brazil - Goiânia
Code:
local config = {
cooldown = 5, -- tempo entre uma magia e outra
tempo = 20, -- tempo em segundos que ficará healando
percent = 2, --- porcentagem da vida que cura
storage = 45382

}

function onCastSpell(cid, var)

local p = Creature(cid)
if os.time() - p:getStorageValue(cid, config.storage) >= config.cooldown then
for i = 1, config.tempo do
addEvent(function()



 local lifedraw = math.ceil(p:getMaxHealth() * (config.percent)/100)
 local pos = p:getPosition()
  p:addHealth(cid, lifedraw, 1)     
        pos:sendMagicEffect(13)
             

end, 1000*i)
end

p:setStorageValue(cid, config.storage, os.time())

else
p:sendCancelMessage(cid, "Your Mass Healing is at cooldown, you must wait "..(config.cooldown - (os.time() - p:getStorageValue(cid, config.storage))).." seconds.")
end
return true
end

I did this spell , a heal over time, but if the player logout while the effect is on, my server crash.
How i can cancel a effect/event/etc over time if a player logout??
 
Last edited:
Code:
local config = {
    cooldown = 5, -- tempo entre uma magia e outra
    tempo = 20, -- tempo em segundos que ficará healando
    percent = 2, --- porcentagem da vida que cura
    storage = 45382
}

function onCastSpell(creature, var)
    if os.time() - creature:getStorageValue(config.storage) < config.cooldown then
        creature:sendCancelMessage("Your Mass Healing is at cooldown, you must wait "..(config.cooldown - (os.time() - creature:getStorageValue(config.storage))).." seconds.")
        return false
    end

    for i = 1, config.tempo do
        addEvent(function (cid)
            local creature = Creature(cid)
            if not creature then
                return true
            end

            local lifedraw = math.ceil(creature:getMaxHealth() * (config.percent) / 100)
            creature:addHealth(lifedraw)   
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        end, 1000 * i, creature:getId())
    end

    creature:setStorageValue(config.storage, os.time())
    return true
end

[Question] Addevent doesn't work with userdata?
[How-to] Using addEvent()
 
Back
Top