noshirtstan
New Member
- Joined
- Aug 2, 2020
- Messages
- 68
- Reaction score
- 2
Hey folks, I'm trying to get this script to work properly, but everytime i try to use it, i get the following error.
Here is the code that I have so far.
Any thoughts?
Using TFS 1.2
Lua:
Lua Script Error: [Action Interface]
data/actions/scripts/quests/floorboss1.lua:onUse
data/actions/scripts/quests/floorboss1.lua:68: attempt to call method 'getThing' (a nil value)
stack traceback:
[C]: in function 'getThing'
data/actions/scripts/quests/floorboss1.lua:68: in function <data/actions/scripts/quests/floorboss1.lua:45>
Here is the code that I have so far.
Code:
local area = { --This checks a square area defined by the top left and bottom right positions
min = {x = 242, y = 1929}, --Set this to the top left square of area you want to check
max = {x = 242, y = 1931} --Set this to the bottom right square of area you want to check
}
local area_teleport_to = {
min = {x = 237, y = 1929}, -- Area top left to teleport players
min = {x = 239, y = 1931} -- Area bottom right to teleport players
}
local posz = 15 --Floor its checking
local Config = {
bossName = 'Rat', -- boss name
bossPosition = Position(223, 1934, 15), -- Boss Position
centerPosition = Position(230, 1931, 15), -- Center Room
exitPosition = Position(237, 1922, 15), -- Exit Position
rangeX = 1,
rangeY = 1,
time = 5, -- time in minutes to remove the player
}
local function roomIsOccupied(centerPosition, rangeX, rangeY)
local spectators = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY)
if #spectators ~= 0 then
return true
end
return false
end
function clearBossRoom(centerPosition, rangeX, rangeY, exitPosition)
local spectators, spectator = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY)
for i = 1, #spectators do
spectator = spectators[i]
if spectator:isPlayer() then
spectator:teleportTo(exitPosition)
exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
end
if spectator:isMonster() then
spectator:remove()
end
end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local creature = Tile(player:getPosition()):getTopCreature()
if not creature or not creature:isPlayer() then
return true
end
if roomIsOccupied(Config.centerPosition, Config.rangeX, Config.rangeY) then
player:sendCancelMessage("There is someone in the room.")
return true
end
local monster = Game.createMonster(Config.bossName, Config.bossPosition)
if not monster then
return true
end
local area_x = area.min.x
local area_y = area.min.y
while area_x <= area.max.x do
while area_y <= area.max.y do
POS = {x = area_x, y = area_y, z = posz}
PLAYER = Player(POS:getThing())
if PLAYER then
PLAYER:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have entered an ancient demon prison cell!')
PLAYER:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have fifteen minutes to kill and loot this boss, else you will lose that chance.')
rand_pos = {x = math.random(area_teleport_to.min.x, area_teleport_to.max.x), y = math.random(area_teleport_to.min.y, area_teleport_to.max.y), z = posz}
PLAYER:teleportTo(rand_pos)
PLAYER:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end
area_x = area_x + 1
area_y = area_y + 1
end
end
addEvent(clearBossRoom, 60 * Config.time * 1000, Config.centerPosition, Config.rangeX, Config.rangeY, Config.exitPosition)
item:transform(item.itemid == 9825 and 9826 or 9825)
return true
end
Any thoughts?
Using TFS 1.2