Dudugz-Contistente

Untitled

Oct 8th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.69 KB | None | 0 0
  1. keys={69,32,27}
  2.  
  3. players={}
  4.  
  5. data={}
  6.  
  7. ids={}
  8.  
  9. mapas={6879570,6879586,2173893,4392183,4569940,1870360,6882237,6882094,6883595}
  10.  
  11. shop={
  12. {"Bolinha Rosa",10,97,80},
  13. {"Bola de Papel",35,95,70},
  14. {"Galinha",75,33,50},
  15. {"Abóbora",100,89,60},
  16. {"Baiacu",250,65,40},
  17. {"Flecha",1000,35,30},
  18. }
  19.  
  20. maxPStatus = 6
  21. maxPMoney = 4
  22. maxPRoom = 20
  23. maxBalas = 50
  24.  
  25. vivos=0
  26. jogadores=0
  27.  
  28. function split(t,s)
  29. local a={}
  30. for i,v in string.gmatch(t,string.format("[^%s]+",s or "%s")) do
  31. table.insert(a,i)
  32. end
  33. return a
  34. end
  35.  
  36. function eventChatCommand(p, cmd)
  37. local arg = split(cmd, " ")
  38. if arg[1] == "p" then -- se o comando for p
  39. if arg[2] then -- se tiver o nome de alguem
  40. local nome = arg[2]:lower():gsub('%a', string.upper, 1) -- guarda na variavel
  41. --nome:lower():gsub('%a', string.upper, 1)
  42. if tfm.get.room.playerList[nome] then -- se tiver na sala (retornaria nil se n tivesse)
  43. perfil="<p align='center'><font size='16'><J>"..nome.."</J></font><br><font size='12'><N>Rodadas: <V>"..players[nome].rounds.."</V><br>Vitórias: <V>"..players[nome].wins.."</V><br>Mortes: <V>"..players[nome].kills.."</V><br>Moedas: <V>"..players[nome].moedas.."</V>"
  44. end
  45. else -- se ele só escreveu !p mostrar o perfil dele mesmo
  46. perfil="<p align='center'><font size='16'><J>"..p.."</J></font><br><font size='12'><N>Rodadas: <V>"..players[p].rounds.."</V><br>Vitórias: <V>"..players[p].wins.."</V><br>Mortes: <V>"..players[p].kills.."</V><br>Moedas: <V>"..players[p].moedas.."</V>"
  47. end
  48. ui.addTextArea(36,'<a href="event:perfilClose"><font color="#ff0000">Fechar</font></a>',p,250,102,60,nil,nil,0x6a8495,1,true)
  49. ui.addTextArea(35,perfil,p,300,100,300,140,nil,0x6a8495,1,true)
  50. end
  51. end
  52.  
  53. for _,f in pairs ({'disableAutoNewGame','disableAutoShaman','disableAutoTimeLeft','disableAutoScore'}) do
  54. tfm.exec[f](true)
  55. end
  56.  
  57. function nextRound()
  58. tfm.exec.newGame(mapas[math.random(#mapas)])
  59. end
  60.  
  61. function eventNewGame()
  62. vivos=0
  63. tfm.exec.setGameTime(100)
  64. for name in pairs(tfm.get.room.playerList) do
  65. vivos=vivos+1;
  66. if jogadores >= maxPStatus then
  67. players[name].rounds = players[name].rounds+1;
  68. end
  69. if players[name].balas < 10 then
  70. ui.addTextArea(6,"<B><J><p align='center'><V>0"..players[name].balas.."</V><N>/</N>"..maxBalas.."</p></J>",name,6,380,100,20,nil,0x6a8495,90,true)
  71. else
  72. ui.addTextArea(6,"<B><J><p align='center'><V>"..players[name].balas.."</V><N>/</N>"..maxBalas.."</p></J>",name,6,380,100,20,nil,0x6a8495,90,true)
  73. end
  74. end
  75. end
  76.  
  77. function eventPlayerLeft(name)
  78. jogadores=jogadores-1;
  79. end
  80.  
  81. function eventNewPlayer(name)
  82. for i,v in pairs ({"<CE>Bem-vindo %s ao #wars</CE>","<J>Para atirar pressione a tecla E ou Espaço, O ultimo vivo ganha.</J>","<R>É necessário "..maxPMoney.." jogadores para contar moedas e "..maxPStatus.." para estátisticas.</R>","<J>Jogo desenvolvido por: <V>Contistente</V></J>"}) do
  83. tfm.exec.chatMessage(v:format(name),name)
  84. end
  85. if jogadores == 1 then
  86. nextRound()
  87. end
  88. jogadores=jogadores+1;
  89.  
  90. players[name]={
  91. objeto={"Bola de Neve",34,80},
  92. tempo=0,
  93. timestamp=os.time(),
  94. width=0,
  95. moedas=0,
  96. balas=maxBalas,
  97. rounds=0,
  98. kills=0,
  99. message=false,
  100. wins=0,
  101. inventory={}
  102. }
  103.  
  104. object = true
  105. for i,v in pairs(data) do
  106. if v[1] == name then
  107. players[name] = v[2]
  108. object = false
  109. end
  110. end
  111. if object then
  112. table.insert(players[name].inventory,{"Bola de Neve",34,80})
  113. end
  114. table.insert(data,{name, players[name]})
  115. tfm.exec.setPlayerScore(name,players[name].moedas,false)
  116. ui.addTextArea(0,"",name,6,320,100,80,nil,0x6a8495,80,true)
  117. ui.addTextArea(1,"<J><B><p align='center'>"..players[name].moedas.."</p></J>",name,6,350,100,20,nil,0x6a8495,90,true)
  118. ui.addTextArea(2,"<J><B><p align='center'>"..players[name].objeto[1].."</p></J>",name,6,320,100,20,nil,0x6a8495,90,true)
  119. ui.addTextArea(3,"<J><B><p align='center'><a href='event:menu'>Menu</a></p></J>",name,6,28,94,20,nil,0x6a8495,80,true)
  120. for i,v in pairs(keys) do
  121. tfm.exec.bindKeyboard(name,v,true)
  122. end
  123. end
  124.  
  125. for all in pairs(tfm.get.room.playerList) do
  126. eventNewPlayer(all)
  127. end
  128.  
  129. function eventLoop(time,remaining)
  130. tempo = time
  131. if remaining < 1000 or vivos == 0 then
  132. nextRound()
  133. if vivos == 0 then
  134. tfm.exec.chatMessage("<N>[<CE>Ξ</CE>]</N> <J>Nenhum ratinho venceu, todos morreram.</J>")
  135. else
  136. tfm.exec.chatMessage("<N>[<CE>Ξ</CE>]</N> <J>Nenhum ratinho venceu, o tempo acabou.</J>")
  137. end
  138. end
  139. for i,pi in pairs(tfm.get.room.playerList) do
  140. if vivos == 1 and jogadores >= 2 then
  141. tfm.exec.giveCheese(i)
  142. tfm.exec.playerVictory(i)
  143. end
  144. if players[i].balas == 0 then
  145. if not players[i].message then
  146. tfm.exec.chatMessage("<N>[<CE>Ξ</CE>]</N> <J>As munições de "..i.." acabaram.</J>")
  147. players[i].message = true
  148. end
  149. eventKeyboard(i,69,nil,pi.x,pi.y)
  150. players[i].width = players[i].width+10;
  151. ui.addTextArea(7,"",i,600,380,180,10,0x363636,0x6a8495,70,true)
  152. ui.addTextArea(8,"",i,600,380,players[i].width,10,0x1C1C1C,0x6a8495,70,true)
  153. else
  154. ui.removeTextArea(8,i)
  155. ui.removeTextArea(7,i)
  156. players[i].width = 0
  157. end
  158. end
  159. end
  160.  
  161. function eventPlayerWon(name)
  162. nextRound()
  163. if jogadores >= maxPMoney then
  164. players[name].moedas = players[name].moedas+math.random(10,40);
  165. tfm.exec.setPlayerScore(name,players[name].moedas,false)
  166. ui.addTextArea(1,"<J><B><p align='center'>"..players[name].moedas.."</p></J>",name,6,350,100,20,nil,0x6a8495,90,true)
  167. end
  168.  
  169. if jogadores >= maxPStatus then
  170. players[name].wins = players[name].wins+1;
  171. end
  172.  
  173. tfm.exec.chatMessage("<N>[<CE>Ξ</CE>]</N> <V>"..name.."</V><BL> é o vencedor.</BL>")
  174. end
  175.  
  176. function eventPlayerDied(name)
  177. vivos=vivos-1;
  178. tfm.exec.chatMessage("<N>[<CE>Ξ</CE>]</N> <V>"..name.."</V><BL> morreu.</BL>")
  179. if jogadores >= maxPStatus then
  180. players[name].kills = players[name].kills+1;
  181. end
  182. end
  183.  
  184. function eventKeyboard(name,key,down,x,y)
  185. if (key==69 or key==32) and not tfm.get.room.playerList[name].isDead and tempo >= 6000 and players[name].balas > 0 then
  186. if players[name].timestamp < os.time()-300 then
  187. local id
  188. if tfm.get.room.playerList[name].isFacingRight then
  189. id=tfm.exec.addShamanObject(players[name].objeto[2],x+15,y-10,0,players[name].objeto[3],0)
  190. id=tfm.exec.addShamanObject(players[name].objeto[2],x+15,y-10,0,players[name].objeto[3],0)
  191. else
  192. id=tfm.exec.addShamanObject(players[name].objeto[2],x-15,y-10,0,-players[name].objeto[3],0)
  193. id=tfm.exec.addShamanObject(players[name].objeto[2],x-15,y-10,0,-players[name].objeto[3],0)
  194. end
  195. players[name].balas = players[name].balas-1;
  196. if players[name].balas < 10 then
  197. ui.addTextArea(6,"<B><J><p align='center'><V>0"..players[name].balas.."</V><N>/</N>"..maxBalas.."</p></J>",name,6,380,100,20,nil,0x6a8495,90,true)
  198. else
  199. ui.addTextArea(6,"<B><J><p align='center'><V>"..players[name].balas.."</V><N>/</N>"..maxBalas.."</p></J>",name,6,380,100,20,nil,0x6a8495,90,true)
  200. end
  201. players[name].timestamp=os.time()
  202. end
  203. end
  204. if (key==69) and players[name].balas == 0 then
  205. if players[name].timestamp < os.time()-9000 then
  206. players[name].balas = maxBalas
  207. players[name].timestamp=os.time()
  208. tfm.exec.chatMessage("<N>[<CE>Ξ</CE>]</N> <J>As munições de "..name.." foram recarregadas.</J>")
  209. players[name].message = false
  210. if players[name].balas < 10 then
  211. ui.addTextArea(6,"<B><J><p align='center'><V>0"..players[name].balas.."</V><N>/</N>"..maxBalas.."</p></J>",name,6,380,100,20,nil,0x6a8495,90,true)
  212. else
  213. ui.addTextArea(6,"<B><J><p align='center'><V>"..players[name].balas.."</V><N>/</N>"..maxBalas.."</p></J>",name,6,380,100,20,nil,0x6a8495,90,true)
  214. end
  215. players[name].timestamp=os.time()
  216. end
  217. end
  218. end
  219.  
  220. function eventTextAreaCallback(id, player, link)
  221. if link == "loja" then
  222. y = 15
  223. id = 400
  224. table.insert(ids,id)
  225. local title = "<p align='center'><font size='18'><J>Loja</J></font><br>"
  226. ui.addTextArea(9,title,player,150,30,500,350,nil,0x6a8495,70,true)
  227. ui.addTextArea(10,"<a href='event:fechar-loja'><p align='center'><font color='#ff0000'><B>Fechar</B></font></p></a>",player,300,350,300,20,nil,0x6a8495,70,true)
  228. str = "<N><J>Nome</J> | <V>Preço</V> | <ROSE>Botão</ROSE></N><br>"
  229. ui.addTextArea(id,str,player,200,y+45,400,20,nil,0x6a8495,70,true)
  230. for i,v in pairs(shop) do
  231. y=y+30
  232. id=id+1;
  233. table.insert(ids,id)
  234. for i,v2 in pairs(players[player].inventory) do
  235. if v2[1] == v[1] then
  236. str = "<N><J>"..v[1].."</J> | <V>"..v[2].."</V> | <CE>COMPRADO</CE></N><br>"
  237. ui.addTextArea(id,str,player,200,y+45,400,20,nil,0x6a8495,70,true)
  238. else
  239. str = "<N><J>"..v[1].."</J> | <V>"..v[2].."</V> | <ROSE><a href='event:buy-"..v[1].."'>COMPRAR</a></ROSE></N><br>"
  240. ui.addTextArea(id,str,player,200,y+45,400,20,nil,0x6a8495,70,true)
  241. end
  242. end
  243. end
  244. ui.addTextArea(10,"<B><p align='center'><font color='#ff0000'><a href='event:fechar-loja'>Fechar</a></font></p>",player,150,360,500,20,nil,0x6a8495,70,true)
  245. elseif link == "fechar-loja" then
  246. ui.removeTextArea(9,player)
  247. ui.removeTextArea(10,player)
  248. ui.removeTextArea(11,player)
  249. ui.removeTextArea(12,player)
  250. for index,v in pairs(ids) do
  251. ui.removeTextArea(v,player)
  252. end
  253. elseif link == "inventory" then
  254. texto = '<B><p align="center"><font size="18"><J>Inventário</J></font><br>[<V>Nome</V>][<ROSE>Botão</ROSE>]<br>'
  255. for i,v in pairs(players[player].inventory) do
  256. if v[2] == players[player].objeto[2] then
  257. texto = texto..'<br>[<V>'..v[1]..'</V>][<J>Equipado</J>]'
  258. else
  259. texto = texto..'<br>[<V>'..v[1]..'</V>][<ROSE><a href="event:equip-'..v[1]..'">Equipar</a></ROSE>]'
  260. end
  261. end
  262. ui.addTextArea(9,texto,player,300,50,300,300,nil,0x6a8495,70,true)
  263. ui.addTextArea(10,"<a href='event:fechar-loja'><p align='center'><font color='#ff0000'><B>Fechar</B></font></p></a>",player,300,350,300,20,nil,0x6a8495,70,true)
  264. elseif link == "ranking" then
  265. eventRanking(player)
  266. elseif link == "menu" then
  267. ui.addTextArea(18,"",player,6,28,94,200,nil,0x6a8495,80,true)
  268. ui.addTextArea(3,"<V><B><p align='center'><a href='event:menu-close'>Menu</a></p></V>",player,6,28,94,20,nil,0x6a8495,80,true)
  269. ui.addTextArea(20,"<J><B><p align='center'><a href='event:loja'>Loja</a></p></J>",player,6,60,94,20,nil,0x6a8495,80,true)
  270. ui.addTextArea(21,"<J><B><p align='center'><a href='event:inventory'>Inventário</a></p></J>",player,6,90,94,20,nil,0x6a8495,80,true)
  271. ui.addTextArea(22,"<J><B><p align='center'><a href='event:ranking'>Ranking</a></p></J>",player,6,120,94,20,nil,0x6a8495,80,true)
  272. ui.addTextArea(49,"<J><B><p align='center'><a href='event:perfil'>Perfil</a></p></J>",player,6,150,94,20,nil,0x6a8495,80,true)
  273. elseif link == "menu-close" then
  274. ui.removeTextArea(18,player)
  275. ui.removeTextArea(20,player)
  276. ui.removeTextArea(21,player)
  277. ui.removeTextArea(22,player)
  278. ui.removeTextArea(49,player)
  279. ui.addTextArea(3,"<J><B><p align='center'><a href='event:menu'>Menu</a></p></J>",player,6,28,94,20,nil,0x6a8495,80,true)
  280. elseif link == "ranking-close" then
  281. ui.removeTextArea(44,player)
  282. ui.removeTextArea(45,player)
  283. for index,v in pairs(ids) do
  284. ui.removeTextArea(v,player)
  285. end
  286. id = 50
  287. elseif link == "perfilClose" then
  288. ui.removeTextArea(35,player)
  289. ui.removeTextArea(36,player)
  290. elseif link == "perfil" then
  291. eventChatCommand(player, "p")
  292. end
  293.  
  294. for i,v in pairs(shop) do
  295. if link == "buy-"..v[1] then
  296. for index,v in pairs(ids) do
  297. ui.removeTextArea(v,player)
  298. end
  299. if players[player].moedas >= v[2] then
  300. ui.addTextArea(9,"<J><B><p align='center'>Você comprou um(a) "..v[1].." com sucesso por <ROSE>-"..v[2].."</ROSE> moedas</p></B></J>",player,300,50,300,300,nil,0x6a8495,70,true)
  301. ui.addTextArea(10,"<a href='event:loja'><p align='center'><font color='#ffcc00'><B>Voltar</B></font></p></a>",player,300,350,300,20,nil,0x6a8495,70,true)
  302. players[player].moedas = players[player].moedas-v[2]
  303. table.insert(players[player].inventory, {v[1],v[3],v[4]})
  304. tfm.exec.setPlayerScore(player,players[player].moedas,false)
  305. ui.addTextArea(1,"<J><B><p align='center'>"..players[player].moedas.."</p></J>",player,6,350,100,20,nil,0x6a8495,90,true)
  306. else
  307. ui.addTextArea(9,"<J><B><p align='center'>Você não tem moedas suficientes.</p></B></J>",player,300,50,300,300,nil,0x6a8495,70,true)
  308. ui.addTextArea(10,"<a href='event:loja'><p align='center'><font color='#ffcc00'><B>Voltar</B></font></p></a>",player,300,350,300,20,nil,0x6a8495,70,true)
  309. end
  310. end
  311. end
  312.  
  313. for i,v in pairs(players[player].inventory) do
  314. if link == "equip-"..v[1] then
  315. players[player].objeto = {v[1],v[2],v[3]}
  316. ui.addTextArea(9,"<J><B><p align='center'>Você equipou a(o) "..v[1].." para atirar.</p></B></J>",player,300,50,300,300,nil,0x6a8495,70,true)
  317. ui.addTextArea(10,"<a href='event:inventory'><p align='center'><font color='#ffcc00'><B>Voltar</B></font></p></a>",player,300,350,300,20,nil,0x6a8495,70,true)
  318. ui.addTextArea(2,"<J><B><p align='center'>"..players[player].objeto[1].."</p></J>",player,6,320,100,20,nil,0x6a8495,90,true)
  319. end
  320. end
  321. end
  322.  
  323. function eventRanking(name)
  324. local sc = {}
  325. for name, player in pairs(tfm.get.room.playerList) do
  326. sc[#sc+1] = {n=name,s=player.score,m=players[name].moedas,w=players[name].wins,k=players[name].kills}
  327. end
  328. table.sort(sc,function(a,b) return a.w>b.w end)
  329. y = 15
  330. id = 50
  331. local str = ""
  332. local title = "<p align='center'><font size='18'><J>Ranking</J></font><br>"
  333. ui.addTextArea(44,title,name,150,30,500,350,nil,0x6a8495,70,true)
  334. for k,v in pairs(sc) do
  335. if k < 11 then
  336. id = id+1;
  337. table.insert(ids, id)
  338. y = y+30
  339. str = "<N><J>"..k.."</J>. | <V>"..v.n.."</V> | Rodadas: <V>"..players[v.n].rounds.."</V> | Moedas: <V>"..v.m.."</V> | Vitórias: <V>"..v.w.."</V> | Mortes: <V>"..v.k.."</V></N><br>"
  340. if id < 60 then
  341. ui.addTextArea(id,str,name,170,y+40,460,20,nil,0x6a8495,70,true)
  342. end
  343. end
  344. end
  345. ui.addTextArea(45,"<B><p align='center'><font color='#ff0000'><a href='event:ranking-close'>Fechar</a></font></p>",name,150,360,500,20,nil,0x6a8495,70,true)
  346. return str
  347. end
  348.  
  349. tfm.exec.setRoomMaxPlayers(maxPRoom)
  350. nextRound()
Add Comment
Please, Sign In to add comment