Advertisement
Tectoon

[TFM] Gerenciador de Sorteio

Apr 27th, 2015
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.95 KB | None | 0 0
  1. -- Gerenciador de sorteios
  2.  
  3. adm = "Seu nick"
  4. nome = "Sorteio de Teste"
  5. 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>]]
  6.  
  7. participante = {}
  8. inicio = false
  9. fim = false
  10. qtd = 0
  11. fast = 0
  12.  
  13. function eventTextAreaCallback(id, p, cmd)
  14.     if cmd == "entrada" then
  15.         ui.addTextArea(0, "<p align='center'>Participando", p, 200, 370, 400, 20, 1, 0x00ff00, 0.8,false)
  16.         entrada(p, #participante + 1)
  17.     elseif cmd == "inicio" then
  18.         ui.addPopup(0, 2, "<p align='center'>Quantidade de sorteados", p, 300, 200, 200, false)
  19.     elseif cmd == "novo" then
  20.         novo()
  21.     end
  22. end
  23.  
  24. function eventNewPlayer(p)
  25.     if not inicio and not fim then
  26.         ui.addTextArea(0, "<p align='center'><a href='event:entrada'>Clique para participar do sorteio!", p, 200, 370, 400, 20, 1, 0xffff00, 0.8, false)
  27.         ui.addTextArea(-3, "<p align='center'><font size='30px'>"..nome, p, 5, 40, 795, 40, 1, 1, 0.8, false)
  28.     end
  29. end
  30.  
  31. function eventPopupAnswer(id, p, cmd)
  32.     if tonumber(cmd, 10) then
  33.         if tonumber(cmd, 10) >= 1 and tonumber(cmd, 10) <= #participante then
  34.             ui.removeTextArea(0, nil)
  35.             ui.removeTextArea(-1, nil)
  36.             qtd = tonumber(cmd, 10)
  37.             fast = math.random(5,15)
  38.             inicio = true
  39.         end
  40.     end
  41. end
  42.  
  43. function participando(p)
  44.     for i, v in pairs(participante) do
  45.         if v == p then
  46.             return true
  47.         end
  48.     end
  49.     return false
  50. end
  51.  
  52. function entrada(p, num)
  53.     if not participando(p) then
  54.         participante[num] = p
  55.         ui.addTextArea(num, "<p align='center'>" .. p, nil, ((num-1)%8)*100+5, math.floor((num-1)/8)*30+100, 90, 20, 1, 1, 0.8, false)
  56.     end
  57. end
  58.  
  59. function novo()
  60.     for i=1, #participante do
  61.         ui.removeTextArea(i, nil)
  62.         table.remove(participante, 1)
  63.     end
  64.     ui.addTextArea(0, "<p align='center'><a href='event:entrada'>Clique para participar do sorteio!", nil, 200, 370, 400, 20, 1, 0xffff00, 0.8, false)
  65.     ui.addTextArea(-1, "<p align='center'><a href='event:inicio'>Iniciar", adm, 650, 370, 100, 20, 1, 0x0000ff, 0.8,false)
  66.     tfm.exec.removePhysicObject(0)
  67.     fim = false
  68. end
  69.  
  70. function sorteio(tipo)
  71.     local lista = {}
  72.     local sorteado = 0
  73.     for i=1, #participante do
  74.         lista[i] = i
  75.     end
  76.     local rand = 0
  77.     for i, v in pairs(participante) do
  78.         ui.addTextArea(i, "<p align='center'>" .. v, nil, ((i-1)%8)*100+5, math.floor((i-1)/8)*30+100, 90, 20, 1, 1, 0.8, false)
  79.     end
  80.     for i=1, qtd do
  81.         sorteado = math.random(#lista)
  82.         rand = lista[sorteado]
  83.         table.remove(lista, rand)
  84.         if tipo == "quase" then
  85.             ui.addTextArea(rand, "<p align='center'><font color='#ffff00'>" .. participante[rand], nil, ((rand-1)%8)*100+5, math.floor((rand-1)/8)*30+100, 90, 20, 1, 0xffff00, 0.8, false)
  86.         elseif tipo == "final" then
  87.             ui.addTextArea(rand, "<p align='center'><font color='#00ff00'><b>" .. participante[rand], nil, ((rand-1)%8)*100+5, math.floor((rand-1)/8)*30+100, 90, 20, 1, 0x00ff00, 0.8, false)
  88.         end
  89.     end
  90. end
  91.  
  92. function eventLoop()
  93.     if inicio then
  94.         if fast > 0 then
  95.             sorteio("quase")
  96.             fast = fast - 1
  97.         else
  98.             sorteio("final")
  99.             inicio = false
  100.             fim = true
  101.             ui.addTextArea(-1, "<p align='center'><a href='event:novo'>Novo sorteio", adm, 650, 370, 100, 20, 1, 0x0000ff, 0.8,false)
  102.         end
  103.     end
  104.     if fim then
  105.         tfm.exec.addPhysicObject(0, 400, 200, {type=12,color=math.random(0x666666, 0x777777), miceCollision=true, width=800, height=400})
  106.         for i=1, 50 do
  107.             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)
  108.         end
  109.     end
  110. end
  111.  
  112. tfm.exec.disableAutoShaman(true)
  113. tfm.exec.disableAutoNewGame(true)
  114. tfm.exec.newGame(mapa)
  115. ui.addTextArea(0, "<p align='center'><a href='event:entrada'>Clique para participar do sorteio!", nil, 200, 370, 400, 20, 1, 0xffff00, 0.8, false)
  116. ui.addTextArea(-1, "<p align='center'><a href='event:inicio'>Iniciar", adm, 650, 370, 100, 20, 1, 0x0000ff, 0.8,false)
  117. ui.addTextArea(-3, "<p align='center'><font size='30px'>"..nome, nil, 5, 40, 795, 40, 1, 1, 0.8, false)
  118. tfm.exec.setUIMapName("Script de sorteios")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement