local config =
{
duration = 20*60,
exitPos = Position(xx, xx, x), -- teleport poss
centerRoomPosition = Position(xx, xx, xx), -- room center
exitMessage = "Your time has been expired!"
}
local function doKickPlayer(cid)
local player = Player(cid)
if not player then
return
end
player:teleportTo(config.exitPos)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, config.exitMessage)
end
function onStepIn(creature, item, position, fromPosition)
local specs = Game.getSpectators(config.centerRoomPosition, false, false, 20, 20, 20, 20)
local count = 0
for i = 1, #specs do
local spectator = specs[i]
if spectator:isPlayer() then
count = count + 1
end
end
if (count > xx) then -- max players
check = addEvent(doKickPlayer, config.duration * 1000, creature:getId())
end
end
function onStepOut(creature, item, position, fromPosition)
local player = creature:getPlayer()
if not player or player:isInGhostMode() then
return true
end
return stopEvent(check, cid)
end