• 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.2 (8.6) spell with groupcooldown?

Edroniasty

New Member
Joined
Oct 2, 2015
Messages
84
Reaction score
1
Hello! Is this possible to add groupcooldown like in newest clients to this spell?:

Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FLASHARROW)
function onGetFormulaValues(player, skill, attack, factor)
    local skill = player:getEffectiveSkillLevel(SKILL_DISTANCE)
    local min = (player:getLevel() * 1.87) + (skill * attack * 0) + 0
    local max = (player:getLevel() * 2.16) + (skill * attack * 0) + 0
    return -min, -max
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
local function executeAttack(cid, variant, i, j)
    local player = Player(cid)
    if not player then
        return
    end
    if i >= j then
        return
    end
    addEvent(executeAttack, 200, cid, variant, i + 1, j)
    return combat:execute(player, variant)
end
function onCastSpell(creature, variant, isHotkey)
    return executeAttack(creature:getId(), variant, 0, 5)
end

I try to make this spell 60s cooldown for other spells - can't use exhaust because when I put 60000 ms I must wait 60 s to use other spells..

ps: sry for bad forum section..
 
Last edited:
Solution
Yes it is, just use a shared storage value. Lets say your spell is a single target attack spell and it has a cool down of 10 seconds you could set a storage value which is reset to its default value when the 10 seconds is up. Meanwhile you have other attack spells which share that group cool down because they too are asked the question is this shared storage value set.

The cool down should not be set in the xml, it should be set in the execution of the spell's script to be effective. Using the example above since it loops we do not want to set the storage value within the executeAttack method, we would want to set and compare the storage value within the onCastSpell.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE...
Yes it is, just use a shared storage value. Lets say your spell is a single target attack spell and it has a cool down of 10 seconds you could set a storage value which is reset to its default value when the 10 seconds is up. Meanwhile you have other attack spells which share that group cool down because they too are asked the question is this shared storage value set.

The cool down should not be set in the xml, it should be set in the execution of the spell's script to be effective. Using the example above since it loops we do not want to set the storage value within the executeAttack method, we would want to set and compare the storage value within the onCastSpell.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FLASHARROW)
function onGetFormulaValues(player, skill, attack, factor)
    local skill = player:getEffectiveSkillLevel(SKILL_DISTANCE)
    local min = (player:getLevel() * 1.87) + (skill * attack * 0) + 0
    local max = (player:getLevel() * 2.16) + (skill * attack * 0) + 0
    return -min, -max
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
local function executeAttack(cid, variant, i, j)
    local player = Player(cid)
    if not player then
        return
    end
    if i >= j then
        return
    end
    addEvent(executeAttack, 200, cid, variant, i + 1, j)
    return combat:execute(player, variant)
end

local storage = 123456
local exhaust = 10

function resetStorage(cid)
    local player = Player(cid)
    if player then
        player:setStorageValue(storage, -1)
    end
end

function onCastSpell(creature, variant, isHotkey)
    -- is the creature who is using this spell a player, always good to check
    if creature:isPlayer() then
        -- have they used this spell yet?
        if creature:getStorageValue(storage) < 0 then
            -- when they do lets set the storage value so they can't use it again
            creature:setStorageValue(storage, 1)
            -- make preperations to reset the storage value
            addEvent(resetStorage, exhaust * 1000, creature:getId())
            -- execute the spell
            return executeAttack(creature:getId(), variant, 0, 5)
        else
            -- if they have used the spell warn them they need to wait to use it again
            creature:sendCancelMessage("This spell is still cooling down.")
        end
    end
    -- if the nested else executes or creature is not a player then the spell will return false and not perform any actions
    return false
end
The only real issue here is if the player logs out before the spell has a chance to reset, this can be resolved in login.lua by setting any storage's you have used for group cool downs.
 
Solution
Yes it is, just use a shared storage value. Lets say your spell is a single target attack spell and it has a cool down of 10 seconds you could set a storage value which is reset to its default value when the 10 seconds is up. Meanwhile you have other attack spells which share that group cool down because they too are asked the question is this shared storage value set.

The cool down should not be set in the xml, it should be set in the execution of the spell's script to be effective. Using the example above since it loops we do not want to set the storage value within the executeAttack method, we would want to set and compare the storage value within the onCastSpell.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FLASHARROW)
function onGetFormulaValues(player, skill, attack, factor)
    local skill = player:getEffectiveSkillLevel(SKILL_DISTANCE)
    local min = (player:getLevel() * 1.87) + (skill * attack * 0) + 0
    local max = (player:getLevel() * 2.16) + (skill * attack * 0) + 0
    return -min, -max
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
local function executeAttack(cid, variant, i, j)
    local player = Player(cid)
    if not player then
        return
    end
    if i >= j then
        return
    end
    addEvent(executeAttack, 200, cid, variant, i + 1, j)
    return combat:execute(player, variant)
end

local storage = 123456
local exhaust = 10

function resetStorage(cid)
    local player = Player(cid)
    if player then
        player:setStorageValue(storage, -1)
    end
end

function onCastSpell(creature, variant, isHotkey)
    -- is the creature who is using this spell a player, always good to check
    if creature:isPlayer() then
        -- have they used this spell yet?
        if creature:getStorageValue(storage) < 0 then
            -- when they do lets set the storage value so they can't use it again
            creature:setStorageValue(storage, 1)
            -- make preperations to reset the storage value
            addEvent(resetStorage, exhaust * 1000, creature:getId())
            -- execute the spell
            return executeAttack(creature:getId(), variant, 0, 5)
        else
            -- if they have used the spell warn them they need to wait to use it again
            creature:sendCancelMessage("This spell is still cooling down.")
        end
    end
    -- if the nested else executes or creature is not a player then the spell will return false and not perform any actions
    return false
