Advertisement
KananGamer

Sorteio Mboscol0

Jun 10th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.37 KB | None | 0 0
  1. adm = "Mboscol0"
  2. nome = "Sorteio de 400 Morangos 18:45 (Se sair perde a chance)"
  3. mapa = [[<C><P Ca=""/><Z><S><S H="40" P="0,0,0.3,0.2,0,0,0,0" L="800" X="399" N="" Y="380" T="0" /></S><D /><O /></Z></C>]]
  4.  
  5. participante = {}
  6. inicio = false
  7. fim = false
  8. qtd = 0
  9. fast = 0
  10.  
  11. function eventChatCommand(name, m)
  12. if m == "reset" then
  13. if name == adm then
  14. novo()
  15. end
  16. end
  17. if m == "iniciar" then
  18. ui.addPopup(0, 2, "<p align='center'>Quantidade de sorteados", adm, 300, 200, 200, false)
  19. end
  20. end
  21.  
  22. function eventPlayerDied(name)
  23.     tfm.exec.respawnPlayer(name)
  24. end
  25.  
  26. function eventTextAreaCallback(id, p, cmd)
  27.     if cmd == "entrada" then
  28.     elseif cmd == "inicio" then
  29.         ui.addPopup(0, 2, "<p align='center'>Quantidade de sorteados", p, 300, 200, 200, false)
  30.     elseif cmd == "novo" then
  31.         novo()
  32.     end
  33. end
  34.  
  35.  
  36. function eventPopupAnswer(id, p, cmd)
  37.     if tonumber(cmd, 10) then
  38.         if tonumber(cmd, 10) >= 1 and tonumber(cmd, 10) <= #participante then
  39.             ui.removeTextArea(0, nil)
  40.             ui.removeTextArea(-1, nil)
  41.             qtd = tonumber(cmd, 10)
  42.             fast = math.random(5,15)
  43.             inicio = true
  44.         end
  45.     end
  46. end
  47.  
  48. function participando(p)
  49.     for i, v in pairs(participante) do
  50.         if v == p then
  51.             return true
  52.         end
  53.     end
  54.     return false
  55. end
  56.  
  57. function entrada(p, num)
  58.     if not participando(p) then
  59.         participante[num] = p
  60.         ui.addTextArea(num, "<p align='center'>" .. p, nil, ((num-0.2)%9)*80-30, math.floor((num-0.2)/9)*20+80, 90, 15, 1, 1, 0.8, false)
  61.     end
  62. end
  63.  
  64. function novo()
  65.     for i=1, #participante do
  66.         ui.removeTextArea(i, nil)
  67.         table.remove(participante, 1)
  68.     end
  69.     ui.addTextArea(-1, "<p align='center'><a href='event:inicio'>Iniciar", adm, 650, 370, 100, 20, 1, 0x0000ff, 0.8,false)
  70.     tfm.exec.removePhysicObject(0)
  71.     fim = false
  72. end
  73.  
  74. function sorteio(tipo)
  75.     local lista = {}
  76.     local sorteado = 0
  77.     for i=1, #participante do
  78.         lista[i] = i
  79.     end
  80.     local rand = 0
  81.     for i, v in pairs(participante) do
  82.         ui.addTextArea(i, "<p align='center'>" .. v, nil, ((i-0.2)%9)*80-30, math.floor((i-0.2)/9)*20+80, 90, 15, 1, 1, 0.8, false)
  83.     end
  84.     for i=1, qtd do
  85.         sorteado = math.random(#lista)
  86.         rand = lista[sorteado]
  87.         table.remove(lista, sorteado)
  88.         if tipo == "quase" then
  89.             ui.addTextArea(rand, "<p align='center'><font color='#ffff00'>" .. participante[rand], nil, ((rand-0.2)%9)*80-30, math.floor((rand-0.2)/9)*20+80, 90, 15, 1, 0xffff00, 0.8, false)
  90.         elseif tipo == "final" then
  91.             ui.addTextArea(rand, "<p align='center'><font color='#00ff00'><b>" .. participante[rand], nil, ((rand-0.2)%9)*80-30, math.floor((rand-0.2)/9)*20+80, 90, 15, 1, 0x00ff00, 0.8, false)
  92.         end
  93.     end
  94. end
  95.  
  96. function eventLoop()
  97.     if inicio then
  98.         if fast > 0 then
  99.             sorteio("quase")
  100.             fast = fast - 1
  101.         else
  102.             sorteio("final")
  103.             inicio = false
  104.             fim = true
  105.             ui.addTextArea(-1, "<p align='center'><a href='event:novo'>Novo sorteio", adm, 650, 370, 100, 20, 1, 0x0000ff, 0.8,false)
  106.         end
  107.     end
  108.     if fim then
  109.         tfm.exec.addPhysicObject(0, 400, 200, {type=12,color=math.random(0x666666, 0x777777), miceCollision=false, width=800, height=400})
  110.         for i=1, 50 do
  111.             tfm.exec.displayParticle(math.random(21,24), math.random(1,800), 20, math.random(-20,20)/100, math.random(10,1000)/100, 0, 0, nil)
  112.         end
  113.     end
  114. end
  115.  
  116. function eventNewPlayer(p)
  117.     entrada(p, #participante + 1)
  118.     if not inicio and not fim then
  119.         ui.addTextArea(-3, "<p align='center'><font size='20px'>"..nome, p, 5, 40, 795, 40, 1, 1, 0.8, false)
  120.     end
  121. end
  122.  
  123. for p,player in pairs(tfm.get.room.playerList) do
  124.     eventNewPlayer(p)
  125. end
  126.  
  127. tfm.exec.disableAutoNewGame(true)
  128. tfm.exec.disableAutoShaman(true)
  129. tfm.exec.disableAutoTimeLeft(true)
  130. tfm.exec.disableAfkDeath(true)
  131. tfm.exec.disableAutoScore(true)
  132. tfm.exec.newGame(mapa)
  133. ui.addTextArea(-1, "<p align='center'><a href='event:inicio'>Iniciar", adm, 650, 370, 100, 20, 1, 0x0000ff, 0.8,false)
  134. ui.addTextArea(-3, "<p align='center'><font size='20px'>"..nome, nil, 5, 20, 795, 40, 1, 1, 0.8, false)
  135. tfm.exec.setUIMapName("Script de sorteios")
  136. system.disableChatCommandDisplay("iniciar")
  137. system.disableChatCommandDisplay("reset")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement