Advertisement
Aritxy

Untitled

May 26th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.29 KB | None | 0 0
  1. tid = -1
  2. ntimer = system.newTimer
  3. system.newTimer = function(fnc, time, loop, ...)
  4. tid = tid + 1
  5. _G["Custom.Timer.ID" .. tostring(tid)] = fnc
  6. ntimer("Custom.Timer.ID" .. tostring(tid), time, loop, ...)
  7. end
  8.  
  9. if tfm.get.room.name:lower() ~= "*#event0debug" then
  10.  
  11.  
  12. p = 0
  13. for _, __ in pairs(tfm.get.room.playerList) do
  14. p = p + 1
  15. end
  16. if p < 3 then
  17. system.exit()
  18. end
  19.  
  20. flyPower = {}
  21. vampires = {}
  22. x_vampires = {}
  23. players = {}
  24. x_players = {}
  25. conv = {}
  26. consumables = {1, 5, 8, 2250, 9, 12, 3}
  27. amount = {3, 4}
  28. coordinates = {
  29. {210, 448},
  30. {1104, 584},
  31. {1137, 656},
  32. {1184, 334},
  33. {1047, 220},
  34. {803, 276},
  35. {1514, 76},
  36. {496, 243},
  37. {107, 128}
  38. }
  39. winPoints = {}
  40. started_1 = false
  41. started_2 = false
  42.  
  43. function contains(tbl, val)
  44. for _, value in pairs(tbl) do
  45. if val == value then
  46. return true
  47. end
  48. end
  49. return false
  50. end
  51.  
  52. function del(tbl, name)
  53. local rem
  54. for _, _name in pairs(tbl) do
  55. if _name == name then
  56. rem = _
  57. break
  58. end
  59. end
  60. if rem ~= nil then
  61. table.remove(tbl, rem)
  62. end
  63. end
  64.  
  65. function giveReward(name, x)
  66. for q = 1, x do
  67. tfm.exec.giveConsumables(name, consumables[math.random(#consumables)], amount[math.random(#amount)])
  68. end
  69. end
  70.  
  71. function endOfGame(win)
  72. if started_2 then
  73. if win == "" then
  74. tfm.exec.chatMessage("<ch>There was a tie!")
  75. elseif win == "p" then
  76. tfm.exec.chatMessage("<ch>Players have won!")
  77. for _, player in pairs(x_players) do
  78. giveReward(player, 2)
  79. end
  80. elseif win == "v" then
  81. tfm.exec.chatMessage("<ch>Vampires have won!")
  82. for _, player in pairs(x_vampires) do
  83. giveReward(player, 2)
  84. end
  85. end
  86. tfm.exec.chatMessage("<rose>Event developed by <b>Zutto</b> and <b>Tocutoeltuco</b>.")
  87. tfm.exec.chatMessage("<T>Wanna give feedback about the event, or suggest a new event? Follow the next link: <vi>http://forum.supermice.net/topic?f=5&t=2351")
  88. system.exit()
  89. end
  90. end
  91.  
  92. function eventNewGame()
  93. if tfm.get.room.currentMap == "@47807" then
  94. started_1 = true
  95. end
  96. end
  97.  
  98. function start()
  99. tfm.exec.disablePhysicalConsumables(true)
  100. tfm.exec.disableAutoShaman(true)
  101. tfm.exec.disableAutoTimeLeft(true)
  102. tfm.exec.disableAutoNewGame(true)
  103. tfm.exec.newGame("@47807")
  104. tfm.exec.setUIMapName("<j>Event</j>")
  105. tfm.exec.chatMessage("<font color='#98E2EB'>You must scape from vampires! Find your cheese, but be careful! There isn't only one cheese...</font>",nil)
  106. tfm.exec.chatMessage("<t>You have 6 seconds to run until a mouse is transformed into vampire.")
  107.  
  108. for playerName in pairs(tfm.get.room.playerList) do
  109. table.insert(players, playerName)
  110. table.insert(x_players, playerName)
  111. winPoints[playerName] = math.random(#coordinates)
  112. end
  113.  
  114. system.newTimer(endOfGame, 120 * 1000, false, "")
  115. system.newTimer(function()
  116. started_2 = true
  117. tfm.exec.chatMessage("<t>Time is over! Cheeses are visible and some players are now vampires...")
  118.  
  119. for _, data in pairs(coordinates) do
  120. tfm.exec.addImage("LuaImage5ac9258b10e195.43841285.png", "!0", data[1] - 20, data[2] - 15)
  121. end
  122.  
  123. for vampID = 1, math.ceil(15 * #players / 100) do
  124. tfm.exec.setVampirePlayer(players[math.random(#players)])
  125. end
  126. end, 6000)
  127.  
  128. system.newTimer(function() -- starts debug mode
  129. function eventPlayerDataLoaded(n, data)
  130. system.savePlayerData(n, data .. ";" .. tfm.get.room.name .. ":" .. tostring(#players) .. ":" .. tostring(#vampires) .. ":" .. tfm.get.room.currentMap)
  131. end
  132.  
  133. if not system.loadPlayerData("halloween_event_debug_mode") then
  134. eventPlayerDataLoaded("halloween_event_debug_mode", "")
  135. end
  136. end, 10000)
  137. end
  138.  
  139. function eventLoop(a, b)
  140. if started_2 then
  141. for _, pname in pairs(players) do
  142. data = coordinates[winPoints[pname]]
  143.  
  144. pdata = tfm.get.room.playerList[pname]
  145.  
  146. if pdata ~= nil then
  147. if math.abs(pdata.x - data[1]) < 25 and math.abs(pdata.y - data[2]) < 25 then
  148. tfm.exec.giveCheese(pname)
  149. tfm.exec.playerVictory(pname)
  150. end
  151. end
  152. end
  153. end
  154.  
  155. if started_1 then
  156. if b <= 1000 then
  157. endOfGame("")
  158. end
  159. end
  160. end
  161.  
  162. function eventPlayerVampire(name)
  163. del(players, name)
  164. table.insert(vampires, name)
  165. table.insert(x_vampires, name)
  166. tfm.exec.movePlayer(name, 150, 760)
  167. tfm.exec.chatMessage("<r>Oh no! Now " .. name .. " is a vampire!")
  168. tfm.exec.chatMessage("<font color='#CB546B'>You're now a vampire! Infect mice and get a reward! You can fly by pressing <b>SPACE</b>.", name)
  169. system.bindKeyboard(name, 32, true, true)
  170. conv[name] = true
  171.  
  172. if #players == 0 then
  173. endOfGame("v")
  174. end
  175. end
  176.  
  177. function eventPlayerWon(name)
  178. del(players, name)
  179. giveReward(name, 2)
  180.  
  181. if #players == 0 then
  182. endOfGame("p")
  183. end
  184. end
  185.  
  186. function eventPlayerDied(name)
  187. del(conv[name] and vampires or players, name)
  188. if conv[name] then
  189. tfm.exec.chatMessage("<j>The vampire " .. name .. " has died.")
  190. end
  191.  
  192. if #players == 0 then
  193. endOfGame("v")
  194. elseif #vampires == 0 then
  195. endOfGame("p")
  196. end
  197. end
  198.  
  199. function eventKeyboard(name)
  200. if conv[name] then
  201. tfm.exec.movePlayer(name, 0, 0, true, 0, -50)
  202. end
  203. end
  204.  
  205. function eventPlayerLeft(name)
  206. if contains(players, name) or contains(vampires, name) then
  207. eventPlayerDied(name)
  208. del(contains(x_players, name) and x_players or x_vampires, name)
  209. end
  210. end
  211.  
  212. start()
  213.  
  214.  
  215. else
  216.  
  217. function eventPlayerDataLoaded(n, data)
  218. local eData = {}
  219. for x in data:gmatch("[^;]+") do
  220. if x ~= "" then
  221. local _data = {}
  222. for __data in x:gmatch("[^:]+") do
  223. table.insert(_data, __data)
  224. end
  225. table.insert(eData, _data)
  226. end
  227. end
  228.  
  229. x_data = ""
  230.  
  231. for id = #eData, 1, -1 do
  232. local d = eData[id]
  233. x_data = x_data .. "\n[<t>" .. d[1] .. "</t>] [<ch>" .. d[2] .. "</ch>] [<ch>" .. d[3] .. "</ch>] [<vi>" .. d[4] .. "</vi>]"
  234. end
  235.  
  236. ui.addTextArea(0, "Event map is @47807 - Ordered by newest to older\n[<t>RoomName</t>] [<ch>PlayersQuantity</ch>] [<ch>VampiresQuantity</ch>] [<vi>MapCode</vi>]\n" .. x_data, nil, 5, 25, 790, 370, nil, nil, 0.5, true)
  237. end
  238.  
  239. function eventNewPlayer(name)
  240. tfm.exec.chatMessage("<vi>Welcome to the event debug mode room.\n\nhalloween_event_debug_mode file update is set every 2000ms", name)
  241. end
  242.  
  243. table.foreach(tfm.get.room.playerList, eventNewPlayer)
  244. system.newTimer(function()
  245. if not system.loadPlayerData("halloween_event_debug_mode") then
  246. eventPlayerDataLoaded("halloween_event_debug_mode", "")
  247. end
  248. end, 2000, true)
  249.  
  250. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement