Karluwu

FREEZE TAG

Mar 4th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.28 KB | None | 0 0
  1. --------------
  2. -- Settings --
  3. --------------
  4. OUTPUT_MODE = 2
  5. -- 0 = silent mode (only visible to the one who loaded the script)
  6. -- 1 = chat box mode (will not work in tribehouse)
  7. -- 2 = tribe mode (will work in tribehouse; outputs through a textbox)
  8. KILL_RADIUS = 75
  9. -- The radius (in pixels) around the ice mouse that is considered in-range to freeze another mouse
  10. COOLDOWN = 2.5;
  11. -- The time (in seconds) of delay between when the ice mouse can freeze again after attacking and when a mouse can revive another mouse (only increments of 0.5)
  12. RESCUE_RADIUS = 100
  13. -- The radius (in pixels) around every other mouse that is considered in-ranged to unfreeze an ice block
  14. OUTPUT_NAME_COLOR = '<V>'
  15. OUTPUT_MESSAGE_COLOR = '<J>'
  16. -- Color tags to be used during output
  17. MAPS = {'@556317', '@556315'}
  18. -- Add more, separate with commas and use quotes, will be chosen randomly(e.g MAPS = {'@111111', '@222222', '@333333'})
  19.  
  20. --------------
  21. --------------
  22. tfm.exec.disableAfkDeath(true)
  23. tfm.exec.disableAutoNewGame(true)
  24. tfm.exec.disableAutoScore(true)
  25. tfm.exec.disableAutoShaman(true)
  26. tfm.exec.disableAutoTimeLeft(true)
  27. tfm.exec.disableAllShamanSkills(true)
  28.  
  29. if OUTPUT_MODE == 2 then
  30. ui.addTextArea(0, '', nil, 5, 5)
  31. end
  32. ui.addTextArea(1, '', nil, 5, 375)
  33.  
  34. all_players = {}
  35. ice_blocks = {}
  36. cooldowns = {}
  37. ice_mouse = '';
  38. countdown = 3
  39. second_mark = false
  40. all_dead = false
  41. can_attack = false
  42. time_to_clear_ttt = 3
  43. time_to_clear_ctt = 3
  44. mk_for_reset = false
  45. ttt = ''
  46. ctt = ''
  47.  
  48. function output_msg(msg)
  49. if OUTPUT_MODE == 0 then
  50. print(msg)
  51. elseif OUTPUT_MODE == 1 then
  52. tfm.exec.chatMessage(msg)
  53. elseif OUTPUT_MODE == 2 then
  54. ttt = ttt .. '\n' .. msg
  55. ui.updateTextArea(0, ttt)
  56. time_to_clear_ttt = 3
  57. end
  58. end
  59.  
  60. function countdown_msg(msg)
  61. ctt = ctt .. ' ' .. msg
  62. ui.updateTextArea(1, ctt)
  63. time_to_clear_ctt = 3
  64. end
  65.  
  66. for name,player in pairs(tfm.get.room.playerList) do
  67. table.insert(all_players, name)
  68. tfm.exec.setPlayerScore(name, 0, false)
  69. end
  70.  
  71. function start_new_game()
  72. all_players = {}
  73. ice_blocks = {}
  74. can_attack = false
  75. tfm.exec.newGame(MAPS[math.random(#MAPS)])
  76.  
  77. for name,player in pairs(tfm.get.room.playerList) do
  78. tfm.exec.bindKeyboard(name, 32, true, true)
  79. table.insert(all_players, name)
  80. cooldowns[name] = 0
  81. tfm.exec.setNameColor(name, 0xB5B5B5)
  82. end
  83.  
  84. ice_mouse = all_players[math.random(#all_players)]
  85. tfm.exec.setNameColor(ice_mouse, 0x009DFF)
  86.  
  87. output_msg(OUTPUT_NAME_COLOR .. ice_mouse .. OUTPUT_MESSAGE_COLOR .. ' is the Ice Mouse!')
  88. output_msg(OUTPUT_MESSAGE_COLOR .. 'The game will start in 10 seconds!')
  89. countdown = 10
  90. end
  91.  
  92. function set_new_game_countdown(num)
  93. countdown = 20 + num
  94. end
  95.  
  96. function eventLoop(current_time, time_remaining)
  97. second_mark = not second_mark
  98. if second_mark then
  99. if countdown > 0 and countdown < 20 then
  100. countdown_msg(OUTPUT_MESSAGE_COLOR .. countdown)
  101. countdown = countdown - 1
  102. elseif countdown == 0 then
  103. countdown_msg(OUTPUT_MESSAGE_COLOR .. 'Go!')
  104. countdown = -1
  105. can_attack = true
  106. elseif countdown == 20 then
  107. output_msg(OUTPUT_MESSAGE_COLOR .. 'Starting next game!')
  108. start_new_game()
  109. elseif countdown > 20 then
  110. countdown = countdown - 1
  111. end
  112. if time_to_clear_ttt == 0 and OUTPUT_MODE == 2 then
  113. if mk_for_reset then
  114. ui.removeTextArea(0)
  115. ui.addTextArea(0, '', nil, 5, 5)
  116. else
  117. ttt = ''
  118. ui.updateTextArea(0, ttt)
  119. end
  120. end
  121. if time_to_clear_ctt == 0 and OUTPUT_MODE == 2 then
  122. if mk_for_reset then
  123. ui.removeTextArea(1)
  124. ui.addTextArea(1, '', nil, 5, 375)
  125. mk_for_reset = false
  126. else
  127. ctt = ''
  128. ui.updateTextArea(1, ctt)
  129. end
  130. end
  131. time_to_clear_ttt = time_to_clear_ttt - 1
  132. time_to_clear_ctt = time_to_clear_ctt - 1
  133. end
  134. if time_remaining <= 1 then
  135. for name,player in pairs(tfm.get.room.playerList) do
  136. if (name ~= ice_mouse) and not (tfm.get.room.playerList[name].isDead) then
  137. all_dead = false
  138. end
  139. end
  140. output_msg(OUTPUT_MESSAGE_COLOR .. 'Oh no! The Ice Mouse ' .. OUTPUT_NAME_COLOR .. ice_mouse .. OUTPUT_MESSAGE_COLOR .. ' has failed to freeze all the mice!')
  141. output_msg(OUTPUT_MESSAGE_COLOR .. 'New game starting now!')
  142. start_new_game()
  143. end
  144. for num,name in pairs(all_players) do
  145. if cooldowns[name] > 0 then
  146. cooldowns[name] = cooldowns[name] - 1
  147. end
  148. end
  149. end
  150.  
  151. function check_alive()
  152. all_dead = true
  153. for name,player in pairs(tfm.get.room.playerList) do
  154. if (name ~= ice_mouse) and not (tfm.get.room.playerList[name].isDead) then
  155. all_dead = false
  156. end
  157. end
  158. if all_dead then
  159. tfm.exec.setPlayerScore(ice_mouse, 1, true)
  160. output_msg(OUTPUT_NAME_COLOR .. ice_mouse .. OUTPUT_MESSAGE_COLOR .. ' has frozen all of the mice!')
  161. output_msg(OUTPUT_NAME_COLOR .. ice_mouse .. OUTPUT_MESSAGE_COLOR .. ' wins!')
  162. output_msg(OUTPUT_MESSAGE_COLOR .. 'The next game will start in 5 seconds')
  163. set_new_game_countdown(5)
  164. end
  165. end
  166.  
  167. function eventPlayerDied(name)
  168. if name == ice_mouse then
  169. for namme,player in pairs(tfm.get.room.playerList) do
  170. if namme ~= ice_mouse and not tfm.get.room.playerList[namme].isDead then
  171. tfm.exec.setPlayerScore(namme, 1, true)
  172. end
  173. end
  174. output_msg(OUTPUT_MESSAGE_COLOR .. 'The Ice Mouse ' .. OUTPUT_NAME_COLOR .. ice_mouse .. OUTPUT_MESSAGE_COLOR .. ' has died!')
  175. output_msg(OUTPUT_MESSAGE_COLOR .. 'The next game will start in 5 seconds')
  176. set_new_game_countdown(5)
  177. else
  178. output_msg(OUTPUT_NAME_COLOR .. name .. OUTPUT_MESSAGE_COLOR .. ' has been frozen!')
  179. ice_blocks[tfm.exec.addShamanObject(54, tfm.get.room.playerList[name].x, tfm.get.room.playerList[name].y, 0, 0, 0, false)] = name
  180. check_alive()
  181. end
  182. end
  183.  
  184. --[[-- Somewhat useful; enable if you want
  185. function eventChatCommand(name, cmd)
  186. if cmd == 'newgame' then
  187. start_new_game()
  188. elseif cmd == 'gg' then
  189. tfm.exec.killPlayer(ice_mouse)
  190. elseif cmd == 'ff' then
  191. tfm.exec.killPlayer(name)
  192. end
  193. end
  194. --]]--
  195. function search_and_kill()
  196. for name,player in pairs(tfm.get.room.playerList) do
  197. if (name ~= ice_mouse) and (not tfm.get.room.playerList[name].isDead) and (math.abs(tfm.get.room.playerList[name].x - tfm.get.room.playerList[ice_mouse].x) <= KILL_RADIUS) and (math.abs(tfm.get.room.playerList[name].y - tfm.get.room.playerList[ice_mouse].y) <= KILL_RADIUS) then
  198. tfm.exec.killPlayer(name)
  199. return
  200. end
  201. end
  202. end
  203.  
  204. function search_and_rescue(rescuee)
  205. for id in pairs(ice_blocks) do
  206. if (math.abs(tfm.get.room.objectList[id].x - tfm.get.room.playerList[rescuee].x) <= RESCUE_RADIUS) and (math.abs(tfm.get.room.objectList[id].y - tfm.get.room.playerList[rescuee].y) <= RESCUE_RADIUS) then
  207. output_msg(OUTPUT_NAME_COLOR .. ice_blocks[id] .. OUTPUT_MESSAGE_COLOR .. ' has been thawed by ' .. OUTPUT_NAME_COLOR .. rescuee)
  208. tfm.exec.respawnPlayer(ice_blocks[id])
  209. tfm.exec.movePlayer(ice_blocks[id], tfm.get.room.objectList[id].x, tfm.get.room.objectList[id].y, false, 0, 0, false)
  210. tfm.exec.removeObject(id)
  211. ice_blocks[id] = nil
  212. return
  213. end
  214. end
  215.  
  216. end
  217.  
  218. function eventKeyboard(name, key, down, x, y)
  219. if not tfm.get.room.playerList[name].isDead and can_attack and key == 32 and cooldowns[name] == 0 then
  220. if name == ice_mouse then
  221. search_and_kill()
  222. else
  223. search_and_rescue(name)
  224. end
  225. cooldowns[name] = COOLDOWN * 2
  226. end
  227. end
  228.  
  229. function eventNewPlayer(name)
  230. mk_for_reset = true
  231. end
  232.  
  233. start_new_game()
Add Comment
Please, Sign In to add comment