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

Lua TFS 1.3 how to make a effect loop for the duration of a spell?

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hello guys,

I would like for a effect to keep on loop for the whole duration of utamo vita. Let's say for example that I would like the blue spark effect to keep on loop for the entire time player has utamo vita, how would I put this?

I've tried to look at utana vid for example, but I believe that the loop on utana vid is at the TFS, not at spell script.
 
Solution
data/scripts/creaturescripts/mana_shield_effect.lua

Lua:
-- time in seconds
local effectInterval = 2
local intervalStorage = 9999

local manaShieldEffect = CreatureEvent("ManaShieldEffect")
manaShieldEffect:type("think")

function manaShieldEffect.onThink(creature, interval)
    local player = Player(creature)

    if not player:hasCondition(CONDITION_MANASHIELD) then
        return false
    end

    if os.time() - player:getStorageValue(intervalStorage) < effectInterval then
        return false
    end

    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    player:setStorageValue(intervalStorage, os.time())
    return true
end

manaShieldEffect:register()

local registerEvent = CreatureEvent("RegisterManaShieldEffect")...
both are conditions (outfit and spellshield), but the condition system is really messed up and can return incorrect values or not offer access to some features at all.
 
Do you think it would be a good idea for me to set "addevent" and "runpart" with several combat brush looping the effect?
Let's take this as a example:
Lua:
-- Areas/Combat for 0ms
local combat0_Brush = createCombatObject()
setCombatParam(combat0_Brush, COMBAT_PARAM_EFFECT, 57)
setCombatArea(combat0_Brush,createCombatArea({{1, 0, 0, 0, 0, 0, 1},
{0, 1, 1, 1, 1, 1, 0},
{0, 1, 0, 1, 0, 1, 0},
{0, 1, 1, 3, 1, 1, 0},
{0, 1, 0, 1, 0, 1, 0},
{0, 1, 1, 1, 1, 1, 0},
{1, 0, 0, 0, 0, 0, 1}}))


-- Areas/Combat for 2000ms
local combat2_Brush_2 = createCombatObject()
setCombatParam(combat2_Brush_2, COMBAT_PARAM_EFFECT, 186)
setCombatParam(combat2_Brush_2, COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
setCombatArea(combat2_Brush_2,createCombatArea({{1, 0, 0, 0, 0, 0, 1},
{0, 1, 1, 1, 1, 1, 0},
{0, 1, 0, 1, 0, 1, 0},
{0, 1, 1, 3, 1, 1, 0},
{0, 1, 0, 1, 0, 1, 0},
{0, 1, 1, 1, 1, 1, 0},
{1, 0, 0, 0, 0, 0, 1}}))
function getDmg_Brush_2(cid, level, maglevel)
    return (10)*-1,(40)*-1
end
setCombatCallback(combat2_Brush_2, CALLBACK_PARAM_LEVELMAGICVALUE, "getDmg_Brush_2")

-- =============== CORE FUNCTIONS ===============
local function RunPart(c,cid,var,dirList,dirEmitPos,startDir) -- Part
    if (isCreature(cid)) then
        doCombat(cid, c, var)
    end
end

function onCastSpell(cid, var)
    local startDir = Creature(cid):getDirection()
    RunPart(combat0_Brush,cid.uid,var)
    addEvent(RunPart,2000,combat2_Brush_2,cid.uid,var)
    return true
end

Lets imagine that the effect I want to loop last for 2 seconds and lets say that I want the utamo vita to last for 10 seconds. So I would a combat brush every 2000ms until it get to 10 seconds. Do you think I would find some problem with it?


I also see that TFS 1.2 has a function called "loop effect", but I don't know how to work with it and don't know if the same function works on TFS 1.3.
 
data/scripts/creaturescripts/mana_shield_effect.lua

Lua:
-- time in seconds
local effectInterval = 2
local intervalStorage = 9999

local manaShieldEffect = CreatureEvent("ManaShieldEffect")
manaShieldEffect:type("think")

function manaShieldEffect.onThink(creature, interval)
    local player = Player(creature)

    if not player:hasCondition(CONDITION_MANASHIELD) then
        return false
    end

    if os.time() - player:getStorageValue(intervalStorage) < effectInterval then
        return false
    end

    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    player:setStorageValue(intervalStorage, os.time())
    return true
end

manaShieldEffect:register()

local registerEvent = CreatureEvent("RegisterManaShieldEffect")
registerEvent:type("login")

function registerEvent.onLogin(player)
    player:registerEvent("ManaShieldEffect")
    return true
end

registerEvent:register()
 
Solution
data/scripts/creaturescripts/mana_shield_effect.lua

Lua:
-- time in seconds
local effectInterval = 2
local intervalStorage = 9999

local manaShieldEffect = CreatureEvent("ManaShieldEffect")
manaShieldEffect:type("think")

function manaShieldEffect.onThink(creature, interval)
    local player = Player(creature)

    if not player:hasCondition(CONDITION_MANASHIELD) then
        return false
    end

    if os.time() - player:getStorageValue(intervalStorage) < effectInterval then
        return false
    end

    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    player:setStorageValue(intervalStorage, os.time())
    return true
end

manaShieldEffect:register()

local registerEvent = CreatureEvent("RegisterManaShieldEffect")
registerEvent:type("login")

function registerEvent.onLogin(player)
    player:registerEvent("ManaShieldEffect")
    return true
end

registerEvent:register()
Nice, I tested and works perfectly. Thank you. But let's say my effect is bigger than 32x32, so I would need to set offset to effect. With spells I use those lines in the function:
Lua:
function onCastSpell(cid, var)
local parameters = { cid = cid, var = var}

local position = {x=getPlayerPosition(cid).x, y=getPlayerPosition(cid).y, z=getPlayerPosition(cid).z}
doSendMagicEffect(position, 126)
    return combat:execute(cid, var)
end

How can I make your script work like this?
 
I'm not sure if I understand your question. I guess you are using bigger sprites, right? Then you could do something in the lines of:

Lua:
local position = player:getPosition()
local effectPosition = Position({x = position.x + foo, y = position.y + bar, z = position.z})
effectPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
 
I'm not sure if I understand your question. I guess you are using bigger sprites, right? Then you could do something in the lines of:

Lua:
local position = player:getPosition()
local effectPosition = Position({x = position.x + foo, y = position.y + bar, z = position.z})
effectPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
That's exactly it. I tried to make the modifications by myself and I got some errors on TFS. Then I tested yours and works nicely. Thank you very much.
 
Back
Top