Lua:
local config = {
actionId = 21501,
Area1 = {
fromPos = Position(20444, 20255, 1), -- Upper left corner of the room
toPos = Position(20541, 20309, 1), -- Lower right corner of the room
entrancePos = Position(20450, 20293, 1),
exitPosition = Position(20377, 20286, 3)
},
Area2 = {
fromPos = Position(20444, 20255, 1), -- Upper left corner of the room
toPos = Position(20541, 20309, 1), -- Lower right corner of the room
entrancePos = Position(20450, 20293, 1),
exitPosition = Position(20377, 20286, 3)
},
Area3 = {
fromPos = Position(20444, 20255, 1), -- Upper left corner of the room
toPos = Position(20541, 20309, 1), -- Lower right corner of the room
entrancePos = Position(20450, 20293, 1),
exitPosition = Position(20377, 20286, 3)
},
participantsPos = {
Position(20380, 20282, 3)
},
attempts = {
level = 100, -- Level required to enter
seconds = 72000 -- 20 hours
},
kickAfterSeconds = 60 * 1, -- 25 minutes
}
local function getSpectators()
if not config.centerPosition then
config.diffX = math.ceil((config.Area1.toPos.x - config.Area1.fromPos.x) / 2)
config.diffY = math.ceil((config.Area1.toPos.y - config.Area1.fromPos.y) / 2)
config.centerPosition = config.Area1.fromPos + Position(config.diffX, config.diffY, 0)
end
return Game.getSpectators(config.centerPosition, false, false, config.diffX, config.diffX, config.diffY, config.diffY)
end
local test = Action()
function test.onUse(player, item, fromPos, target, toPos, isHotkey)
local participants = {}
for index, pos in pairs(config.participantsPos) do
local tile = Tile(pos)
if not tile then error("[Warning - Tile not found]") end
local participant = tile:getTopVisibleCreature(player)
if participant and participant:isPlayer() then
if index == 1 and participant ~= player then
player:sendCancelMessage("Only the first participant can pull the lever.")
return true
end
participants[#participants +1] = participant
end
end
local spectators = getSpectators()
for _, spectator in pairs(spectators) do
if spectator:isPlayer() then
player:sendCancelMessage("At this time the room is occupied, please try again later.")
return true
end
end
for _, spectator in pairs(spectators) do spectator:remove() end
for index, participant in pairs(participants) do
participant:teleportTo(config.Area1.entrancePos, false)
end
config.kickEventId = addEvent(function ()
for _, spectator in pairs(getSpectators()) do
if spectator:isPlayer() then
spectator:teleportTo(config.Area1.exitPosition, false)
config.Area1.exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
spectator:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It's been a long time and you haven't managed to defeat the boss.")
else
spectator:remove()
end
end
end, config.kickAfterSeconds * 1000)
return true
end
test:aid(config.actionId)
test:register()
Good night, I'm trying to make that when the player pulls the lever he will be teleported to area1 if there is a player in area1 he will be teleported to area2.
with a time limit of 30 minutes