Advertisement
KananGamer

[TFM-LUA] Survivor

Dec 24th, 2020
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.83 KB | None | 0 0
  1. local tribe_name = tfm.get.room.name:sub(2)
  2. local enable_rotation = false
  3. local admins = {} -- Não é necessário por seu nick caso você que vá carregar o script
  4. local maps = {3107377, 305748, 1539148, 4543602, 390649, 495880, 1463332, 1492805, 292678, 305753, 1545834, 3175437, 2964900, 1812056, 852617, 799141, 1794907, 2939549, 459284, 1519483, 1794873, 811211, 306360, 489829, 479091, 3419948, 290546, 276534, 3220945, 281649, 390657, 311496, 295988, 802958, 2643833}
  5.  
  6. --[[
  7. __-- Lista de Comandos --__
  8.  
  9. !add <username = "Fulano"> <hp = 10> // Adiciona um participante
  10. !hp <username = "Fulano"> <hp = 0> // Modifica HP de um participante
  11. !skip // Passa pro próximo mapa
  12. ]]--
  13.  
  14. -- Não mude nada a partir daqui
  15.  
  16. local maps_cache = {}
  17. local current_interval = 10
  18. local cannon_to_spawn = false
  19. local current_difficulty = "easy"
  20. local ended = false
  21. local no_participants = true
  22. local participants = {}
  23. local alive_players = {}
  24. local difficulty_time = {
  25. ["easy"] = 7,
  26. ["normal"] = 8,
  27. ["hard"] = 9
  28. }
  29. local spectrum = {0x38ab07, 0x41c609, 0x47d80a, 0x50f20b, 0x91f507, 0xa2f409, 0xd1f507, 0xfff200, 0xf4e900, 0xe8dc00, 0xd9ce00, 0xd9b800, 0xd99300, 0xd95700, 0xd84201, 0xd91500, 0xc61400, 0xbb1300, 0xb31200, 0xa61100}
  30.  
  31. do
  32. local _, nickname = pcall(nil)
  33. local owner = string.match(nickname, "(.-)%.")
  34. admins[#admins + 1] = owner
  35. end
  36.  
  37. do
  38. local new_table = {}
  39.  
  40. for o, a in next, admins do
  41. new_table[a] = a
  42. end
  43.  
  44. admins = new_table
  45. end
  46.  
  47. function split(t, s)
  48. local a={}
  49. for i in string.gmatch(t, "[^" .. (s or "%s") .. "]+") do
  50. a[#a + 1] = i
  51. end
  52. return a
  53. end
  54.  
  55. function log(text)
  56. print('<V>[Log]</V> <N>' .. text)
  57. end
  58.  
  59. function changeDifficulty(difficulty)
  60. if difficulty == "easy" or difficulty == "normal" or difficulty == "hard" then
  61. current_difficulty = difficulty
  62. current_interval = 10
  63. showDifficulty()
  64. end
  65. end
  66.  
  67. function showDifficulty(user)
  68. local easy_text = (current_difficulty == "easy" and "" or "<a href='event:easy'>") .. "<font color=\"#4AFF59\">Fácil"
  69. local normal_text = (current_difficulty == "normal" and "" or "<a href='event:normal'>") .. "<font color=\"#E5EF27\">Normal"
  70. local hard_text = (current_difficulty == "hard" and "" or "<a href='event:hard'>") .. "<font color=\"#EF2626\">Difícil"
  71. local players = user and {[user] = {}} or tfm.get.room.playerList
  72.  
  73. for name, data in next, players do
  74. ui.addTextArea(0, "", name, 661, 375, 130, 17, 0x010101, nil, 0.7, true)
  75. ui.addTextArea(1, easy_text, name, 661, 375, nil, nil, 0x767676, nil, current_difficulty == "easy" and 0.3 or 0, true)
  76. ui.addTextArea(2, normal_text, name, 700, 375, nil, nil, 0x767676, nil, current_difficulty == "normal" and 0.3 or 0, true)
  77. ui.addTextArea(3, hard_text, name, 755, 375, nil, nil, 0x767676, nil, current_difficulty == "hard" and 0.3 or 0, true)
  78. end
  79. end
  80.  
  81. function changeMap()
  82. if #maps_cache == 0 then
  83. for index, map in next, maps do
  84. maps_cache[#maps_cache + 1] = map
  85. end
  86. end
  87.  
  88. tfm.exec.newGame(enable_rotation and table.remove(maps_cache, math.random(#maps_cache)) or maps[math.random(#maps)], math.random(1, 5) == 1 and true or false)
  89. end
  90.  
  91. function spawnCannon(data)
  92. local info = {}
  93.  
  94. local px = data.x
  95. local py = data.y
  96.  
  97. local cnnx = math.random()*800
  98. local cnny = math.random()*400
  99.  
  100. if cnny > py then
  101. cnny = py-math.random(50)-20
  102. end
  103.  
  104. if math.abs(cnnx-px) > 300 then
  105. cnnx = px + math.random(-50, 50)
  106. end
  107.  
  108. local ang = math.deg(math.atan2(cnny-py, cnnx-px))
  109. tfm.exec.addShamanObject(0, cnnx, cnny, ang+90)
  110.  
  111. info[1] = cnnx
  112. info[2] = cnny
  113. info[3] = ang - 90
  114.  
  115. return info
  116. end
  117.  
  118. function alivePlayers()
  119. local n = 0
  120.  
  121. for name, player in next, tfm.get.room.playerList do
  122. if not player.isDead then
  123. n = n + 1
  124. end
  125. end
  126.  
  127. return n
  128. end
  129.  
  130. function addPlayer(name, hp)
  131. participants[name] = {hp = hp, score = 0, total_hp = hp}
  132. tfm.exec.setPlayerScore(name, hp, false)
  133.  
  134. if no_participants then
  135. no_participants = false
  136. changeMap()
  137. end
  138. end
  139.  
  140. function editHP(name, hp)
  141. if participants[name] then
  142. participants[name].hp = hp
  143. tfm.exec.setPlayerScore(name, participants[name].hp, false)
  144.  
  145. if participants[name].hp == 0 then
  146. log(name .. ' perdeu todas as vidas e teve um resultado de <ROSE>' .. participants[name].score .. '</ROSE> partidas ganhas.')
  147. participants[name] = nil
  148. tfm.exec.killPlayer(name)
  149. end
  150. end
  151. end
  152.  
  153. function removeHP(name)
  154. if participants[name] then
  155. editHP(name, participants[name].hp - 1)
  156. end
  157. end
  158.  
  159. function eventChatCommand(name, cmd)
  160. local args = split(cmd, ' ')
  161.  
  162. if admins[name] then
  163. if args[1] == 'addall' then
  164. for i, v in next, tfm.get.room.playerList do
  165. if not participants[i] then
  166. addPlayer(i, 10)
  167. end
  168. end
  169. elseif args[1] == 'add' and args[2] and tfm.get.room.playerList[args[2]] and args[3] and tonumber(args[3]) and not participants[args[2]] then
  170. addPlayer(args[2], tonumber(args[3]))
  171. elseif args[1] == 'skip' then
  172. changeMap()
  173. elseif args[1] == 'hp' and args[2] and tfm.get.room.playerList[args[2]] and args[3] and tonumber(args[3]) and participants[args[2]] then
  174. editHP(args[2], tonumber(args[3]))
  175. end
  176. end
  177. end
  178.  
  179. function eventLoop(time, remaining)
  180. ui.setMapName('<CS>' .. tribe_name .. '</CS> <BL>|</BL> <VP>Teste para Cargo</VP>')
  181.  
  182. if not no_participants then
  183. if time > 3000 then
  184. current_interval = current_interval - 1
  185.  
  186. if not ended then
  187. if current_interval == difficulty_time[current_difficulty] then
  188. local users = {}
  189.  
  190. for name in next, participants do
  191. if tfm.get.room.playerList[name] and not tfm.get.room.playerList[name].isDead then
  192. users[#users + 1] = tfm.get.room.playerList[name]
  193. end
  194. end
  195.  
  196. cannon_to_spawn = #users > 0 and spawnCannon(users[math.random(#users)]) or false
  197. current_interval = 11
  198. elseif current_interval == 10 and cannon_to_spawn then
  199. tfm.exec.addShamanObject(17, cannon_to_spawn[1], cannon_to_spawn[2], cannon_to_spawn[3])
  200. cannon_to_spawn = false
  201. end
  202. elseif remaining > 0 then
  203. if current_interval <= 0 then
  204. changeMap()
  205. end
  206. end
  207. end
  208.  
  209. if remaining <= 0 then
  210. if not ended then
  211. ended = true
  212. current_interval = 20
  213. tfm.exec.setGameTime(10)
  214. ui.addTextArea(5, "<VP><p align='center'><B><font size='18'>PARABÉNS, você conseguiu!", nil, 10, 33, 780, 30, 0x010101, 0x010101, 0.8, true)
  215.  
  216. for name, data in next, tfm.get.room.playerList do
  217. if not data.isDead and participants[name] then
  218. participants[name].score = participants[name].score + 1
  219. log(name .. ' venceu uma partida! Score total: ' .. participants[name].score)
  220. end
  221. end
  222. end
  223.  
  224. current_interval = current_interval - 1
  225.  
  226. if current_interval <= 0 then
  227. changeMap()
  228. end
  229. end
  230. end
  231. end
  232.  
  233. function eventTextAreaCallback(id, name, cb)
  234. if admins[name] then
  235. changeDifficulty(cb)
  236. end
  237. end
  238.  
  239. function eventNewGame()
  240. ended = false
  241. alive_players = {}
  242. current_interval = 10
  243. ui.removeTextArea(5)
  244.  
  245. local alive_count = 0
  246.  
  247. for name, data in next, tfm.get.room.playerList do
  248. if not participants[name] then
  249. tfm.exec.killPlayer(name)
  250. else
  251. alive_count = alive_count + 1
  252. alive_players[name] = true
  253. tfm.exec.setNameColor(name, spectrum[math.floor((#spectrum * (participants[name].total_hp - participants[name].hp + 1)) / participants[name].total_hp)] or spectrum[1])
  254. end
  255. end
  256.  
  257. if alive_count == 0 then
  258. no_participants = true
  259. tfm.exec.setGameTime(99999999)
  260. ui.addTextArea(5, "<R><p align='center'><B><font size='18'>Não há participantes o suficiente para começar", nil, 10, 33, 780, 30, 0x010101, 0x010101, 0.8, true)
  261. end
  262. end
  263.  
  264. function eventNewPlayer(name)
  265. showDifficulty(name)
  266. tfm.exec.setPlayerScore(name, not participants[name] and 0 or participants[name].hp, false)
  267. end
  268.  
  269. function eventPlayerLeft(name)
  270. if alive_players[name] then
  271. alive_players[name] = nil
  272. removeHP(name)
  273. end
  274. end
  275.  
  276. function eventPlayerDied(name)
  277. if not ended then
  278. if not no_participants then
  279. if alivePlayers() < 1 then
  280. current_interval = 10
  281. tfm.exec.setGameTime(5)
  282. ended = true
  283. ui.addTextArea(5, "<p align='center'><CE><font size='18'>Ninguém venceu!", nil, 10, 33, 780, 30, 0x010101, 0x010101, 0.8, true)
  284. end
  285. end
  286.  
  287. alive_players[name] = nil
  288. if participants[name] then
  289. removeHP(name)
  290. end
  291. end
  292. end
  293.  
  294. for index, value in next, {'AutoScore', 'AutoShaman', 'AutoNewGame', 'AutoTimeLeft', 'PhysicalConsumables', 'DebugCommand', 'MinimalistMode', 'AllShamanSkills'} do
  295. tfm.exec['disable' .. value]()
  296. end
  297.  
  298. system.disableChatCommandDisplay("add")
  299. system.disableChatCommandDisplay("skip")
  300. system.disableChatCommandDisplay("hp")
  301.  
  302. table.foreach(tfm.get.room.playerList, eventNewPlayer)
  303. tfm.exec.newGame(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement