• 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 Need help with spells (TFS 1.4.2)

kite28

Member
Joined
May 15, 2012
Messages
69
Reaction score
5
Hello, I need help with the harness because I don't know what's wrong anymore. Not working . maybe writing new ones.

TFS 1.4.2

1. I need a directional spell. Whenever the character turns, a magical effect strikes a specific place, and in the script it is possible to change the position of the effect and the area of effect.

2. Aoe with one effect and aoe with many effect


This is my old script but no work.
Lua:
local combat1 = createCombatObject()
setCombatParam(combat1, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat1, COMBAT_PARAM_HITCOLOR, COLOR_TEAL)
setCombatFormula(combat1, COMBAT_FORMULA_LEVELMAGIC, -5.0, -1200, -5.0, -1400)

local condition = createConditionObject(CONDITION_PARALYZE)
setConditionParam(condition, CONDITION_PARAM_TICKS, 20000)
setConditionParam(condition, CONDITION_PARAM_SPEED, -400)
addCombatCondition(combat1, condition)

arr1 = {
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 3, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
}

local area1 = createCombatArea(arr1)
setCombatArea(combat1, area1)

function onCastSpell(cid, var)

local waittime = 1 -- Tempo de exhaustion
local storage = 8032

if exhaustion.check(cid, storage) then
return false
end

local p = getCreaturePosition(cid)
local x = {
[0] = {x=p.x+2, y=p.y-1, z=p.z},
[1] = {x=p.x+4, y=p.y+1, z=p.z},
[2] = {x=p.x+2, y=p.y+4, z=p.z},
[3] = {x=p.x-1, y=p.y+1, z=p.z}
}
local y = {
[0] = 91,    --
[1] = 89,    --prawo
[2] = 92,    --dol
[3] = 90    --lewo
}
pos = x[getCreatureLookDirection(cid)]
eff = y[getCreatureLookDirection(cid)]
doSendMagicEffect(pos, eff)
doCreatureSay(cid, "Katon Gokakyu no Jutsu", TALKTYPE_MONSTER)
exhaustion.set(cid, storage, waittime)
doCombat(cid, combat1, var)
end
Very thanks for help <3
 
Last edited:
look for this line:
Lua:
local function applyMagicEffect(cid)
Just replace and test
Lua:
local function applyMagicEffect(cid)
    local creature = Creature(cid)
    if creature then
        local position = creature:getPosition()
        local direction = creature:getDirection()  -- Gets the player's current direction

        -- Determines new position based on current direction
        local newPosition = {
            x = position.x,
            y = position.y,
            z = position.z
        }

        -- Change position based on current direction
        if direction == NORTH then
            newPosition.y = newPosition.y - 1
        elseif direction == EAST then
            newPosition.x = newPosition.x + 1
        elseif direction == SOUTH then
            newPosition.y = newPosition.y + 1
        elseif direction == WEST then
            newPosition.x = newPosition.x - 1
        end

        for i = 1, #effect do
            position:sendMagicEffect(effect[i], newPosition)  -- Sends the effect to the new position
        end
    end
end
Give me error
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/spells/scripts/postacie/sasuke/susano.lua:38: attempt to get length of global 'effect' (a nil value)
stack traceback:
[C]: in function '__len'
data/spells/scripts/postacie/sasuke/susano.lua:38: in function 'applyMagicEffect'
data/spells/scripts/postacie/sasuke/susano.lua:58: in function <data/spells/scripts/postacie/sasuke/susano.lua:58>
 
You copied and pasted wrong. You need to copy and change correctly. But I'll send the complete code here, there are two different versions that I fixed


Lua:
local tempo = 45
local effect = {50}

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

local skillCondition = Condition(CONDITION_ATTRIBUTES)
skillCondition:setParameter(CONDITION_PARAM_TICKS, tempo * 1000)
skillCondition:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, 30)
skillCondition:setParameter(CONDITION_PARAM_SKILL_FIST, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_SWORD, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_AXE, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_CLUB, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_SHIELD, 30)
combat:addCondition(skillCondition)

local outfitCondition = Condition(CONDITION_OUTFIT)
outfitCondition:setOutfit({lookType = 1128})
outfitCondition:setTicks(tempo * 1000)
combat:addCondition(outfitCondition)

local regenCondition = Condition(CONDITION_REGENERATION)
regenCondition:setParameter(CONDITION_PARAM_SUBID, 1)
regenCondition:setParameter(CONDITION_PARAM_BUFF, true)
regenCondition:setParameter(CONDITION_PARAM_TICKS, tempo * 1000)
regenCondition:setParameter(CONDITION_PARAM_HEALTHGAIN, 1250)
regenCondition:setParameter(CONDITION_PARAM_HEALTHTICKS, 1000)
combat:addCondition(regenCondition)

local cooldownTime = 165
local lastCastTime = {}

local function applyMagicEffect(cid)
    local creature = Creature(cid)
    if creature then
        local position = creature:getPosition()
        local direction = creature:getDirection()  -- Gets the player's current direction

        -- Determines new position based on current direction
        local newPosition = {
            x = position.x,
            y = position.y,
            z = position.z
        }

        -- Change position based on current direction
        if direction == NORTH then
            newPosition.y = newPosition.y - 1
        elseif direction == EAST then
            newPosition.x = newPosition.x + 1
        elseif direction == SOUTH then
            newPosition.y = newPosition.y + 1
        elseif direction == WEST then
            newPosition.x = newPosition.x - 1
        end

        for i = 1, #effect do
            position:sendMagicEffect(effect[i], newPosition)  -- Sends the effect to the new position
        end
    end
end


function onCastSpell(cid, var)
    local storage = 25895

    if not lastCastTime[cid] or os.time() - lastCastTime[cid] >= cooldownTime then
        if Creature(cid):getStorageValue(134453) ~= 1 or getCreatureCondition(cid, CONDITION_REGENERATION, 1) == false then
            combat:execute(cid, var)
            Player(cid):sendTextMessage(MESSAGE_INFO_DESCR, 'Kurama gave you some chakra.')
            doCreatureSay(cid, 'Kuramaaa!', TALKTYPE_ORANGE_1)

            local tempo2 = 0
            local totalTempo = tempo * 1000
            while tempo2 < totalTempo do
                if Creature(cid) then
                    local delayedTempo = tempo2
                    addEvent(function() applyMagicEffect(cid) end, delayedTempo)
                else
                    break
                end
                tempo2 = tempo2 + 300
            end

            local player = Player(cid)
            if player then
                player:addSkillTries(SKILL_SHIELD, 1)
            end

            Creature(cid):setStorageValue(134453, 1)
            lastCastTime[cid] = os.time()
        else
            Player(cid):sendCancelMessage("Sorry, you are transformed.")
        end
    else
        local remainingCooldown = cooldownTime - (os.time() - lastCastTime[cid])
        Player(cid):sendChannelMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Wait " .. remainingCooldown .. " seconds to use the jutsu again.", TALKTYPE_CHANNEL_O, CHANNEL_SPELL)
    end
end

or

Lua:
local tempo = 45
local effect = {50}

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

local skillCondition = Condition(CONDITION_ATTRIBUTES)
skillCondition:setParameter(CONDITION_PARAM_TICKS, tempo * 1000)
skillCondition:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, 30)
skillCondition:setParameter(CONDITION_PARAM_SKILL_FIST, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_SWORD, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_AXE, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_CLUB, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_SHIELD, 30)
combat:addCondition(skillCondition)

local outfitCondition = Condition(CONDITION_OUTFIT)
outfitCondition:setOutfit({lookType = 1128})
outfitCondition:setTicks(tempo * 1000)
combat:addCondition(outfitCondition)

local regenCondition = Condition(CONDITION_REGENERATION)
regenCondition:setParameter(CONDITION_PARAM_SUBID, 1)
regenCondition:setParameter(CONDITION_PARAM_BUFF, true)
regenCondition:setParameter(CONDITION_PARAM_TICKS, tempo * 1000)
regenCondition:setParameter(CONDITION_PARAM_HEALTHGAIN, 1250)
regenCondition:setParameter(CONDITION_PARAM_HEALTHTICKS, 1000)
combat:addCondition(regenCondition)

local cooldownTime = 165
local lastCastTime = {}

