• 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

Intermediate OT User
Joined
Jun 29, 2020
Messages
528
Solutions
16
Reaction score
129
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
 
Solution
Solved

LUA:
local config = {
  duration = 1 * 60 * 1000,
}

local effect = {
  id = CONST_ME_HEALING,
  interval = 1500,
}

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

local condition = Condition(CONDITION_REGENERATION)
condition:setParameter(CONDITION_PARAM_SUBID, 1) -- SUB_ID must be unique among other CONDITION_REGENERATION entries
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, 1)
condition:setParameter(CONDITION_PARAM_TICKS, config.duration)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 15)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 1500)
combat:addCondition(condition)

local active = {}
local function sendEffect(playerName)...
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.
 
Solved

LUA:
local config = {
  duration = 1 * 60 * 1000,
}

local effect = {
  id = CONST_ME_HEALING,
  interval = 1500,
}

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

local condition = Condition(CONDITION_REGENERATION)
condition:setParameter(CONDITION_PARAM_SUBID, 1) -- SUB_ID must be unique among other CONDITION_REGENERATION entries
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, 1)
condition:setParameter(CONDITION_PARAM_TICKS, config.duration)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 15)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 1500)
combat:addCondition(condition)

local active = {}
local function sendEffect(playerName)
  if active[playerName] and active[playerName] > (os.mtime() - config.duration) then
    local p = Player(playerName)
    if p and p:hasCondition(CONDITION_REGENERATION, 1 --[[SUBID HERE]]) then
      p:getPosition():sendMagicEffect(effect.id)
    end
    addEvent(sendEffect,effect.interval,playerName)
  else
    active[playerName] = nil
  end
end

function onCastSpell(creature, var)
  if combat:execute(creature, var) then
    local playerName = creature:getName()
    local now = os.mtime()
    if not active[playerName] or active[playerName] < now then
      if not active[playerName] then
        addEvent(sendEffect,effect.interval,playerName)
      end
      active[playerName] = now
    end
    return true
  end
end
 
Solution
Back
Top