Zerveorus

SnowBallWar

Feb 17th, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.43 KB | None | 0 0
  1. admins={Miiiclaroo=true,Newwthejbk=true}
  2. count = 0
  3. locations={
  4.     {[1]={579,180},
  5.     [2]={157,180}},
  6.  
  7.     {[1]={350,210},
  8.     [2]={640,200},
  9.     [3]={100,200}},
  10.  
  11.     {[1]={400,95},
  12.     [2]={393,216},
  13.     [3]={398,338}},
  14.  
  15.     {[1]={400,330},
  16.     [2]={400,170}},
  17.  
  18.     {[1]={688,315},
  19.     [2]={97,318}},
  20.  
  21.     {[1]={389,169},
  22.     [2]={387,317},
  23.     [3]={591,349},
  24.     [4]={190,347}}
  25. }
  26. local maps = {
  27.  
  28. '<C><P  /><Z><S><S P="0,0,0.3,0.2,0,0,0,0" L="32" H="31" Y="213" T="0" X="371" /><S P="0,0,0,0.2,0,0,0,0" L="33" H="29" Y="113" T="1" X="577" /><S L="33" X="580" H="29" Y="342" T="1" P="0,0,0,0.2,0,0,0,0" /><S L="33" X="373" H="29" Y="316" T="1" P="0,0,0,0.2,0,0,0,0" /><S L="33" X="168" H="29" Y="337" T="1" P="0,0,0,0.2,0,0,0,0" /><S L="33" X="370" H="29" Y="115" T="1" P="0,0,0,0.2,0,0,0,0" /><S L="33" X="157" H="29" Y="115" T="1" P="0,0,0,0.2,0,0,0,0" /><S L="32" X="268" H="31" Y="270" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="32" X="478" H="31" Y="273" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="32" X="374" H="31" Y="404" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="32" X="580" H="31" Y="217" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="32" X="161" H="31" Y="210" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="32" X="266" H="31" Y="154" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="32" X="475" H="31" Y="150" T="0" P="0,0,0.3,0.2,0,0,0,0" /></S><D><DS Y="186" X="370" /></D><O /></Z></C>',
  29. --arriba mapas de zax
  30. '<C><P /><Z><S><S L="45" H="34" X="356" Y="110" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="45" X="355" H="34" Y="230" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="45" X="355" H="34" Y="350" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="45" H="34" X="640" Y="230" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="45" H="34" X="640" Y="110" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="45" X="640" H="34" Y="350" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="45" X="100" H="34" Y="230" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="45" X="100" H="34" Y="110" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="45" X="100" H="34" Y="350" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="26" X="225" H="23" Y="170" T="1" P="0,0,0,0.2,0,0,0,0" /><S L="26" H="23" X="497" Y="170" T="1" P="0,0,0,0.2,0,0,0,0" /><S L="26" H="23" X="225" Y="300" T="1" P="0,0,0,0.2,0,0,0,0" /><S L="26" X="497" H="23" Y="300" T="1" P="0,0,0,0.2,0,0,0,0" /></S><D><DS Y="76" X="357" /></D><O /></Z></C>',
  31. '<C><P /><Z><S><S L="406" X="400" H="23" Y="120" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="406" H="23" X="400" Y="240" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="406" H="23" X="399" Y="360" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="95" X="663" H="10" Y="320" T="1" P="0,0,0,0.2,-45,0,0,0" /><S L="95" H="10" X="135" Y="320" T="1" P="0,0,0,0.2,45,0,0,0" /><S L="95" X="118" H="10" Y="180" T="1" P="0,0,0,0.2,45,0,0,0" /><S L="95" H="10" X="680" Y="180" T="1" P="0,0,0,0.2,-45,0,0,0" /></S><D><DS Y="92" X="401" /></D><O /></Z></C>',
  32. '<C><P /><Z><S><S L="330" H="20" X="400" Y="200" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S L="330" X="400" H="20" Y="350" T="0" P="0,0,0.3,0.2,0,0,0,0" /></S><D><DS Y="176" X="399" /></D><O /></Z></C>',
  33. '7062433'
  34. }
  35.  
  36.  paginas={
  37. "<b>Teclas</b><br>- espacio : disparas una bolita de nieve suculenta<br>- M : congelas a un jugador cercano",
  38. "<b>comandos</b><br>- !p [nombre del jugador] para ver su perfil",
  39. "<b>info para ocupar espacio</b><br><b>creador del juego:</b> <j>Miiiclaroo</j>"
  40. }
  41.  
  42. k={
  43. type = 8,
  44.         width = 120,
  45.         height = 120,
  46.         friction = 1,
  47.         restitution = 0,
  48.         miceCollision =false,
  49.         groundCollision = false
  50.  
  51. }
  52.  
  53. local currentMap
  54. local playersAlive
  55.  
  56. dataTitlesW={
  57.                 {"pro",100},
  58.                 {"invencible",1000},
  59.                 {"frozen Balls",500}
  60.    
  61. }
  62.  
  63. dataTitlesM={
  64.                 {"noob",20},
  65.                 {"frozen mouse",10}
  66. }
  67.  
  68.  
  69. mice={}
  70. dataPlayer= {
  71.                
  72. }
  73. gunActive=false
  74. gun=0
  75. local gunx,guny = 400,200
  76. contador=0
  77. FC=false
  78. equipo={azul={},rojo={}}
  79. lastId=0
  80. isBanned={}
  81. gameContador=0
  82. gameFinished = false
  83. -------------------
  84. despawnTime = 2500
  85. fireDelay = 750
  86. offsetX = 0
  87. offsetY = 0
  88. -----------------------
  89. keys = {0,2,32,112,77}
  90. _left = 0
  91. _right = 2
  92.  
  93. facingLeft = {}
  94. toDespawn = {}
  95. fireTS = {}
  96. ------------
  97. function main()
  98.  
  99.     tfm.exec.disableAutoShaman(true)
  100.     tfm.exec.disableAutoShaman(true)
  101.     tfm.exec.disableAutoNewGame(true)
  102.     tfm.exec.disableAfkDeath(true)
  103.     tfm.exec.disableAutoTimeLeft (true)
  104.     tfm.exec.disableAutoScore (true)
  105.     startGame()
  106.     for n in pairs(tfm.get.room.playerList) do
  107.         eventNewPlayer(n)
  108.     end
  109. end
  110. function eventNewPlayer(name)
  111. lastId=lastId+1
  112.     if not mice[name] then
  113.        mice[name]={[1]=0,[2]=0,[3]=false,id=lastId,title="rata congelada",frozed=false,x=0,y=0,frozedTime=0,frozen=3,contador=0,Icontador=0,on=false,pa=1}
  114.     end
  115. if not dataPlayer[name] then
  116.     dataPlayer[name]={}
  117. elseif dataPlayer[name] then
  118.     mice[name][1]=dataPlayer[name][1]
  119.     mice[name][2]=dataPlayer[name][2]
  120.     mice[name].title=dataPlayer[name].title
  121. end
  122. if isBanned[name] then
  123.     ui.addTextArea(mice[name].id+200,"",name,-50,-50,900,450)
  124. ui.addTextArea(mice[name].id-200,"<p align = 'center'>has sido baneado",name,-50,-50,900,450)
  125.  end
  126.  
  127.     facingLeft[name] = false
  128.     fireTS[name] = 0
  129.    
  130.     for _,k in pairs(keys) do
  131.         system.bindKeyboard(name, k, true)
  132.     end
  133. ui.addTextArea(mice[name].id+1000,"<b><font size='20'><font color='#FFFFFF'>Hola "..name.." bienvenido a </font><font color='#FFDD00'>SnowBall War</font>",name,160,200,0,0,0)
  134. mice[name].on=true
  135. ui.addTextArea(mice[name].id+2000,"<b><font size='20'><font color='#FFFFFF'>escribe </font><font color='#FF0500'>!help</font><font color='#FFFFFF'> para más info.",name,260,240,0,0,0)
  136.  
  137. end
  138.  
  139. function startGame()
  140.   local newMap
  141.   repeat
  142.     newMap = math.random(#maps)
  143.   until newMap ~= currentMap
  144.   currentMap = newMap
  145.   tfm.exec.newGame(maps[newMap])
  146.  for n in pairs (tfm.get.room.playerList)do
  147.  if maps[newMap] == maps[1] then
  148.     tfm.exec.movePlayer(n,locations[1][math.random(#locations[1])][1],locations[1][math.random(#locations[1])][2])
  149. elseif maps[newMap] == maps[2] then
  150.     tfm.exec.movePlayer(n,locations[2][math.random(#locations[2])][1],locations[2][math.random(#locations[2])][2])
  151. elseif maps[newMap] == maps[3] then
  152.     tfm.exec.movePlayer(n,locations[3][math.random(#locations[3])][1],locations[3][math.random(#locations[3])][2])
  153. elseif maps[newMap] == maps[4] then
  154.     tfm.exec.movePlayer(n,locations[4][math.random(#locations[4])][1],locations[4][math.random(#locations[4])][2])
  155. elseif maps[newMap] == maps[5] then
  156.     tfm.exec.movePlayer(n,locations[5][math.random(#locations[5])][1],locations[5][math.random(#locations[5])][2])
  157. end
  158. end
  159. end
  160.  
  161. function endGame()
  162. gameFinished = true
  163. tfm.exec.setGameTime(5)
  164. end
  165.  
  166. function eventNewGame()
  167. count = count+1
  168. if count == 5 then
  169. for n in pairs(tfm.get.room.playerList)do
  170. tfm.exec.lowerSyncDelay(n)
  171. end
  172. count = 0
  173. end
  174. for n in pairs (mice) do
  175.     mice[n].frozedTime = 0
  176.     mice[n].frozen = 3
  177.     mice[n].x = 0
  178.     mice[n].y = 0
  179. if isBanned[n] then
  180.     tfm.exec.killPlayer(n)
  181. end
  182. end
  183. gameFinished=false
  184.     tfm.exec.snow(1,70)
  185.   playersAlive = 0
  186.   for _ in pairs(tfm.get.room.playerList) do
  187.     playersAlive = playersAlive + 1
  188.   end
  189. for name in pairs (mice) do
  190.     mice[name][3]=true
  191. end
  192. contador=0
  193. end
  194.  
  195. function eventPlayerRespawn(name)
  196. if mice[name].frozed then
  197.     tfm.exec.movePlayer(name,mice[name].x,mice[name].y,false)
  198.     mice[name][3] = true
  199.     mice[name].frozed = false
  200. elseif not mice[name].frozed then
  201.   playersAlive = playersAlive + 1
  202.   mice[name][3] = true
  203. if isBanned[name]then
  204.             tfm.exec.killPlayer(name)
  205. end
  206. end
  207. end
  208.  
  209. function eventPlayerDied(name)
  210. if mice[name].frozed then
  211.     mice[name][3]=false
  212.  
  213. elseif not mice[name].frozed then
  214.   playersAlive = playersAlive - 1
  215.   checkPlayers()
  216.   mice[name][1]=mice[name][1]+1
  217.     mice[name][3]=false
  218.     checkTitle(name)
  219. end
  220. end
  221. function eventPlayerLeft(name)
  222.     dataPlayer[name][1]=mice[name][1]
  223.     dataPlayer[name][2]=mice[name][2]
  224.     dataPlayer[name].title=mice[name].title
  225. end
  226. function eventPlayerWon(name)
  227.   playersAlive = playersAlive - 1
  228.   checkPlayers()
  229.   mice[name][2]=mice[name][2]+1
  230.     checkTitle(name)
  231. end
  232. function checkPlayers()
  233.   if playersAlive == 0 then
  234.     endGame()
  235.   end
  236. if playersAlive == 1 then
  237.     for name in pairs (mice) do
  238.         if mice[name].frozed then
  239.             tfm.exec.respawnPlayer(name)
  240.             mice[name].frozed=false
  241.         end
  242.         tfm.exec.giveCheese(name)
  243.         endGame()
  244. end
  245. end
  246. end
  247. function eventPlayerGetCheese(name)
  248.     tfm.exec.playerVictory(name)
  249. end
  250.  
  251. function eventLoop(t, tr)
  252.  
  253. for name in pairs (tfm.get.room.playerList) do
  254. if mice[name].frozed then
  255.     mice[name].contador = mice[name].contador + 1
  256. end
  257. if mice[name].contador == 6 then
  258.     tfm.exec.respawnPlayer(name)
  259.     mice[name].contador = 0
  260. end
  261.     if mice[name].on then
  262.         mice[name].Icontador=mice[name].Icontador+1
  263.         if  mice[name].Icontador == 10 then
  264.             ui.removeTextArea(mice[name].id+1000)
  265.             ui.removeTextArea(mice[name].id+2000)
  266.             mice[name].on=false
  267.             mice[name].Icontador=0
  268.         end
  269.     end
  270. end
  271. if gunActive then
  272.     gun=gun+1
  273.     if gun == 10 then
  274.         tfm.exec.removePhysicObject(0)
  275.         gun = 0
  276.         gunActive = false
  277.     end
  278. end
  279. if contador <12 then
  280.     contador = contador+1
  281.     FC=false
  282. end
  283. if contador >= 12 then
  284.     FC=true
  285. end
  286. if not gameFinished and tr <= 0 then
  287. endGame()
  288. elseif gameFinished and tr <= 0 then
  289. startGame()
  290. end
  291.  
  292.   for i,o in ipairs(toDespawn) do
  293.         if os.time() > o[2]+despawnTime then
  294.             tfm.exec.removeObject (o[1])
  295.             table.remove (toDespawn, i)
  296.         end
  297.     end
  298. end
  299.  
  300. function eventKeyboard(name, key, down, px, py)
  301.     if key == _left then
  302.         facingLeft[name] = true
  303.    
  304.     elseif key == _right then
  305.         facingLeft[name] = false
  306.    
  307.     elseif key==32 and os.time() > fireTS[name] + fireDelay  then
  308.     local m = mice[name]
  309.     local dx,a,id
  310.         if px > gunx-60 and px < gunx+60 and py > guny-60 and py < guny+60 and gunActive then
  311.             if facingLeft[name] then
  312.                     dx,dy,a,f = -30,0,-90,5
  313.             else
  314.                     dx,dy,a,f = 30,0,90,-5
  315.             end
  316.            
  317.         else
  318.         if facingLeft[name] then
  319.                 dx,dy,a,f = -30,0,-90,-12
  320.             else
  321.                 dx,dy,a,f = 30,0,90,12
  322.         end
  323.         end
  324.    
  325.         if FC then
  326.             if mice[name][3] then
  327.                 fireTS[name] = os.time()
  328.             id = tfm.exec.addShamanObject(34, px+dx+offsetX, py+offsetY, a,f)
  329.             table.insert(toDespawn, {id, os.time()})
  330.             end
  331.         end
  332. end
  333. if key == 112 and not gunActive and mice[name][3] and FC then
  334.     gunx = px
  335.     guny = py
  336. tfm.exec.addPhysicObject (0,gunx, guny, k )
  337.     gunActive=true
  338. end
  339. if key == 77 then
  340.     if mice[name].frozen > 0 and FC and mice[name][3] and not mice[name].frozed then
  341.         for n,mouse in pairs(tfm.get.room.playerList) do
  342.         local x,y = mouse.x, mouse.y
  343.             if px > x-60 and px < x+60 and py > y-60 and py < y+60 then
  344.                 if name ~= n and not mice[n].frozed and mice[n][3] then
  345.                 mice[name].frozen = mice[name].frozen - 1
  346.                 mice[n].frozed=true
  347.                 tfm.exec.killPlayer(n)
  348.                 mice[n].x=x
  349.                 mice[n].y=y
  350.                 fireTS[n] = os.time()
  351.                 id = tfm.exec.addShamanObject(54,x,y)
  352.                 table.insert(toDespawn, {id, os.time()})
  353.                 for i = -20,20 do
  354.                 tfm.exec.displayParticle(9,x,y-i,0.5,0)
  355.                 tfm.exec.displayParticle(9,x,y-i,-0.5,0)
  356.                 tfm.exec.displayParticle(9,x-i,y,0.5,0.5)
  357.                 tfm.exec.displayParticle(9,x-i,y,0,-0.5)
  358.                 tfm.exec.displayParticle(9,x-i,y-i,0.5,-0.5)
  359.                 tfm.exec.displayParticle(9,x-i,y+i,-0.5,-0.5)
  360.                 tfm.exec.displayParticle(9,x-i,y-i,-0.5,0.5)
  361.                 tfm.exec.displayParticle(9,x-i,y+i,0.5,0.5)
  362.                
  363.         end
  364.             break
  365.             end
  366.   end
  367.  end
  368. end
  369. end
  370. end
  371.  
  372.  
  373.  
  374. function eventChatCommand(name,command)
  375. local a={}
  376.     for i in command:gmatch ('[^%s]+') do
  377.         table.insert(a,i)
  378.     end
  379. if a[1] == "ban" then
  380.     if a[2] then
  381.         if admins[name] then
  382.             tfm.exec.killPlayer(a[2])
  383.             isBanned[a[2]]=true
  384.             ui.addTextArea(mice[a[2]].id+200,"",a[2],-50,-50,900,450)
  385.             ui.addTextArea(mice[a[2]].id-200,"<p align = 'center'>has sido baneado",a[2],300,200)
  386.         end
  387.     end
  388. elseif a[1] == "unban" then
  389.     if isBanned[a[2]] then
  390.         if admins[name] then
  391.             isBanned[a[2]] = false
  392.             ui.removeTextArea(mice[a[2]].id+200)
  393.             ui.removeTextArea(mice[a[2]].id-200)
  394.         end
  395.     end
  396. end
  397.  
  398. if a[1]=="p" then
  399.     if mice[a[2]] then
  400.         ui.addTextArea(mice[name].id-200,"<a href= 'event:close'>X<a/>",name,465,175,0,0,0xFF1000)
  401.         ui.addTextArea(mice[name].id-100,"<j><b><font size= '14'>"..a[2].."</font></b>",name,300,175,160,0,0,1)
  402.         ui.addTextArea(mice[name].id,"<b><j>título: </j></b>"..mice[a[2]].title.."<br><b><j>muertes: </b></j>"..mice[a[2]][1].."<br><b><j>veces ganadas: </b></j>"..mice[a[2]][2].."",name,300,200,160)
  403.     else
  404.         ui.addTextArea(mice[name].id-200,"<a href= 'event:close'>X<a/>",name,465,175,0,0,0xFF1000)
  405.         ui.addTextArea(mice[name].id-100,"<j><b><font size= '14'>"..name.."</font></b>",name,300,175,160,0,0,1)
  406.         ui.addTextArea(mice[name].id,"<b><j>título: </j></b>"..mice[name].title.."<br><b><j>muertes: </b></j>"..mice[name][1].."<br><b><j>veces ganadas: </b></j>"..mice[name][2].."",name,300,200,160)
  407.     end
  408. end
  409. if a[1] == "save" then
  410. if mice[a[2]] then
  411.         print(""..a[2].."={ "..mice[a[2]][1]..","..mice[a[2]][2]..", title="..mice[a[2]].title.."}")
  412. end
  413. end
  414. if command == "exit" and admins[name]then
  415.     system.exit()
  416.  
  417.  
  418. elseif command == "next" and admins[name]then
  419.     endGame()
  420. end
  421.  
  422. if command =="help" then
  423.     openCl(name)
  424. end
  425. end
  426.  
  427.  
  428. function eventTextAreaCallback(id,name,cb)
  429.     if cb == 'close' then
  430.     ui.removeTextArea(mice[name].id)
  431.     ui.removeTextArea(mice[name].id-100)
  432.     ui.removeTextArea(mice[name].id-200)
  433. end
  434. if cb == 'open' then
  435.     openCl(name)
  436. elseif cb == 'closeCl' then
  437.     mice[name].pa = 1
  438.     closeCl(name)
  439. elseif cb == 'next' and mice[name].pa<3 then
  440.     mice[name].pa = mice[name].pa +1
  441.     actualizarCl(name)
  442. elseif cb == 'prev' and mice[name].pa >1 then
  443.     mice[name].pa = mice[name].pa-1
  444.     actualizarCl(name)
  445. end
  446. end
  447.  
  448. function openCl(player)
  449.     ui.addTextArea(mice[player].id+3000,""..paginas[mice[player].pa].."",player,250,76,210,200,0x67534F,0x67534F)
  450.     ui.addTextArea(mice[player].id-3050,"<a href='event:closeCl'>X</a>",player,448,52,0,0,0x67534F,0x67534F)
  451.     ui.addTextArea(mice[player].id+3100,"<a href='event:next'>next</a>",player,411,52,0,0,0x67534F,0x67534F)
  452.     ui.addTextArea(mice[player].id+3050,"<a href = 'event:prev'>prev</a>",player,249,52,0,0,0x67534F,0x67534F)
  453. end
  454.  
  455. function closeCl(player)
  456. ui.removeTextArea(mice[player].id+3000)
  457. ui.removeTextArea(mice[player].id-3050)
  458. ui.removeTextArea(mice[player].id+3050)
  459. ui.removeTextArea(mice[player].id+3100)
  460. end
  461.  
  462. function actualizarCl(player)
  463.     ui.addTextArea(mice[player].id+3000,""..paginas[mice[player].pa].."",player,250,76,210,200,0x67534F,0x67534F)
  464. end
  465.  
  466. function checkTitle(name)
  467. for i = 1,#dataTitlesW do
  468.         if mice[name][2] == dataTitlesW[i][2] then
  469.             mice[name].title = dataTitlesW[i][1]
  470.         end
  471. end
  472. for a= 1,#dataTitlesM do
  473.         if mice[name][1] == dataTitlesM[a][2] then
  474.             mice[name].title = dataTitlesM[a][1]
  475.         end
  476. end
  477. end
  478.    
  479. main()
Advertisement
Add Comment
Please, Sign In to add comment