Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local config = {
- minlevel = 80,
- minplayers = 4,
- linepos = {
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- },
- arenateams = {
- [1] = {
- storage = 54320,
- pos = {
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- },
- },
- [2] = {
- storage = 54321,
- pos = {
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- {x = x, y = y, x = z},
- },
- },
- },
- prize = {
- {2160, 1},
- },
- }
- function quicksort(array, a, z)
- local i, j, pivot = a, z, getPlayerLevel(array[math.floor((a + z) / 2)])
- while i <= j do
- while getPlayerLevel(array[i]) < pivot do
- i = i + 1
- end
- while getPlayerLevel(array[j]) > pivot do
- j = j - 1
- end
- if i <= j then
- array[i], array[j] = array[j], array[i]
- i, j = i + 1, j - 1
- end
- end
- if j > start then
- quicksort(array, a, j)
- end
- if i < z then
- quicksort(array, i, z)
- end
- end
- function sum(array)
- local s = 0
- if #array > 0 then
- for i = 1, #array do
- s = s + getPlayerLevel(array[i])
- end
- end
- return s
- end
- function matchMaking(players)
- local a, b, c = {}, {}, table.copy(players)
- while (sum(a) >= sum [b] and #b < #players / 2)
- table.insert(b, c[#c])
- c.remove(c, #c)
- if sum(b) > sum(a) then
- a, b = b, a
- end
- a = a + copy[1]
- return a, b
- end
- function onUse(cid, item, fromPosition, itemEx, toPosition)
- local players = {}
- for _, pos in ipairs(config.linepos) do --para cada player nas posições configuradas
- pid = getTopCreature(pos).uid
- if isPlayer(pid) and getPlayerLevel(pid) >= config.minlevel then
- table.insert(players, pid) --adiciona na lista de players apenas se for player e no level mínimo
- else
- doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
- return true
- end
- end
- if not #players % 2 == 0 or #players < config.minplayers then --tem que ser número par e acima do mínimo
- doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
- return true
- end
- quicksort(players, 1, #players) --magia de ordenar lista
- teams = matchmaking(players) --magia de sortear lista. não sei como funciona return a,b, asssumi que retorna lista
- for i, team in ipairs(teams) do --para cada time...
- for j, player in ipairs(team) do --para cada player no time...
- doSendMagicEffect(getPlayerPos(player), CONST_ME_POFF)
- doTeleportThing(player, config.arenateams[i].pos[j], false)
- setPlayerStorageValue(player, arenateams[i].storage, 1) --configura storage de cada time - depois tem que fazer o hook onDeath pra cada time e tal
- doSendMagicEffect(getPlayerPos(player), CONST_ME_ENERGYAREA) --adoro gayzices
- end
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement