Advertisement
ranisalt

Blaster Arena

May 27th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.39 KB | None | 0 0
  1. local config = {
  2.     minlevel = 80,
  3.     minplayers = 4,
  4.     linepos = {
  5.         {x = x, y = y, x = z},
  6.         {x = x, y = y, x = z},
  7.         {x = x, y = y, x = z},
  8.         {x = x, y = y, x = z},
  9.         {x = x, y = y, x = z},
  10.         {x = x, y = y, x = z},
  11.         {x = x, y = y, x = z},
  12.         {x = x, y = y, x = z},
  13.     },
  14.     arenateams = {
  15.         [1] = {
  16.             storage = 54320,
  17.             pos = {
  18.                 {x = x, y = y, x = z},
  19.                 {x = x, y = y, x = z},
  20.                 {x = x, y = y, x = z},
  21.                 {x = x, y = y, x = z},
  22.             },
  23.         },
  24.         [2] = {
  25.             storage = 54321,
  26.             pos = {
  27.                 {x = x, y = y, x = z},
  28.                 {x = x, y = y, x = z},
  29.                 {x = x, y = y, x = z},
  30.                 {x = x, y = y, x = z},
  31.             },
  32.         },
  33.     },
  34.     prize = {
  35.         {2160, 1},
  36.     },
  37. }
  38.  
  39. function quicksort(array, a, z)
  40.     local i, j, pivot = a, z, getPlayerLevel(array[math.floor((a + z) / 2)])
  41.     while i <= j do
  42.         while getPlayerLevel(array[i]) < pivot do
  43.             i = i + 1
  44.         end
  45.         while getPlayerLevel(array[j]) > pivot do
  46.             j = j - 1
  47.         end
  48.         if i <= j then
  49.             array[i], array[j] = array[j], array[i]
  50.             i, j = i + 1, j - 1
  51.         end
  52.     end
  53.     if j > start then
  54.         quicksort(array, a, j)
  55.     end
  56.     if i < z then
  57.         quicksort(array, i, z)
  58.     end
  59. end
  60.  
  61. function sum(array)
  62.     local s = 0
  63.     if #array > 0 then
  64.         for i = 1, #array do
  65.             s = s + getPlayerLevel(array[i])
  66.         end
  67.     end
  68.     return s
  69. end
  70.  
  71. function matchMaking(players)
  72.     local a, b, c = {}, {}, table.copy(players)
  73.     while (sum(a) >= sum [b] and  #b < #players / 2)
  74.         table.insert(b, c[#c])
  75.         c.remove(c, #c)
  76.         if sum(b) > sum(a) then
  77.             a, b = b, a
  78.         end
  79.     a  = a + copy[1]
  80.     return a, b
  81. end
  82.  
  83. function onUse(cid, item, fromPosition, itemEx, toPosition)
  84.     local players = {}
  85.     for _, pos in ipairs(config.linepos) do --para cada player nas posições configuradas
  86.         pid = getTopCreature(pos).uid
  87.         if isPlayer(pid) and getPlayerLevel(pid) >= config.minlevel then
  88.             table.insert(players, pid) --adiciona na lista de players apenas se for player e no level mínimo
  89.         else
  90.             doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
  91.             return true
  92.         end
  93.     end
  94.     if not #players % 2 == 0 or #players < config.minplayers then --tem que ser número par e acima do mínimo
  95.         doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
  96.         return true
  97.     end
  98.     quicksort(players, 1, #players) --magia de ordenar lista
  99.     teams = matchmaking(players) --magia de sortear lista. não sei como funciona return a,b, asssumi que retorna lista
  100.     for i, team in ipairs(teams) do --para cada time...
  101.         for j, player in ipairs(team) do --para cada player no time...
  102.             doSendMagicEffect(getPlayerPos(player), CONST_ME_POFF)
  103.             doTeleportThing(player, config.arenateams[i].pos[j], false)
  104.             setPlayerStorageValue(player, arenateams[i].storage, 1) --configura storage de cada time - depois tem que fazer o hook onDeath pra cada time e tal
  105.             doSendMagicEffect(getPlayerPos(player), CONST_ME_ENERGYAREA) --adoro gayzices
  106.         end
  107.     end
  108.     return true
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement