• 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 1.X+ Spell cooldown not working on monsters TFS 1.5 772 downgrade

jakub742

Active Member
Joined
May 1, 2010
Messages
199
Solutions
3
Reaction score
42
Location
Slovakia
Hi, do you know how to add cooldown on spell so it would work for monsters aswell ?

i have a monster revscript, example attacks:
LUA:
monster.attacks = {
    {name ="melee", interval = 1500, chance = 80, minDamage = -2100, maxDamage = -3000},
    {name ="firestorm", cooldown = 9000, interval = 2000, chance = 60, minDamage = -2830, maxDamage = -5720},
}

It has 2000 interval and 60 chance but when its casted i expected to be in cooldown that is set on spell:cooldown

But the cooldown is ignored in this case with monster. Monster can spam it more often than spell:cooldown(9000)

Spell script:

LUA:
local spell = Spell(SPELL_INSTANT)
spell:name("firestorm")
spell:cooldown(9000)

function spell.onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)
end

spell:register()

Any other workaround that i could use for that ?
 
Yeah I don't think cooldown works for monsters.

But you could force a cooldown.. using storages.


then inside the spell, just give it the current os.mtime() , then whenever the monster attempts to cast again, check if enough time has passed.
If not enough time, then cancel the spell activation.

LUA:
local cooldown = 9000

function spell.onCastSpell(creature, variant, isHotkey)
    if creature:isMonster() then
        local currentTime = os.mtime()
        if creature:getStorageValue(11111) + cooldown > currentTime then
            return false
        end
        creature:setStorageValue(11111, currentTime)
    end
    return combat:execute(creature, variant)
end
 
Last edited by a moderator:
Yeah I don't think cooldown works for monsters.

But you could force a cooldown.. using storages.


then inside the spell, just give it the current os.mtime() , then whenever the monster attempts to cast again, check if enough time has passed.
If not enough time, then cancel the spell activation.

LUA:
local cooldown = 9000

function spell.onCastSpell(creature, variant, isHotkey)
    if creature:isMonster() then
        local currentTime = os.mtime()
        if creature:getStorageValue(11111) + cooldown > currentTime then
            return false
        end
        creature:setStorageValue(11111, currentTime)
    end
    return combat:execute(creature, variant)
end
Thank you 😉
 
Back
Top