Brenower

[Minigame] Squish Bird

Feb 13th, 2014
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.59 KB | None | 0 0
  1. -- Squish Bird
  2. -- Tables
  3. -- Créditos:Brenower  |  Outros créditos você encontra pelo script. :D
  4. birds = {};
  5. player = "Ninguém";
  6. score = 0;
  7. tube = 0;
  8. time = 0;
  9. game = 0;
  10. bx = {};
  11. data = {};
  12. p = {};
  13. tx = 0;
  14. -- Functions
  15. function choosePlayer()
  16.     local score = -1;
  17.     local p = nil;
  18.     for i,v in pairs(tfm.get.room.playerList) do
  19.         if v.score > score and i ~= player then
  20.             score = v.score;
  21.             p = i;
  22.         end
  23.     end
  24.     return p
  25. end
  26.  
  27. function check(pla)
  28.     for i,v in pairs(p) do
  29.         if pla == v then
  30.             return true
  31.         end
  32.     end
  33. end
  34.  
  35. function bestScores(pl)
  36.     for i = #p,1,-1 do
  37.         table.remove(p,i)
  38.     end
  39.     local s = 0;
  40.     for i,v in pairs(tfm.get.room.playerList) do
  41.         if v.score > s and check(i) ~= true then
  42.             score = v.score;
  43.             table.insert(p,i)
  44.         end
  45.     end
  46.     if p[1] then
  47.         ui.addPopup(0,0,"<font size='12'>Melhores pontuações:<br /><br /><font color='#6C77C1'>"..p[#p].." <font color='#606090'>- <font color='#BABD2F'>"..data[p[#p]].score,pl,300,175,200,true)
  48.     end
  49.     if p[2] then
  50.         ui.addPopup(0,0,"<font size='12'>Melhores pontuações:<br /><br /><font color='#6C77C1'>"..p[#p].." <font color='#606090'>- <font color='#BABD2F'>"..data[p[#p]].score.."<br /><font color='#6C77C1'>"..p[#p-1].." <font color='#606090'>- <font color='#BABD2F'>"..data[p[#p-1]].score.."",pl,300,175,200,true)
  51.     end
  52.     if p[3] then
  53.         ui.addPopup(0,0,"<font size='12'>Melhores pontuações:<br /><br /><font color='#6C77C1'>"..p[#p].." <font color='#606090'>- <font color='#BABD2F'>"..data[p[#p]].score.."<br /><font color='#6C77C1'>"..p[#p-1].." <font color='#606090'>- <font color='#BABD2F'>"..data[p[#p-1]].score.."<br /><font color='#6C77C1'>"..p[#p-2].." <font color='#606090'>- <font color='#BABD2F'>"..data[p[#p-2]].score.."",pl,300,175,200,true)
  54.     end
  55. end
  56.  
  57. function moveTheTube()
  58.     if tube == 1 then
  59.         tx = tx + 5;
  60.         if tx <= 80 then
  61.             ui.addTextArea(1000,"",nil,350,300-tx,100,800,0xA0C654,0x000000,1)
  62.             ui.addTextArea(2000,"",nil,350,-675+tx,100,800,0xA0C654,0x000000,1)
  63.         elseif tx >= 80 then
  64.             tube = 0;
  65.             tx = 0;
  66.             ui.addTextArea(1000,"",nil,350,300,100,800,0xA0C654,0x000000,1)
  67.             ui.addTextArea(2000,"",nil,350,-675,100,800,0xA0C654,0x000000,1)
  68.         end
  69.     end
  70. end
  71.  
  72. function givePoints()
  73.     for i in pairs(birds) do
  74.         if bx[i] >= 345 and bx[i] <= 445 then
  75.             score = score + 1;
  76.             data[player].score = data[player].score + 1;
  77.             tfm.exec.setPlayerScore(player,data[player].score,false)
  78.             bx[i] = 10;
  79.         end
  80.     end
  81.     if score == 10 then
  82.         score = 0;
  83.         table.insert(birds,#birds+1)
  84.         table.insert(bx,10)
  85.     end
  86. end
  87.  
  88. function hasTheBestScore()
  89.     if data[player].score > data[p[#p]].score then
  90.         local particle = math.random(0,2) -- Fogos de artificio por Stheblindd
  91.         local x = math.random(0,800)
  92.         local y = math.random(30,75)
  93.         for i=0,2 do
  94.             tfm.exec.displayParticle(particle,x,y,0.2F,0.2F,0.2F,0.2F,nil)
  95.             tfm.exec.displayParticle(particle,x,y,-0.2F,-0.2F,-0.2F,-0.2F,nil)
  96.             tfm.exec.displayParticle(particle,x,y,0F,0.2F,0F,0.2F,nil)
  97.             tfm.exec.displayParticle(particle,x,y,0F,-0.2F,0F,-0.2F,nil)
  98.             tfm.exec.displayParticle(particle,x,y,0.2F,0F,0.2F,0F,nil)
  99.             tfm.exec.displayParticle(particle,x,y,-0.2F,0F,-0.2F,0F,nil)
  100.             particle = math.random(0,2)
  101.         end
  102.     end
  103. end
  104.  
  105. function f5MapName()
  106.     local time = string.format("%.2d:%.2d",time/60%60, time%60) -- Tempo por Eshkation
  107.     tfm.exec.setUIMapName("<n>Jogador : <j>"..player.."   <bl>|   <n>Pontos : <v>"..data[player].score.."   <bl>|   <n>Tempo :<v> "..time.."<p")
  108. end
  109. -- Novo jogador entra na sala
  110. function eventNewPlayer(p)
  111.     if not data[p] then
  112.         data[p] = {
  113.             ["score"] = 0;
  114.     };
  115.     end
  116.     system.bindMouse(p,true)
  117. end
  118. -- Inicio do script
  119. tfm.exec.disableAutoShaman(true)
  120. tfm.exec.disableAutoNewGame(true)
  121. tfm.exec.disableAutoTimeLeft(true)
  122. tfm.exec.disableAfkDeath(true)
  123. tfm.exec.disableAutoScore(true)
  124. tfm.exec.newGame('<C><P Ca="" /><Z><S /><D><P X="800" P="0,1" C="bcd374" Y="-200" T="34" /><P X="0" P="0,0" C="4c7942" Y="200" T="34" /></D><O /></Z></C>')
  125. for i in pairs(tfm.get.room.playerList) do
  126.     eventNewPlayer(i)
  127. end
  128. -- Loop
  129. function eventLoop(ct,rt)
  130.     bestScores("A")
  131.     time = time + 0.5;
  132.     if p[1] then
  133.         hasTheBestScore()
  134.     end
  135.     moveTheTube()
  136.     if time >= 3 and game == 0 then
  137.         f5MapName()
  138.         tfm.exec.setGameTime(999)
  139.         for i,v in pairs(birds) do
  140.             bx[i] = bx[i] + math.random(-3,20);
  141.             ui.addTextArea(v,"<R>B",nil,bx[i],200+math.random(-50,50),10,10,0xFBEA2B,1,0.6)
  142.             if bx[i] >= 500 then
  143.                 game = 1;
  144.                 tfm.exec.setGameTime(10)
  145.                 tfm.exec.setUIMapName("<n>Jogador : <j>"..player.."   <bl>|   <n>Pontos :<v> "..data[player].score.."   <bl>|   <r>O "..player.." perdeu o jogo. :(")
  146.             end
  147.         end
  148.     end
  149.     if rt <= 0 then
  150.         tfm.exec.newGame('<C><P Ca="" /><Z><S /><D><P X="800" P="0,1" C="bcd374" Y="-200" T="34" /><P X="0" P="0,0" C="4c7942" Y="200" T="34" /></D><O /></Z></C>')
  151.     end
  152. end
  153. -- Novo jogo é iniciado
  154. function eventNewGame()
  155.     for i = #birds,1,-1 do
  156.         ui.removeTextArea(birds[i],nil)
  157.         table.remove(birds,i)
  158.         table.remove(bx,i)
  159.     end
  160.     for i in pairs(tfm.get.room.playerList) do
  161.         tfm.exec.setPlayerScore(i,data[i].score,false)
  162.     end
  163.     table.insert(birds,1)
  164.     table.insert(bx,10)
  165.     time = -3;
  166.     game = 0;
  167.     score = 0;
  168.     tube = 0;
  169.     tx = 0;
  170.     player = choosePlayer();
  171.     data[player].score = 0;
  172.     ui.addTextArea(1000,"",nil,350,300,100,800,0xA0C654,0x000000,1,true)
  173.     ui.addTextArea(2000,"",nil,350,-675,100,800,0xA0C654,0x000000,1,true)
  174. end
  175. -- Comandos
  176. function eventChatCommand(p,cm)
  177.     if cm == [[scores]] then
  178.         bestScores(p)
  179.     end
  180. end
  181. -- Eventos do mouse
  182. function eventMouse(p,x,y)
  183.     if p == player then
  184.         tube = 1;
  185.         givePoints()
  186.     end
  187. end
Advertisement
Add Comment
Please, Sign In to add comment