aqubjukr
Well-Known Member
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:
Script:
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