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

spells cooldown

Mateus Robeerto

Excellent OT User
Joined
Jun 5, 2016
Messages
1,245
Solutions
68
Reaction score
601
Location
ლ(ಠ益ಠლ)
can someone convert to tfs 1x?
C++:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_DRAWBLOOD)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -0, -3500, -0, -3500)

local condition = createConditionObject(CONDITION_EMO)
setConditionParam(condition, CONDITION_PARAM_DELAYED, 1)
addDamageCondition(condition, 10, 1000, -3000)
setCombatCondition(combat, condition)

arr = {
{1, 1, 1},
{1, 2, 1},
{1, 1, 1}
}

local area = createCombatArea(arr)
setCombatArea(combat, area)

function onCastSpell(cid, var)
         local rand = math.random(1,50)
         if rand == 1 and isPlayer(cid) == 1 then
             doCreatureSay(cid,"Bleed!",16)
         elseif rand == 2 and isPlayer(cid) == 1 then
             doCreatureSay(cid,"Bleed!",16)
         elseif rand == 3 and isPlayer(cid) == 1 then
             doCreatureSay(cid,"Bleed!",16)
         elseif rand == 4 and isPlayer(cid) == 1 then
             doCreatureSay(cid,"Bleed!",16)
         end
         return doCombat(cid, combat, var)

end
                
local function Cooldown(cid)
if isPlayer(cid) == TRUE then
doPlayerSendTextMessage(cid,MESSAGE_STATUS_WARNING,'CD: Lamina Mortal.')
end
end

local exhausted_seconds = 5  -- Segundos que o Player Poderá castar a spell novamente
local exhausted_storagevalue = 94346834656742 -- Storage Value do Cool Down

function onCastSpell(cid, var)
if(os.time() < getPlayerStorageValue(cid, exhausted_storagevalue)) then
doPlayerSendCancel(cid,'O Cooldown não está pronto.')
return TRUE
end

    rand = math.random(1,1)
    if rand == 1 and isPlayer(cid) == 1 then
     doCreatureSay(cid,"Exori Bleed!",16)
      addEvent(Cooldown, 1*4900,cid)
         setPlayerStorageValue(cid, exhausted_storagevalue, os.time() + exhausted_seconds)
    return doCombat(cid, combat, var)
    elseif rand == 2 and isPlayer(cid) == 1 then
     doCreatureSay(cid,"Exori Bleed!",16)
      addEvent(Cooldown, 1*4900,cid)
         setPlayerStorageValue(cid, exhausted_storagevalue, os.time() + exhausted_seconds)
    return doCombat(cid, combat, var)
else
      addEvent(Cooldown, 1*4900,cid)
         setPlayerStorageValue(cid, exhausted_storagevalue, os.time() + exhausted_seconds)
    return doCombat(cid, combat, var)
end
end

follow the error here \/

Lua Script Error: [Spell Interface]
data/spells/scripts/headcut.lua:eek:nCastSpell
LuaScriptInterface::luaAddEvent(). Argument #3 is unsafe
stack traceback:
[C]: in function 'addEvent'
data/spells/scripts/headcut.lua:62: in function <data/spells/scripts/headcut.lua:44>
 
It's actually a nice script to learn how to do it :)
Try it yourself with compat.lua

Just look for things like e.g. setPlayerStorageValue
Result:
Lua:
function setPlayerStorageValue(cid, key, value) local p = Player(cid) return p and p:setStorageValue(key, value) or false end

Check definition of onCastSpell, you have 2 options, look on repository for examples or look into sources:

So you can see it already passes "creature"
// onCastSpell(creature, variant)

So you can see main diff that it's already a "creature" and not a "cid" so you can already call methods on it like:
Lua:
creature:getStorageValue(exhausted_storagevalue)

Same for other things, but the main issue here is that previously you had "cid" (number) but right know you have object "creature" which you cannot pass to addEvent as it's unsafe.
You can rework that by passing cid like:
Lua:
function onCastSpell(creature, variant)
   local cid = creature:getId()
   addEvent(Cooldown, 4900, cid)
end

Btw you have two functions onCastSpell in one spell script💥
You have rand that returns always zero so why do even keep code that's not used.
And one last thing, what's CONDITION_EMO? (no idea so replace it with some random one)
exhausted_storagevalue is higher than max allowed number for storage key.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_DRAWBLOOD)
combat:setFormula(COMBAT_FORMULA_LEVELMAGIC, -0, -3500, -0, -3500)

local condition = Condition(CONDITION_BLEEDING)
condition:setParameter(CONDITION_PARAM_DELAYED, 1)
condition:addDamage(10, 1000, -3000)
combat:addCondition(condition)

local AREA = {
    {1, 1, 1},
    {1, 2, 1},
    {1, 1, 1}
}

combat:setArea(createCombatArea(AREA))

local function cooldown(cid)
    local player = Player(cid)
    if player then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, 'CD: Lamina Mortal.')
    end
end

local exhausted_seconds = 5
local exhausted_storagevalue = 943468346

function onCastSpell(creature, variant)
    local exhaustEnd = creature:getStorageValue(exhausted_storagevalue)
    if os.time() < exhaustEnd then
        creature:sendCancelMessage('O Cooldown não está pronto.')
        return true
    end

    creature:say("Exori Bleed!", TALKTYPE_MONSTER_YELL)
    addEvent(cooldown, 4900, creature:getId())
    creature:setStorageValue(exhausted_storagevalue, os.time() + exhausted_seconds)

    return combat:execute(creature, variant)
end

Anyway I do not understand this whole exhaust thing as it can be simply configured in "spells.xml" or in lua script when spell is defined as "revscript":

Lua:
local instant = Spell(SPELL_INSTANT)

function instant.onCastSpell(creature, variant)
    ...
end

instant:name("Test")
instant:id(999)
instant:words("spell words")
instant:level(20)
instant:mana(250)
instant:group("attack")
instant:isAggressive(true)
instant:cooldown(2000) -- exhaust
instant:groupCooldown(2000) -- group exhaust
instant:needLearn(false)
instant:vocation("sorcerer", "master sorcerer")
instant:register()
 
Last edited:
Back
Top