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

Spell Tree of Life

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
829
Solutions
123
Reaction score
655
Location
United States
Made for TFS 1.1

One of my first spells, so I'm sure it's not perfect. If you have advice on how to make it better please let me know. Thought it was pretty cool and didn't see a spell like it anywhere so here you go!

It's a directional spell that summons the tree, heals in intervals, then disappears.

treeoflife.png


data/spells/spells.xml
XML:
<instant group="healing" spellid="159" name="Tree of Life" words="exura con" lvl="36" mana="150" prem="1" aggressive="0" casterTargetOrDirection="1" blockwalls="1" exhaustion="60000" groupcooldown="2000" needlearn="0" script="healing/tree of life.lua">
        <vocation name="Elder Druid"/>
    </instant>

data/spells/scripts/healing/tree of life.lua
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatArea(combat,createCombatArea({{0, 0, 0, 1, 0, 0, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 3, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 0, 0, 0}}))

function getWaveDmg(cid, level, maglevel)
    min = ((level / 5) + (maglevel * 1.4) + 8)
    max = ((level / 5) + (maglevel * 1.8) + 11)
    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,3000,combat,cid.uid,var)
    addEvent(RunPart,6000,combat,cid.uid,var)
    addEvent(RunPart,9000,combat,cid.uid,var)
    addEvent(RunPart,11000,combatpoff,cid.uid,var)
    addEvent(doRemove, 11000, pos, 2699)
    return true
end

EDIT: Shortened code.
 
Last edited:
can u made it for tfs 1.2+? I use this spell, no error in console but tree don't add heal.. why?
 
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/spells/scripts/healing/tree of life.lua:49: attempt to index a nil value
stack traceback:
[C]: in function '__index'
data/spells/scripts/healing/tree of life.lua:49: in function <data/spells/scripts/healing/tree of life.lua:48>

bump?
 
Rewritten (hopefully less buggy for everyone)

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
setCombatArea(combat,
    createCombatArea({
        {0, 0, 0, 1, 0, 0, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 1, 1, 1, 1, 1, 0},
        {1, 1, 1, 3, 1, 1, 1},
        {0, 1, 1, 1, 1, 1, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 0, 0, 1, 0, 0, 0}
    })
)

local stack = {}
function healingFormula(cid, level, maglevel)
    min = ((level / 5) + (maglevel * 1.4) + 8)
    max = ((level / 5) + (maglevel * 1.8) + 11)
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "healingFormula")

function treeHeal(combat, cid, var)
    local continue = false
    local players = Game.getPlayers()
    for i = 1, #players do
        local player = players[i]
        if players[i]:getName() == cid:getName() then
            continue = true
        end
    end
    if continue == true then
        local pPos = getPlayerPosition(cid)
        local vPos = var:getPosition()
        if pPos then
            if stack[cid] == nil then
                doSendDistanceShoot(pPos, vPos, CONST_ANI_EARTH)
                local tree = Game.createItem(2699, 1, vPos, true)
                addEvent(function()    tree:remove()    vPos:sendMagicEffect(CONST_ME_POFF)    end, 12000)
                stack[cid] = 5
            end
       
            stack[cid] = stack[cid] - 1
            if stack[cid] > 0 then
                doCombat(cid, combat, var)
                addEvent(function()    treeHeal(combat, cid, var)    end, 3000)
            elseif stack[cid] == 0 then
                stack[cid] = nil
            end
        end
    end
end
function onCastSpell(cid, var)
    local tile = Tile(var:getPosition())
    if tile then
        local creatures = tile:getCreatures()
        if creatures then
            if #creatures == 0 then
                treeHeal(combat, cid, var)
                return true
            end
        end
    end
    cid:getPosition():sendMagicEffect(CONST_ME_POFF)
    cid:sendCancelMessage("There is not enough room.")
    return false
end
 
Rewritten (hopefully less buggy for everyone)

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
setCombatArea(combat,
    createCombatArea({
        {0, 0, 0, 1, 0, 0, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 1, 1, 1, 1, 1, 0},
        {1, 1, 1, 3, 1, 1, 1},
        {0, 1, 1, 1, 1, 1, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 0, 0, 1, 0, 0, 0}
    })
)

local stack = {}
function healingFormula(cid, level, maglevel)
    min = ((level / 5) + (maglevel * 1.4) + 8)
    max = ((level / 5) + (maglevel * 1.8) + 11)
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "healingFormula")

function treeHeal(combat, cid, var)
    local continue = false
    local players = Game.getPlayers()
    for i = 1, #players do
        local player = players[i]
        if players[i]:getName() == cid:getName() then
            continue = true
        end
    end
    if continue == true then
        local pPos = getPlayerPosition(cid)
        local vPos = var:getPosition()
        if pPos then
            if stack[cid] == nil then
                doSendDistanceShoot(pPos, vPos, CONST_ANI_EARTH)
                local tree = Game.createItem(2699, 1, vPos, true)
                addEvent(function()    tree:remove()    vPos:sendMagicEffect(CONST_ME_POFF)    end, 12000)
                stack[cid] = 5
            end
       
            stack[cid] = stack[cid] - 1
            if stack[cid] > 0 then
                doCombat(cid, combat, var)
                addEvent(function()    treeHeal(combat, cid, var)    end, 3000)
            elseif stack[cid] == 0 then
                stack[cid] = nil
            end
        end
    end
end
function onCastSpell(cid, var)
    local tile = Tile(var:getPosition())
    if tile then
        local creatures = tile:getCreatures()
        if creatures then
            if #creatures == 0 then
                treeHeal(combat, cid, var)
                return true
            end
        end
    end
    cid:getPosition():sendMagicEffect(CONST_ME_POFF)
    cid:sendCancelMessage("There is not enough room.")
    return false
end

It's good idea to use this way of checking boolean variable:
Code:
if continue then
if not continue then

There you check if player is online?
Code:
    local players = Game.getPlayers()
    for i = 1, #players do
        local player = players[i]
        if players[i]:getName() == cid:getName() then
            continue = true
        end
    end

Maybe try something like this (I'm not sure if it will work or not).
Code:
continue = cid:isPlayer()

BTW Nice script :)
 
I can't edit posts.
You can also try:
Code:
local player = Player:new(cid)
if player:isPlayer() then
Yeah I tried a ton of ways but it kept still having user data attached to cid. These ideas look great I'll mess with it later today and update.
 
To stop user data entry you could use:

TFS 1.x+
Lua:
playerName = player:getName()
addEvent(function()   treeHeal(combat, playerName, var)   end, 3000)

Then in treeHeal
Lua:
player = Player(playerName)
if player then

For TFS 0.3.6-1.x
Lua:
guid = getPlayerGUID(cid)
addEvent(function()   treeHeal(combat, guid, var)   end, 3000)

In treeHeal
Lua:
player = getPlayerByGUID(guid)
if player then
 
Niiice, I think I got it right now, thanks for the help guys!

Update:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
setCombatArea(combat,
    createCombatArea({
        {0, 0, 0, 1, 0, 0, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 1, 1, 1, 1, 1, 0},
        {1, 1, 1, 3, 1, 1, 1},
        {0, 1, 1, 1, 1, 1, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 0, 0, 1, 0, 0, 0}
    })
)

local stack = {}
function healingFormula(cid, level, maglevel)
    min = ((level / 5) + (maglevel * 1.4) + 8)
    max = ((level / 5) + (maglevel * 1.8) + 11)
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "healingFormula")

function treeHeal(combat, name, var)
    local player = Player(name)
    if player then
        local cid = player:getId()
        local pPos = player:getPosition()
        local vPos = var:getPosition()
        if pPos then
            if stack[cid] == nil then
                doSendDistanceShoot(pPos, vPos, CONST_ANI_EARTH)
                local tree = Game.createItem(2699, 1, vPos, true)
                addEvent(function()    tree:remove()    vPos:sendMagicEffect(CONST_ME_POFF)    end, 12000)
                stack[cid] = 5
            end
       
            stack[cid] = stack[cid] - 1
            if stack[cid] > 0 then
                doCombat(cid, combat, var)
                local playerName = player:getName()
                addEvent(function()    treeHeal(combat, playerName, var)    end, 3000)
            elseif stack[cid] == 0 then
                stack[cid] = nil
            end
        end
    end
end
function onCastSpell(cid, var)
    local tile = Tile(var:getPosition())
    if tile then
        local creatures = tile:getCreatures()
        if creatures then
            if #creatures == 0 and not tile:hasFlag(TILESTATE_BLOCKPATH) then
                local playerName = Player(cid):getName()
                treeHeal(combat, playerName, var)
                return true
            end
        end
    end
    cid:getPosition():sendMagicEffect(CONST_ME_POFF)
    cid:sendCancelMessage("There is not enough room.")
    return false
