waitingRoom = { fromPos = {x = 630, y = 1028, z = 7}, toPos = {x = 636, y = 1034, z = 7} } redPlayers = 1200 bluePlayers = 2200 redGoal = 3200 blueGoal = 4200 redFlag = 5200 blueFlag = 5520 ctf = { redPos = {x = 1355, y = 93, z = 7}, bluePos = {x = 1379, y = 45, z = 6} } temple = {x = 1000, y = 1000, z = 7} local hcreatepos = {x=966,y=999,z=10} local htopos = {x=633,y=1035,z=7} local msg = "The teleport to the Capture The Flag event has been closed." local timetoclose = 280 -- in second local red, blue = {}, {} local conditionBlue = createConditionObject(CONDITION_OUTFIT) setConditionParam(conditionBlue, CONDITION_PARAM_TICKS, 1800 * 1000) addOutfitCondition(conditionBlue, {lookType = 130, lookHead = 120, lookBody = 120, lookLegs = 120, lookFeet = 120}) local conditionRed = createConditionObject(CONDITION_OUTFIT) setConditionParam(conditionRed, CONDITION_PARAM_TICKS, 1800 * 1000) addOutfitCondition(conditionRed, {lookType = 130, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94}) local function getPlayers(from, to) local list = {} for x = from.x, to.x do for y = from.y, to.y do for z = from.z, to.z do local creature = getTopCreature({x =x , y =y, z = z}).uid if isPlayer(creature) then table.insert(list, creature) end end end end return list end local function finishThis() local t = getPlayers(waitingRoom.fromPos, waitingRoom.toPos) if #t == 1 then doPlayerSendTextMessage(t[1], 27, "Find another player to play with.") doTeleportThing(t[1], temple, true) elseif #t == 2 then table.insert(red, t[1]) table.insert(blue, t[2]) elseif #t == 3 then table.insert(red, t[2]) table.insert(blue, t[3]) table.insert(red, t[1]) elseif #t == 4 then table.insert(red, t[1]) table.insert(blue, t[2]) table.insert(red, t[3]) table.insert(blue, t[4]) elseif #t == 5 then table.insert(red, t[1]) table.insert(blue, t[2]) table.insert(red, t[3]) table.insert(blue, t[4]) table.insert(red, t[5]) elseif #t == 6 then table.insert(red, t[1]) table.insert(blue, t[2]) table.insert(red, t[3]) table.insert(blue, t[4]) table.insert(red, t[5]) table.insert(blue, t[6]) elseif #t == 7 then table.insert(red, t[1]) table.insert(blue, t[2]) table.insert(red, t[3]) table.insert(blue, t[4]) table.insert(red, t[5]) table.insert(blue, t[6]) table.insert(red, t[7]) elseif #t == 8 then table.insert(red, t[1]) table.insert(blue, t[2]) table.insert(red, t[3]) table.insert(blue, t[4]) table.insert(red, t[5]) table.insert(blue, t[6]) table.insert(red, t[7]) table.insert(blue, t[8]) elseif #t == 9 then table.insert(red, t[1]) table.insert(blue, t[2]) table.insert(red, t[3]) table.insert(blue, t[4]) table.insert(red, t[5]) table.insert(blue, t[6]) table.insert(red, t[7]) table.insert(blue, t[8]) table.insert(red, t[9]) elseif #t == 10 then table.insert(red, t[1]) table.insert(blue, t[2]) table.insert(red, t[3]) table.insert(blue, t[4]) table.insert(red, t[5]) table.insert(blue, t[6]) table.insert(red, t[7]) table.insert(blue, t[8]) table.insert(red, t[9]) table.insert(blue, t[10]) else for _, v in ipairs(t) do if math.random(1, 3) < 3 then table.insert(red, v) else table.insert(blue, v) end end end if #red > 0 and #blue > 0 then for _, r in ipairs(red) do setPlayerStorageValue(r, redPlayers, 1) doAddCondition(r, conditionRed) doTeleportThing(r, ctf.redPos, true) red = {} end for _, b in ipairs(blue) do setPlayerStorageValue(b, bluePlayers, 1) doAddCondition(b, conditionBlue) doTeleportThing(b, ctf.bluePos, true) blue = {} end end return true end local function teleport() addEvent(doBroadcastMessage, 60 * 1 * 1000, "Capture The Flag will begin in 4 minutes.") addEvent(doBroadcastMessage, 60 * 2 * 1000, "Capture The Flag will begin in 3 minutes.") addEvent(doBroadcastMessage, 60 * 3 * 1000, "Capture The Flag will begin in 2 minutes.") addEvent(doBroadcastMessage, 60 * 4 * 1000, "Capture The Flag will begin in 1 minute.") addEvent(doBroadcastMessage, 57 * 5 * 1000, "Capture The Flag will begin in 15 seconds.") addEvent(finishThis, 5 * 60 * 1000) end local function remove() local tp = getTileItemById(hcreatepos,1387).uid if tp ~= 0 then doRemoveItem(tp) doBroadcastMessage(msg) end end function onThink() setGlobalStorageValue(3200, 0) setGlobalStorageValue(4200, 0) setGlobalStorageValue(5200, -1) setGlobalStorageValue(5520, -1) db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. 5200 .. ";") db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. 5520 .. ";") db.executeQuery("DELETE FROM `player_storage` WHERE `key`= " .. 1200 .. ";") db.executeQuery("DELETE FROM `player_storage` WHERE `key` = " .. 2200 .. ";") doCreateTeleport(1387, htopos, hcreatepos) doBroadcastMessage("The 'Capture The Flag' even will start in 5 minutes.") addEvent(remove,timetoclose*1000) return teleport() end