• 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.5 / Spell - Effect on Ticks

Forkz

Well-Known Member
Joined
Jun 29, 2020
Messages
359
Solutions
1
Reaction score
75
Hello,

Could someone help me, during each tick I would like the character to release an effect;

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_REGENERATION)
condition:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 300)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 3000)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
combat:addCondition(condition)

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end
 
Lua:
-- you should put it in global.lua or any other libs that are loaded before the spells, safety reasons and gain ability to stopEvent in other scripts, etc.
spellTickEffectEvent = {}

local config = {
    conditionTime = 1 * 60 * 1000, -- minute * seconds * miliseconds (1*60*1000 = 1 minute)
    tickTime = 3 * 1000, -- seconds * miliseconds (3*1000 = 3 seconds)
    healthRegen = 300 -- how many health regen per tick
    effect = CONST_ME_MAGIC_GREEN -- magic effect when tick
}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_REGENERATION)
condition:setParameter(CONDITION_PARAM_TICKS, config.conditionTime)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, config.healthRegen)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, config.tickTime)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
combat:addCondition(condition)

local function effect(cid)
    local creature = Creature(cid)
    -- Sanity check, if creature not exist - no execute this function
    if not creature then return false end
    -- if condition is ended stop
    if not creature:getCondition(condition, CONDITIONID_DEFAULT) then
        -- safety stop event and clean it from table
        if spellTickEffectEvent[creature:getId()] then  
            stopEvent(spellTickEffectEvent[creature:getId()])
            spellTickEffectEvent[creature:getId()] = nil -- or -- table.remove(spellTickEffectEvent, creature:getId())
        end
        return false
    end

    local effectPos = creature:getPosition()
    effectPos:sendMagicEffect(config.effect)
    -- execute
    spellTickEffectEvent[creature:getId()] = addEvent(effect, config.tickTime, creature:getId())
    return true
end

function onCastSpell(creature, variant)
    combat:execute(creature, variant)
    effect(creature)
    return
end
 
Last edited:
Lua:
-- you should put it in global.lua or any other libs that are loaded before the spells, safety reasons and gain ability to stopEvent in other scripts, etc.
spellTickEffectEvent = {}

local config = {
    conditionTime = 1 * 60 * 1000, -- minute * seconds * miliseconds (1*60*1000 = 1 minute)
    tickTime = 3 * 1000, -- seconds * miliseconds (3*1000 = 3 seconds)
    healthRegen = 300 -- how many health regen per tick
    effect = CONST_ME_MAGIC_GREEN -- magic effect when tick
}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_REGENERATION)
condition:setParameter(CONDITION_PARAM_TICKS, config.conditionTime)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, config.healthRegen)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, config.tickTime)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
combat:addCondition(condition)

local function effect(cid)
    local creature = Creature(cid)
    -- Sanity check, if creature not exist - no execute this function
    if not creature then return false end
    -- if condition is ended stop
    if not creature:getCondition(condition, CONDITIONID_DEFAULT) then
        -- safety stop event and clean it from table
        if spellTickEffectEvent[creature:getId()] then 
            stopEvent(spellTickEffectEvent[creature:getId()])
            spellTickEffectEvent[creature:getId()] = nil -- or -- table.remove(spellTickEffectEvent, creature:getId())
        end
        return false
    end

    local effectPos = creature:getPosition()
    effectPos:sendMagicEffect(config.effect)
    -- execute
    spellTickEffectEvent[creature:getId()] = addEvent(effect, config.tickTime, creature:getId())
    return true
end

function onCastSpell(creature, variant)
    effect(creature)
    combat:execute(creature, variant)
    return
end
It is healing, but the effect is not showing every tick.
 
Back
Top