end
 
Last rewrite, simple fix. :p

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
setCombatArea(combat,
    createCombatArea({
        {0, 0, 0, 1, 0, 0, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 1, 1, 1, 1, 1, 0},
        {1, 1, 1, 3, 1, 1, 1},
        {0, 1, 1, 1, 1, 1, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 0, 0, 1, 0, 0, 0}
    })
)
function healingFormula(cid, level, maglevel)
    min = ((level / 5) + (maglevel * 1.4) + 8)
    max = ((level / 5) + (maglevel * 1.8) + 11)
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "healingFormula")

function treeHeal(combat, name, var, count)
    local player = Player(name)
    if player then
        local cid = player:getId()
        local pPos = player:getPosition()
        local vPos = var:getPosition()
        if pPos then
            if count == 5 then
                doSendDistanceShoot(pPos, vPos, CONST_ANI_EARTH)
                local tree = Game.createItem(2699, 1, vPos, true)
                addEvent(function()    tree:remove()    vPos:sendMagicEffect(CONST_ME_POFF)    end, 12000)
            end
       
            count = count - 1
            if count > 0 then
                doCombat(cid, combat, var)
                local playerName = player:getName()
                addEvent(function()    treeHeal(combat, playerName, var, count)    end, 3000)
            end
        end
    end
end
function onCastSpell(cid, var)
    local tile = Tile(var:getPosition())
    if tile then
        local creatures = tile:getCreatures()
        if creatures then
            if #creatures == 0 and not tile:hasFlag(TILESTATE_BLOCKPATH) then
                local playerName = Player(cid):getName()
                treeHeal(combat, playerName, var, 5)
                return true
            end
        end
    end
    cid:getPosition():sendMagicEffect(CONST_ME_POFF)
    cid:sendCancelMessage("There is not enough room.")
    return false
end
 
Last rewrite, simple fix. :p

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
setCombatArea(combat,
    createCombatArea({
        {0, 0, 0, 1, 0, 0, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 1, 1, 1, 1, 1, 0},
        {1, 1, 1, 3, 1, 1, 1},
        {0, 1, 1, 1, 1, 1, 0},
        {0, 0, 1, 1, 1, 0, 0},
        {0, 0, 0, 1, 0, 0, 0}
    })
)
function healingFormula(cid, level, maglevel)
    min = ((level / 5) + (maglevel * 1.4) + 8)
    max = ((level / 5) + (maglevel * 1.8) + 11)
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "healingFormula")

function treeHeal(combat, name, var, count)
    local player = Player(name)
    if player then
        local cid = player:getId()
        local pPos = player:getPosition()
        local vPos = var:getPosition()
        if pPos then
            if count == 5 then
                doSendDistanceShoot(pPos, vPos, CONST_ANI_EARTH)
                local tree = Game.createItem(2699, 1, vPos, true)
                addEvent(function()    tree:remove()    vPos:sendMagicEffect(CONST_ME_POFF)    end, 12000)
            end
      
            count = count - 1
            if count > 0 then
                doCombat(cid, combat, var)
                local playerName = player:getName()
                addEvent(function()    treeHeal(combat, playerName, var, count)    end, 3000)
            end
        end
    end
end
function onCastSpell(cid, var)
    local tile = Tile(var:getPosition())
    if tile then
        local creatures = tile:getCreatures()
        if creatures then
            if #creatures == 0 and not tile:hasFlag(TILESTATE_BLOCKPATH) then
                local playerName = Player(cid):getName()
                treeHeal(combat, playerName, var, 5)
                return true
            end
        end
    end
    cid:getPosition():sendMagicEffect(CONST_ME_POFF)
    cid:sendCancelMessage("There is not enough room.")
    return false
end


Hello guys,
Im using TFS 1.3, when i cast it, i just get:
Code:
There is not enough room.
And nothing happens :rolleyes: I tried to understand the scrip but im stucked o_O:p
 
Hello guys,
Im using TFS 1.3, when i cast it, i just get:
Code:
There is not enough room.
And nothing happens :rolleyes: I tried to understand the scrip but im stucked o_O:p

Sounds like you miss some param in spells.xml

Try all of this

XML:
aggressive="0" selftarget="0" needtarget="0"  casterTargetOrDirection="1" blockwalls="1"
 
Testei, com a ultima atualização que você fez e esta funcionando 100% no TFS 1.4.2!!!
 
Back
Top