local event = {
{ color = 'BLACK', outfit = {lookType = 134, lookHead = 114, lookBody = 114, lookLegs = 114, lookFeet = 114},
text = "-BR-\nVocê entrou! Aguarde o ínicio do evento. Você precisa matar todos os players do time adversário e SOBREVIVER para obter a recompensa.\n\n-ENG-\nYou entered! Wait for the event start. You need to kill all the players of the opposing team and SURVIVE for win the reward.", destination = {x = 713, y = 763, z = 6}, storage = { p = 261, g = 262)
},
{ color = 'RED', outfit = {lookType = 143, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94},
text = "-BR-\nVocê entrou! Aguarde o ínicio do evento. Você precisa matar todos os players do time adversário e SOBREVIVER para obter a recompensa.\n\n-ENG-\nYou entered! Wait for the event start. You need to kill all the players of the opposing team and SURVIVE for win the reward.", destination = {x = 656, y = 795, z = 6}, storage = { p = 260, g = 259)
}
}
local oufits = {}
for i = 1, #event do
outfits[event[i].color] = createConditionObject(CONDITION_OUTFIT)
setConditionParam(outfits[event[i].color], CONDITION_PARAM_TICKS, -1)
addOutfitCondition(outfits[event[i].color], event[i].outfit)
end
local centerOfEventRoom = {x = 0, y = 0, z = 0}
local eventRoom = {width = 7, height = 7}
--------------------------------------------------------------------------------------------------
-- get everyone in the event room
local players = getSpectators(centerOfEventRoom, eventRoom.width, eventRoom.height, false)
local levels = {}
local pid = {}
-- create the teams
local team = {}
for i = 1, #event do
team[event[i].color] = {}
end
-- get everyone's levels & their id's
for i, cid in ipairs(players) do
if isPlayer(cid) then
pid[i] = cid
table.insert(levels, getPlayerLevel(pid[i]))
end
end
-- sort the players levels
table.sort(levels, function(a, b) return a < b end)
-- try to evenly place them on teams
for x = 1, #levels do
if getPlayerLevel(pid[x]) == levels[x] then
team[x % 2 == 0 and event[1].color or event[2].color][x] = pid[x]
end
end
-- teleport everyone to their destinations on their respective teams
for i = 1, #event do
for n = 1, #team[event[i].color] do
local id = team[event[i].color][n]
setPlayerStorageValue(id, event[i].storage.p, 1)
setGlobalStorageValue(event[i].storage.g, getGlobalStorageValue(event[i].storage.g) + 1)
doAddCondition(id, outfits[event[i].color])
doTeleportThing(id, event[i].destination)
doCreatureSetNoMove(id, true)
oPlayerPopupFYI(id, event[i].text)
end
end
----------------------------------------------------------------------------------------------------------
return true
end