Advertisement
alditojeje

Lua parkour v2

Dec 2nd, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 KB | None | 0 0
  1. -- TODO:
  2. -- checkpoints, score arriba grafico, arriba poner puntos, establecer score con los puntos, arreglar autoJoin
  3.  
  4. adm="Blood#3565"
  5. tfm.exec.disableAfkDeath(true)
  6. tfm.exec.disableAutoShaman()
  7. tfm.exec.disableAutoTimeLeft()
  8. tfm.exec.disablePhysicalConsumables()
  9. tfm.exec.disableAutoScore()
  10. tfm.exec.disableMinimalistMode()
  11. tfm.exec.newGame(7657121)
  12. tfm.exec.disableAutoNewGame(false)
  13. system.disableChatCommandDisplay("text", true)
  14.  
  15. autoJoin = "on"
  16. enJuego = false
  17. contTeam1 = 0
  18. contTeam2 = 0
  19. verTexto = true
  20. tiempoJugado = 0
  21. puntosParaGanar = 5
  22. scoreTeams = 3
  23. args = {}
  24. jugador = false
  25. active = true
  26. local teams = {Team1 = {}, Team2 = {}}
  27. local puntos = {team1Puntos = 0, team2Puntos = 0}
  28. local maps = {7623375, 7618265, 7598750, 7572953, 7569215, 7565716, 7569454, 7571727, 7568533, 7566172, 7570693, 7197833, 7573427, 7142793, 7565563, 7571737, 7568384, 7566459, 7571491, 7568359, 7568830, 7171137, 7356802, 7506432, 4612890, 7172091, 7565705, 7196916, 7367964}
  29.  
  30. function eventLoop (elapsedTime, remainingTime )
  31. tiempoJugado = elapsedTime
  32.  
  33. if remainingTime <= 2823 then
  34. newMap()
  35. end
  36. end
  37.  
  38. function eventPlayerLeft (playerName)
  39. if enJuego == false then
  40. for i=1, #teams.Team1 do
  41. if playerName == teams.Team1[i] then
  42. teams.Team1[i] = "[Player Left]"
  43. textoArea()
  44. end
  45. end
  46. for i=1, #teams.Team2 do
  47. if playerName == teams.Team2[i] then
  48. teams.Team2[i] = "[Player Left]"
  49. textoArea()
  50. end
  51. end
  52. end
  53. end
  54.  
  55. function eventNewPlayer (playerName)
  56. if autoJoin == "on" then
  57. if enJuego then
  58. if #teams.Team1 > #teams.Team2 then
  59. table.insert(teams.Team1,playerName)
  60. else
  61. table.insert(teams.Team2,playerName)
  62. end
  63. tfm.exec.respawnPlayer(playerName)
  64. establecerColor()
  65. end
  66. end
  67. if enJuego == false then
  68. textoArea()
  69. end
  70. end
  71. function newMap()
  72. active = false
  73. enJuego = true
  74. contTeam1 = 0
  75. contTeam2 = 0
  76. local mapcode = maps[math.random(#maps)]
  77. tfm.exec.newGame(mapcode)
  78. for name, p in pairs(tfm.get.room.playerList) do
  79. if not matarNoJugadores(name) then
  80. tfm.exec.killPlayer(name)
  81. end
  82. end
  83. establecerColor()
  84. establecerTiempo()
  85. end
  86.  
  87. function eventChatCommand(playerName, command)
  88.  
  89. if playerName == adm then
  90. args = string.split(command, " ")
  91.  
  92. if args[1] == "skip" or args[1] == "saltar" and enJuego then
  93. newMap()
  94. end
  95. if args[1] == "text" and enJuego == false then
  96. print(enJuego)
  97. print(verTexto)
  98. if verTexto then
  99. verTexto = false
  100. else
  101. verTexto = true
  102. end
  103. end
  104. if args[1] == "d" then
  105. if tonumber(args[2]) ~= nil then
  106. puntosParaGanar = tonumber(args[2])
  107. end
  108. end
  109. if args[1] == "pointsteam" or args[1] == "pointsteams" or args[1] == "pointeams" or args[1] == "pt" then
  110. if tonumber(args[2]) ~= nil then
  111. scoreTeams = tonumber(args[2])
  112. end
  113. end
  114. if args[1] == "add" then -- si el comando es add
  115. if args[2] == "team1" then -- y sigue con team1
  116. for i=3, #args do -- recorre toda la tabla args
  117. for j=1, #teams.Team2 do -- recorre toda la tabla teams2
  118. if args[i] == teams.Team2[j] then -- si un elemento de la tabla args conicide con un elento de la tabla teams2
  119. teams.Team2[j] = "[Removed]" -- reemplaza su nombre por removed
  120. end
  121. end
  122. end
  123. end
  124. teams.Team1 = {} -- establece vacio la tabla teams1
  125. for i=3, #args do
  126. table.insert (teams.Team1, args[i]) -- le aƱade a team1 los argumentos escritos.
  127. establecerPuntos()
  128. end
  129. if args[2] == "team2" then
  130. for i=3, #args do -- recorre toda la tabla args
  131. for j=1, #teams.Team1 do -- recorre toda la tabla teams1
  132. if args[i] == teams.Team1[j] then -- si un elemento de la tabla args conicide con un elento de la tabla teams1
  133. teams.Team1[j] = "[Removed]" -- reemplaza su nombre por removed
  134. end
  135. end
  136. end
  137. teams.Team2 = {}
  138. for i=3, #args do
  139. table.insert (teams.Team2, args[i])
  140. establecerPuntos()
  141. end
  142. end
  143. end
  144. if args[1] == "autoj" or args[1] == "aj" then
  145. autoj()
  146. end
  147. end
  148. textoArea()
  149. end
  150.  
  151. function establecerTiempo()
  152. tfm.exec.setGameTime(1080)
  153. end
  154.  
  155. function establecerTiempoGanar()
  156. tfm.exec.setGameTime(10)
  157. end
  158.  
  159. function eventTextAreaCallback(id, player, callback)
  160. if callback == 'iniciarJuego' and tiempoJugado >= 3383 then
  161. tfm.exec.disableAutoNewGame(true)
  162. verTexto = false
  163. newMap()
  164. end
  165. if callback == 'llenarEquipos' then
  166. establecerPuntos()
  167. establecerEquipos()
  168. end
  169. if callback == 'vaciar' then
  170. teams.Team1 = {}
  171. teams.Team2 = {}
  172. end
  173. if callback == 'autoj' then
  174. autoj()
  175. end
  176. textoArea()
  177. end
  178.  
  179. function autoj()
  180. if autoJoin == "on" then
  181. autoJoin = "off"
  182. else
  183. autoJoin = "on"
  184. end
  185. end
  186. function eventPlayerDied (playerName)
  187. if enJuego == false or matarNoJugadores(playerName) == true then
  188. tfm.exec.respawnPlayer(playerName)
  189. establecerColor()
  190. end
  191. end
  192.  
  193. function matarNoJugadores(name)
  194. player = name
  195. for i = 1, #teams.Team1 do
  196. if teams.Team1[i] == player then
  197. return true
  198. end
  199. end
  200. for i = 1, #teams.Team2 do
  201. if teams.Team2[i] == player then
  202. return true
  203. end
  204. end
  205. return false
  206. end
  207.  
  208. function establecerPuntos()
  209. for name in pairs(tfm.get.room.playerList) do
  210. tfm.exec.setPlayerScore(name, 0)
  211. end
  212. end
  213.  
  214. function establecerEquipos()
  215. teams.Team1 = {}
  216. teams.Team2 = {}
  217. local equipo = 1
  218. for k in pairs(tfm.get.room.playerList) do
  219. if equipo == 1 then
  220. table.insert(teams.Team1, k)
  221. equipo = 2
  222. elseif equipo == 2 then
  223. table.insert(teams.Team2, k)
  224. equipo = 1
  225. end
  226. end
  227. end
  228.  
  229. function establecerColor()
  230. for i, v in pairs(teams.Team1) do
  231. tfm.exec.setNameColor(v, 0xE2FF14)
  232. end
  233. for i, v in pairs(teams.Team2) do
  234. tfm.exec.setNameColor(v, 0x2F7FCC)
  235. end
  236. end
  237.  
  238. function eventPlayerWon (playerName, timeElapsed, timeElapsedSinceRespawn)
  239.  
  240. active = true
  241. tfm.exec.respawnPlayer(playerName)
  242. establecerColor()
  243. system.bindMouse(playerName, active)
  244. system.bindKeyboard(playerName, 32, active)
  245. for i, v in pairs(teams.Team1) do
  246. if playerName == v then
  247. contTeam1 = contTeam1 +1
  248. tfm.exec.setPlayerScore(playerName, 1)
  249. end
  250. end
  251.  
  252. for i,v in pairs (teams.Team2) do
  253. if playerName == v then
  254. contTeam2 = contTeam2 +1
  255. end
  256. end
  257. equipoPunto()
  258. end
  259.  
  260. function eventKeyboard(name, key, down, px, py)
  261. _space = 32
  262. if active then
  263. if key == _space then
  264. tfm.exec.movePlayer(name, 0, 0, true, 0, -40, true)
  265. end
  266. end
  267. end
  268.  
  269. function eventMouse(name, mx, my)
  270. if active then
  271. tfm.exec.movePlayer(name, mx, my)
  272. end
  273. end
  274.  
  275. function equipoPunto()
  276. if enJuego then
  277. if contTeam1 == scoreTeams then
  278. puntos.team1Puntos = puntos.team1Puntos + 1
  279. contTeam1 = 0
  280. contTeam2 = 0
  281. enJuego = false
  282. establecerTiempoGanar()
  283. end
  284. if contTeam2 == scoreTeams then
  285. puntos.team2Puntos = puntos.team2Puntos + 1
  286. contTeam1 = 0
  287. contTeam2 = 0
  288. enJuego = false
  289. establecerTiempoGanar()
  290. end
  291. end
  292. if puntos.team1Puntos >= puntosParaGanar then
  293. team1Gano = true
  294. ganador()
  295. end
  296. if puntos.team2Puntos >= puntosParaGanar then
  297. ganador()
  298. end
  299. end
  300.  
  301. function ganador()
  302. tfm.exec.newGame(7589151)
  303. establecerColor()
  304. if team1Gano then
  305. print ("equp1")
  306. else
  307. print ("equp2")
  308. end
  309. end
  310.  
  311.  
  312.  
  313. -- GRAFICO --
  314.  
  315. function textoArea()
  316. if verTexto then
  317. ui.addTextArea(0, "", nil, 200, 62, 400, 12, 0x324650, 0x121212, 0.7, true)
  318. ui.addTextArea(1, "", nil, 200, 44, 400, 12, 0x324650, 0x121212, 1, true)
  319. ui.addTextArea(2, "<p align='center'><font color='#00C17C'><b>" ..(adm), nil, 320, 36, 150, 20, 0x324650, 0x121212, 1, true)
  320. ui.addTextArea(3, "<p align='center'><font color='#E2FF14'>" .. (table.concat(teams.Team1,"\n") or ""), nil, 15, 72, 180, 266, 0x324650, 0x121212, 1, true)
  321. ui.addTextArea(4, "<p align='center'><font color='#2F7FCC'>" .. (table.concat(teams.Team2,"\n") or ""), nil, 605, 72, 180, 266, 0x324650, 0x121212, 1, true)
  322. ui.addTextArea(5, "<p align='center'><font color='#E2FF14'><b>Team 1", nil, 10, 44, 190, 20, 0x324650, 0x121212, 1, true)
  323. ui.addTextArea(6, "<p align='center'><font color='#2F7FCC'><b>Team 2", nil, 600, 44, 190, 20, 0x324650, 0x121212, 1, true)
  324. ui.addTextArea(7, "<p align='center'><V><a href='event:iniciarJuego'><font color='#F93018'><b>Iniciar", adm, 375, 60, 0, 0, 0x324650, 0x121212, 1, true)
  325. ui.addTextArea(8, "<p align='center'>ScoreT: <font color='#00C17C'><b>" ..(scoreTeams), nil, 225, 36, 70, 20, 0x324650, 0x121212, 1, true)
  326. ui.addTextArea(9, "<p align='center'><V><a href='event:llenarEquipos'><font color='#F93018'><b>Llenar", adm, 240, 60, 0, 0, 0x324650, 0x121212, 1, true)
  327. ui.addTextArea(10, "<p align='center'>Score: <font color='#00C17C'><b>" ..(puntosParaGanar), nil, 500, 36, 70, 20, 0x324650, 0x121212, 1, true)
  328. ui.addTextArea(11, "<p align='center'><V><a href='event:vaciar'><font color='#F93018'><b>Vaciar", adm, 515, 60, 0, 0, 0x324650, 0x121212, 1, true)
  329. ui.addTextArea(12, "<p align='center'>Auto Join: <V><a href='event:autoj'><font color='#F93018'><b>" .. (autoJoin), adm, 660, 342, 0, 0, 0x324650, 0x121212, 1, true)
  330. establecerColor()
  331. else
  332. for i=0, 17,1 do
  333. ui.removeTextArea(i)
  334. end
  335. end
  336. end
  337.  
  338. --[[function string.split(s, pattern, n)
  339. local st = {}
  340. for sb in string.gmatch(s, "[^"..pattern.."]+") do
  341. if not n or n > -1 then
  342. table.insert(st,sb)
  343. else
  344. st[#st] = st[#st]..pattern..sb
  345. end
  346. n = n and n-1 or false
  347. end
  348. return st
  349. end --]]
  350.  
  351. establecerTiempo()
  352. textoArea()
  353. establecerPuntos()
  354.  
  355. --[[function matarNoJugadores(name)
  356. local player = name
  357. for i,v in pairs(teams.Team1) do
  358. if v == player then
  359. return true
  360. end
  361. end
  362. for i,n in pairs(teams.Team2) do
  363. if n == player then
  364. return true
  365. end
  366. end
  367. return false
  368. end ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement