• Vote in November Mapping Competition to select a winner!
  • 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 [TFS1.3] Time Guardian Spell

aqubjukr

Well-Known Member
Joined
Mar 13, 2013
Messages
177
Solutions
14
Reaction score
65
Location
Paraná, Brazil
I have a script from the boss time guardian (to change the phases), and I wanted to know what the reason for the error would be, since the "index" was set in top as a random number between 1 and 2. If you have a possible way to fix it, I would be grateful.

Console:
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/monster/time guardiann.lua:onCastSpell
data/spells/scripts/monster/time guardiann.lua:41: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/monster/time guardiann.lua:41: in function <data/spells/scripts/monster/time guardiann.lua:34>

Script:
Lua:
local monsters = {
    [1] = {pos = Position(32810, 32664, 14)},
    [2] = {pos = Position(32815, 32664, 14)}
}

local function functionBack(position, oldpos)
    local guardian = Tile(position):getTopCreature()
    local bool, diference, health = false, 0, 0
    local spectators, spectator = Game.getSpectators(Position(32813, 32664, 14), false, false, 15, 15, 15, 15)
    for v = 1, #spectators do
        spectator = spectators[v]
        if spectator:getName():lower() == 'the blazing time guardian' or spectator:getName():lower() == 'the freezing time guardian' then
            oldpos = spectator:getPosition()
            bool = true
        end
    end
    if not bool then
        guardian:remove()
        return true
    end
    local specs, spec = Game.getSpectators(Position(32813, 32664, 14), false, false, 15, 15, 15, 15)
    for i = 1, #specs do
        spec = specs[i]
        if spec:isMonster() and spec:getName():lower() == 'the blazing time guardian' or spec:getName():lower() == 'the freezing time guardian' then
            spec:teleportTo(position)
            health = spec:getHealth()
            diference = guardian:getHealth() - health
        end
    end
    guardian:addHealth( - diference)
    guardian:teleportTo(oldpos)
end

function onCastSpell(creature, var)
    local index = math.random(1, 2)
    local monsterPos = creature:getPosition()
    if monsterPos.z ~= 14 then
        return true
    end
    local position = monsters[index].pos
    local form = Tile(position):getTopCreature()
    creature:teleportTo(position)
    local diference, health = 0, 0
    health = creature:getHealth()
    diference = form:getHealth() - health
    form:addHealth( - diference)
    form:teleportTo(monsterPos)
    addEvent(functionBack, 30 * 1000, position, monsterPos)
    return true
end
 
OP
aqubjukr

aqubjukr

Well-Known Member
Joined
Mar 13, 2013
Messages
177
Solutions
14
Reaction score
65
Location
Paraná, Brazil
While this is not the solution, using print will always help in situations like this one :p
Thanks for the comment, I will try to do that next time.
I've made a script from scratch, to be sure of using everything correctly and that there would be no bugs.

Btw, thx.
Post automatically merged:

While this is not the solution, using print will always help in situations like this one :p
Thanks for the comment, I will try to do that next time.
I've made a script from scratch, to be sure of using everything correctly and that there would be no bugs.

Btw, thx.
 
Top