end
The only real issue here is if the player logs out before the spell has a chance to reset, this can be resolved in login.lua by setting any storage's you have used for group cool downs.
Nice! It's working well - I try to edit this spell to but get errors in lines 40-60 probarly I need to change it for that spell, can u help me? ( I'm bad scripter) ;'c

Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HOLYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 29)
local arr1 = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 1, 3, 1, 0, 0, 0, 0, 0, 0}
}
local area = createCombatArea(arr1)
combat:setArea(createCombatArea(arr1))

function onGetFormulaValues(player, skill, attack, factor)
    local skill = player:getEffectiveSkillLevel(SKILL_DISTANCE)
    local min = (player:getLevel() * 18.72) + (skill * attack * 0) + 0
    local max = (player:getLevel() * 21.6) + (skill * attack * 0) + 0
    return -min, -max
end

function onTargetTile(cid, pos)
    doSendDistanceShoot(getCreaturePosition(cid), pos, CONST_ANI_ETHEREALSPEAR)
end
combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end
 
Not exactly sure what you want to accomplish here but maybe you should post the original script(s)?

You are mixing old code with new code, unfortunately defining methods to work with your current distribution isn't always as easy as copy and paste.
What I do is I reference the sources to look for methods which are similar or are already defined to help me write my scripts.
 
I can understand how hard it is so if u don't know how to do this no problem - I need 4 more scripts to make the groupcooldown 60s u already did it to first script - don't know what u mean "original scripts" - i want to edit my custom spell scripts..

1
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HOLYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 29)
local arr1 = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 1, 3, 1, 0, 0, 0, 0, 0, 0}
}
local area = createCombatArea(arr1)
combat:setArea(createCombatArea(arr1))
function onGetFormulaValues(player, skill, attack, factor)
    local skill = player:getEffectiveSkillLevel(SKILL_DISTANCE)
    local min = (player:getLevel() * 18.72) + (skill * attack * 0) + 0
    local max = (player:getLevel() * 21.6) + (skill * attack * 0) + 0
    return -min, -max
end
function onTargetTile(cid, pos)
    doSendDistanceShoot(getCreaturePosition(cid), pos, CONST_ANI_ETHEREALSPEAR)
end
combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, var)
    return combat:execute(creature, var)
end

2
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
local protect = Condition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT)
protect:setParameter(CONDITION_PARAM_SUBID, 56)
protect:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
protect:setParameter(CONDITION_PARAM_TICKS, 8 * 1000)
combat:setCondition(protect)
function onCastSpell(creature, var)
    return combat:execute(creature, var)
end

3
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatArea(combat,createCombatArea({
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}))
function getWaveDmg(cid, level, maglevel)
    min = ((level * 3.3) + (maglevel * 0) + 0)
    max = ((level * 3.3) + (maglevel * 0) + 0)
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "getWaveDmg")
local combatsummon = createCombatObject()
setCombatParam(combatsummon,COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_EARTH)
setCombatParam(combatsummon,COMBAT_PARAM_CREATEITEM, 2699)
local combatpoff = createCombatObject()
setCombatParam(combatpoff, COMBAT_PARAM_EFFECT, CONST_ME_POFF)
setCombatParam(combatpoff, COMBAT_PARAM_TYPE, COMBAT_NONE)
setCombatArea(combatpoff,createCombatArea({{3}}))
function getDmg_Brush(cid, level, maglevel)
    return (10)*-1,(20)*-1
end
setCombatCallback(combatpoff, CALLBACK_PARAM_LEVELMAGICVALUE, "getDmg_Brush")
local function RunPart(c,cid,var,dirList,dirEmitPos)
    if (isCreature(cid)) then
        doCombat(cid, c, var)
        if (dirList ~= nil) then
            local i = 2;
            while (i < #dirList) do
                doSendDistanceShoot(dirEmitPos,{x=dirEmitPos.x-dirList[i],y=dirEmitPos.y-dirList[i+1],z=dirEmitPos.z},dirList[1])
                i = i + 2
            end 
        end
    end
end
local function doRemove(pos, itemId)
     local tree = Tile(pos):getItemById(2699)
     if tree then
         tree:remove()
     end
end
function onCastSpell(cid, var)
    local pos = var:getPosition()
    local startPos = getCreaturePosition(cid)
    RunPart(combat,cid,var)
    addEvent(RunPart,1,combatsummon,cid.uid,var)
    addEvent(RunPart,1000,combat,cid.uid,var)
    addEvent(RunPart,2000,combat,cid.uid,var)
    addEvent(RunPart,3000,combat,cid.uid,var)
    addEvent(RunPart,4000,combat,cid.uid,var)
    addEvent(RunPart,5000,combat,cid.uid,var)
    addEvent(RunPart,6000,combat,cid.uid,var)
    addEvent(RunPart,7000,combat,cid.uid,var)
    addEvent(RunPart,7000,combat,cid.uid,var)
    addEvent(RunPart,8000,combat,cid.uid,var)
    addEvent(RunPart,9000,combat,cid.uid,var)
    addEvent(RunPart,10000,combatpoff,cid.uid,var)
    addEvent(doRemove, 10000, pos, 2699)
    return true
end

4
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_BIGCLOUDS)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, 11)

function onGetFormulaValues(player, level, maglevel)
    local min = (level * 23.4) + (maglevel * 0) + 0
    local max = (level * 27) + (maglevel * 0) + 0
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, var, isHotkey)
    return combat:execute(creature, var)
end
 
Back
Top