local function applyMagicEffect(cid)
    local creature = Creature(cid)
    if creature then
        local position = creature:getPosition()

       -- Set custom offset here (e.g. x + 2 and y - 2)
        local xOffset, yOffset = 2, -2

       -- Calculates the new position
        local newPosition = {
            x = position.x + xOffset,
            y = position.y + yOffset,
            z = position.z
        }

        for i = 1, #effect do
            position:sendMagicEffect(effect[i], newPosition)  -- Sends the effect to the new position
        end
    end
end



function onCastSpell(cid, var)
    local storage = 25895

    if not lastCastTime[cid] or os.time() - lastCastTime[cid] >= cooldownTime then
        if Creature(cid):getStorageValue(134453) ~= 1 or getCreatureCondition(cid, CONDITION_REGENERATION, 1) == false then
            combat:execute(cid, var)
            Player(cid):sendTextMessage(MESSAGE_INFO_DESCR, 'Kurama gave you some chakra.')
            doCreatureSay(cid, 'Kuramaaa!', TALKTYPE_ORANGE_1)

            local tempo2 = 0
            local totalTempo = tempo * 1000
            while tempo2 < totalTempo do
                if Creature(cid) then
                    local delayedTempo = tempo2
                    addEvent(function() applyMagicEffect(cid) end, delayedTempo)
                else
                    break
                end
                tempo2 = tempo2 + 300
            end

            local player = Player(cid)
            if player then
                player:addSkillTries(SKILL_SHIELD, 1)
            end

            Creature(cid):setStorageValue(134453, 1)
            lastCastTime[cid] = os.time()
        else
            Player(cid):sendCancelMessage("Sorry, you are transformed.")
        end
    else
        local remainingCooldown = cooldownTime - (os.time() - lastCastTime[cid])
        Player(cid):sendChannelMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Wait " .. remainingCooldown .. " seconds to use the jutsu again.", TALKTYPE_CHANNEL_O, CHANNEL_SPELL)
    end
end
 
You copied and pasted wrong. You need to copy and change correctly. But I'll send the complete code here, there are two different versions that I fixed


Lua:
local tempo = 45
local effect = {50}

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

local skillCondition = Condition(CONDITION_ATTRIBUTES)
skillCondition:setParameter(CONDITION_PARAM_TICKS, tempo * 1000)
skillCondition:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, 30)
skillCondition:setParameter(CONDITION_PARAM_SKILL_FIST, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_SWORD, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_AXE, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_CLUB, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_SHIELD, 30)
combat:addCondition(skillCondition)

local outfitCondition = Condition(CONDITION_OUTFIT)
outfitCondition:setOutfit({lookType = 1128})
outfitCondition:setTicks(tempo * 1000)
combat:addCondition(outfitCondition)

local regenCondition = Condition(CONDITION_REGENERATION)
regenCondition:setParameter(CONDITION_PARAM_SUBID, 1)
regenCondition:setParameter(CONDITION_PARAM_BUFF, true)
regenCondition:setParameter(CONDITION_PARAM_TICKS, tempo * 1000)
regenCondition:setParameter(CONDITION_PARAM_HEALTHGAIN, 1250)
regenCondition:setParameter(CONDITION_PARAM_HEALTHTICKS, 1000)
combat:addCondition(regenCondition)

local cooldownTime = 165
local lastCastTime = {}

local function applyMagicEffect(cid)
    local creature = Creature(cid)
    if creature then
        local position = creature:getPosition()
        local direction = creature:getDirection()  -- Gets the player's current direction

        -- Determines new position based on current direction
        local newPosition = {
            x = position.x,
            y = position.y,
            z = position.z
        }

        -- Change position based on current direction
        if direction == NORTH then
            newPosition.y = newPosition.y - 1
        elseif direction == EAST then
            newPosition.x = newPosition.x + 1
        elseif direction == SOUTH then
            newPosition.y = newPosition.y + 1
        elseif direction == WEST then
            newPosition.x = newPosition.x - 1
        end

        for i = 1, #effect do
            position:sendMagicEffect(effect[i], newPosition)  -- Sends the effect to the new position
        end
    end
end


function onCastSpell(cid, var)
    local storage = 25895

    if not lastCastTime[cid] or os.time() - lastCastTime[cid] >= cooldownTime then
        if Creature(cid):getStorageValue(134453) ~= 1 or getCreatureCondition(cid, CONDITION_REGENERATION, 1) == false then
            combat:execute(cid, var)
            Player(cid):sendTextMessage(MESSAGE_INFO_DESCR, 'Kurama gave you some chakra.')
            doCreatureSay(cid, 'Kuramaaa!', TALKTYPE_ORANGE_1)

            local tempo2 = 0
            local totalTempo = tempo * 1000
            while tempo2 < totalTempo do
                if Creature(cid) then
                    local delayedTempo = tempo2
                    addEvent(function() applyMagicEffect(cid) end, delayedTempo)
                else
                    break
                end
                tempo2 = tempo2 + 300
            end

            local player = Player(cid)
            if player then
                player:addSkillTries(SKILL_SHIELD, 1)
            end

            Creature(cid):setStorageValue(134453, 1)
            lastCastTime[cid] = os.time()
        else
            Player(cid):sendCancelMessage("Sorry, you are transformed.")
        end
    else
        local remainingCooldown = cooldownTime - (os.time() - lastCastTime[cid])
        Player(cid):sendChannelMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Wait " .. remainingCooldown .. " seconds to use the jutsu again.", TALKTYPE_CHANNEL_O, CHANNEL_SPELL)
    end
end

or

Lua:
local tempo = 45
local effect = {50}

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

local skillCondition = Condition(CONDITION_ATTRIBUTES)
skillCondition:setParameter(CONDITION_PARAM_TICKS, tempo * 1000)
skillCondition:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, 30)
skillCondition:setParameter(CONDITION_PARAM_SKILL_FIST, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_SWORD, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_AXE, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_CLUB, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 0)
skillCondition:setParameter(CONDITION_PARAM_SKILL_SHIELD, 30)
combat:addCondition(skillCondition)

local outfitCondition = Condition(CONDITION_OUTFIT)
outfitCondition:setOutfit({lookType = 1128})
outfitCondition:setTicks(tempo * 1000)
combat:addCondition(outfitCondition)

local regenCondition = Condition(CONDITION_REGENERATION)
regenCondition:setParameter(CONDITION_PARAM_SUBID, 1)
regenCondition:setParameter(CONDITION_PARAM_BUFF, true)
regenCondition:setParameter(CONDITION_PARAM_TICKS, tempo * 1000)
regenCondition:setParameter(CONDITION_PARAM_HEALTHGAIN, 1250)
regenCondition:setParameter(CONDITION_PARAM_HEALTHTICKS, 1000)
combat:addCondition(regenCondition)

local cooldownTime = 165
local lastCastTime = {}

local function applyMagicEffect(cid)
    local creature = Creature(cid)
    if creature then
        local position = creature:getPosition()

       -- Set custom offset here (e.g. x + 2 and y - 2)
        local xOffset, yOffset = 2, -2

       -- Calculates the new position
        local newPosition = {
            x = position.x + xOffset,
            y = position.y + yOffset,
            z = position.z
        }

        for i = 1, #effect do
            position:sendMagicEffect(effect[i], newPosition)  -- Sends the effect to the new position
        end
    end
end



function onCastSpell(cid, var)
    local storage = 25895

    if not lastCastTime[cid] or os.time() - lastCastTime[cid] >= cooldownTime then
        if Creature(cid):getStorageValue(134453) ~= 1 or getCreatureCondition(cid, CONDITION_REGENERATION, 1) == false then
            combat:execute(cid, var)
            Player(cid):sendTextMessage(MESSAGE_INFO_DESCR, 'Kurama gave you some chakra.')
            doCreatureSay(cid, 'Kuramaaa!', TALKTYPE_ORANGE_1)

            local tempo2 = 0
            local totalTempo = tempo * 1000
            while tempo2 < totalTempo do
                if Creature(cid) then
                    local delayedTempo = tempo2
                    addEvent(function() applyMagicEffect(cid) end, delayedTempo)
                else
                    break
                end
                tempo2 = tempo2 + 300
            end

            local player = Player(cid)
            if player then
                player:addSkillTries(SKILL_SHIELD, 1)
            end

            Creature(cid):setStorageValue(134453, 1)
            lastCastTime[cid] = os.time()
        else
            Player(cid):sendCancelMessage("Sorry, you are transformed.")
        end
    else
        local remainingCooldown = cooldownTime - (os.time() - lastCastTime[cid])
        Player(cid):sendChannelMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Wait " .. remainingCooldown .. " seconds to use the jutsu again.", TALKTYPE_CHANNEL_O, CHANNEL_SPELL)
    end
end
okay work it but i have question how i can centered outfit ?
 
ok, trabalhe, mas tenho dúvidas de como posso centralizar a roupa?

look for this line:
Lua:
position:sendMagicEffect(effect[i], newPosition)
and change here:
Lua:
local xOffset, yOffset = -1 * (creature:getOutfit().lookType % 4), -1 * math.floor(creature:getOutfit().lookType / 4)
You can add an offset to the xOffset and yOffset coordinates to center the outfit. For example, you can set the xOffset and yOffset to half the player's size to center the outfit.




But I'm not sure if it will work and centralize. I've never seen a Moon that centers. From what I know, the correct position is defined by the object constructor. I don't know if I'm wrong, can someone correct me? Is there any way to center the clothes inside Lua or something similar in C++?
 
Last edited:
I haven't tested it yet, but to convert an old script to the new version of TFS 1.4.2, you should look at the compat.lua file and identify the functions that need to be replaced. For example:

Replace createCombatObject() with Combat().
Replace setCombatParam() with combat:setParameter().
Replace setCombatFormula() with combat:setFormula().
Replace createCombatArea() with CombatArea().
Replace addDamageCondition() with condition:addDamage().
Replace setCombatCondition() with combat:addCondition().
Replace onCastSpell() with combat.onCastSpell().
Replace createConditionObject() with Condition().
Replace setConditionParam() with condition:setParameter().
And instead of doCombat(), use combat:execute(). This should help with conversion

Look for the function you want in compat.lua and see if it needs to be replaced. Replace and test. If errors appear, try again and do it correctly. This is how you will be able to convert the old scripts to work with the new version."


Lua:
local combat1 = Combat()
combat1:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combat1:setParameter(COMBAT_PARAM_HITCOLOR, COLOR_TEAL)
combat1:setFormula(COMBAT_FORMULA_LEVELMAGIC, -5.0, -1200, -5.0, -1400)

local condition = Condition(CONDITION_PARALYZE)
condition:setParameter(CONDITION_PARAM_TICKS, 20000)
condition:setParameter(CONDITION_PARAM_SPEED, -400)
combat1:addCondition(condition)

local arr1 = {
    {0, 0, 0, 0, 0, 0, 0},
    {0, 0, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 0, 0},
    {0, 0, 0, 1, 0, 0, 0},
    {0, 0, 0, 3, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0},
}

local area1 = createCombatArea(arr1)
combat1:setArea(area1)


local cooldownTable = {}

function onCastSpell(creature, variant)
    local cooldown = 1000 -- Cooldown time in milliseconds

    if cooldownTable[creature:getId()] and os.time() - cooldownTable[creature:getId()] < cooldown then
        creature:sendTextMessage(MESSAGE_INFO_DESCR, "You need to wait for the spell to cool down.")
        return false
    end

    local position = creature:getPosition()
    local x = {
        [0] = {x = position.x + 2, y = position.y - 1, z = position.z},
        [1] = {x = position.x + 4, y = position.y + 1, z = position.z},
        [2] = {x = position.x + 2, y = position.y + 4, z = position.z},
        [3] = {x = position.x - 1, y = position.y + 1, z = position.z}
    }
    local y = {
        [0] = 91, --
        [1] = 89, -- prawo
        [2] = 92, -- dol
        [3] = 90 -- lewo
    }
    local pos = x[creature:getDirection()]
    local magicEffect = y[creature:getDirection()]

    Position(pos):sendMagicEffect(magicEffect)

    creature:say("Katon Gokakyu no Jutsu", TALKTYPE_MONSTER)
   
    cooldownTable[creature:getId()] = os.time() + cooldown

    combat1:execute(creature, variant)
end
sorry for interrupt but i was looking for this information, i have old scripts but i am learning an this info its very important
thanks Mateus
 
Back
Top