Advertisement
suxonov

Untitled

Apr 6th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.86 KB | None | 0 0
  1. --[[
  2. /!\ This version hasn't tested with a lot of mice in a room yet. So there could be bugs.
  3. beta version 1.3
  4. Last update: 06/07/2016
  5. To-do list:
  6. • Rsrrambler won! WITH 0 POINTS! WTF? (Should be fixed after reorganizing)
  7. • Profiles (http://i.imgur.com/Zakdatu.png)
  8. ChangeLog:
  9. Beta version 1.1:
  10. • arrows aren't speed up [fixed];
  11. Beta version 1.2
  12. • Wave 4 error [fixed];
  13. • Messages bug [fixed].
  14. Beta version 1.3
  15. • Code has been reorganized.]]
  16.  
  17. tfm.exec.disableAutoNewGame(true)
  18. tfm.exec.disableAutoShaman(true)
  19. tfm.exec.disableAutoTimeLeft(true)
  20. tfm.exec.disableAfkDeath(true)
  21.  
  22. players = {}
  23. timerList = {}
  24. moves = {
  25. [1] = {direction = -90; key = 39, key_ = 68}, --right
  26. [2] = {direction = 90; key = 37, key_ = 65}, -- left
  27. [3] = {direction = -180; key = 38, key_ = 87}, -- up
  28. [4] = {direction = 0; key = 40, key_ = 83}, -- down
  29. }
  30. waves = {
  31. [1] = {seconds = 1800, loops = 38},
  32. [2] = {seconds = 1500, loops = 50},
  33. [3] = {seconds = 1000, loops = 55},
  34. }
  35. default = {
  36. stats = {
  37. waves = 0,
  38. wins = 0,
  39. deaths = 0,
  40. right = 0,
  41. wrong = 0,
  42. },
  43. }
  44. keys = {
  45. 68,
  46. 65,
  47. 87,
  48. 83,
  49. 39,
  50. 37,
  51. 38,
  52. 40,
  53. 72,
  54. }
  55. messages = {
  56. _help = '<p align=\'center\'><font color=\"#009d9d\"><b><font size=\"20\">#dance</font></b></font></p><br>Move in the right directions. If you do movement right, you get <font color=\"#92d64d\">3 points</font>! If you don\'t, you get <font color=\"#d64d4d\">-2 points</font>!<br><br>Every round <span>consists of</span> 3 waves (<i>1 wave per minute!</i>). With every new wave you have to move faster and faster. If you make mistakes too much, you\'re going to be killed.<br><br><div>Use arrows or WASD to move and have fun in our <V>#DANCE<N>-PARTY!</div><br>',
  57. _start = '<J>Հ[#DANCE] <N>You have <V>10 seconds<N> to get ready!',
  58. _go = '<J>Հ[#DANCE] <N>GO!',
  59. _newWave = '<J>Հ[#DANCE] <V>Wave %x<N> starts right now!',
  60. _win = '<J>Հ[#DANCE] <V>%s <N>won!',
  61. _welcome = '<J>Հ[#DANCE] <N>Welcome to our <V>#dance<N>-party! Press <V>[H]<N> to learn more. Report any issues to <V>Aviener#0000',
  62. _right = '<BL>Right! +3',
  63. _wrong = '<BL>Wrong! -2',
  64. _draw = '<N>Nobody has won! :['
  65. }
  66.  
  67. module = {
  68. start = function()
  69. for name,player in pairs(tfm.get.room.playerList) do
  70. -- module.players.getData(name)
  71. players[name] = {lock = true, opennedPopup = false}
  72. for i, key in ipairs(keys) do
  73. system.bindKeyboard(name, key, true, true)
  74. end
  75. end
  76. tfm.exec.setGameTime(10)
  77. print('<J>## <BL>Game is loaded!')
  78. end,
  79. addMove = function()
  80. if started == true then
  81. points = points + 1
  82. for name,player in pairs(tfm.get.room.playerList) do
  83. if not player.isDead then
  84. players[name].lock = false
  85. end
  86. end
  87. i = math.random(1, 4)
  88. tfm.exec.addShamanObject(0, 400, 200, moves[i].direction)
  89. return moves[i].key, moves[i].key_, points
  90. end
  91. end,
  92. newWave = function()
  93. if started == true then
  94. wave = wave + 1
  95. module.UI.changeStatusBar(wave)
  96. end
  97. for name,player in pairs(tfm.get.room.playerList) do
  98. if player.score < points then
  99. tfm.exec.killPlayer(name)
  100. end
  101. end
  102. module.timers.addTimer(module.addMove, waves[wave].seconds, waves[wave].loops, i)
  103. module.UI.message(string.format(messages._newWave, wave))
  104. end,
  105. timers = {
  106. addTimer = function(callback, time, loops, label, ...)
  107. local id = #timerList + 1
  108. timerList[id] = {
  109. callback = callback,
  110. time = time,
  111. loops = loops or 1,
  112. label = label,
  113. arguments = {...},
  114. isComplete = false,
  115. currentTime = 0,
  116. currentLoop = 0,
  117. }
  118. return id
  119. end,
  120. removeTimer = function(id)
  121. if timer[id] then
  122. timerList[id] = 0
  123. return true
  124. end
  125. return false
  126. end,
  127. removeAll = function()
  128. timerList = {}
  129. end,
  130. },
  131. --User Interface
  132. UI = {
  133. changeStatusBar = function(wave)
  134. if wave <= 3 then
  135. local code = tfm.get.room.currentMap
  136. local author = tfm.get.room.xmlMapInfo.author
  137. tfm.exec.setUIMapName('<J>'..author..'<BL> - '..code..' <font color="#5a5f6e">|</font> <N>Wave: <V>'..wave..'/3')
  138. end
  139. end,
  140. message = function(message, name)
  141. tfm.exec.chatMessage(message, name)
  142. --print (message)
  143. end,
  144. addPopup = function(id, text, n, x, y, width, height)
  145. players[n].opennedPopup = true
  146. ui.addTextArea(id, "", n, x + - 2, y + 18, width + 24, height + 14, 0x2E221B, 0x2E221B, 1, true)
  147. ui.addTextArea(id + 1, "", n, x + - 1, y + 19, width + 22, height + 12, 0x986742, 0x986742, 1, true)
  148. ui.addTextArea(id + 2, "", n, x + 2, y + 22, width + 16, height + 6, 0x171311, 0x171311, 1, true)
  149. ui.addTextArea(id + 3, "", n, x + 3, y + 23, width + 14, height + 4, 0x0C191C, 0x0C191C, 1, true)
  150. ui.addTextArea(id + 4, "", n, x + 4, y + 24, width + 12, height + 2, 0x24474D, 0x24474D, 1, true)
  151. ui.addTextArea(id + 5, "", n, x + 5, y + 25, width + 10, height + 0, 0x183337, 0x183337, 1, true)
  152. ui.addTextArea(id + 6, text, n, x + 6, y + 26, width + 8, height + - 2, 0x324650, 0x324650, 1, true)
  153. ui.addTextArea(id + 7, "", n, x + 12, y + height - 20 + 25, width - 5, 15, 0x5D7D90, 0x5D7D90, 1, true)
  154. ui.addTextArea(id + 8, "", n, x + 12, y + height - 20 + 27, width - 5, 15, 0x11171C, 0x11171C, 1, true)
  155. ui.addTextArea(id + 9, "<p align='center'><a href='event:close'><N>Close</a>", n, x + 12, y + height - 20 + 26, width - 5, 15, 0x3C5064, 0x3C5064, 1, true)
  156. end,
  157. removePopup = function(id, n)
  158. for id = id, (id + 9) do
  159. ui.removeTextArea(id, n)
  160. end
  161. players[n].opennedPopup = false
  162. end;
  163. },
  164. --Players settings, data and etc
  165. players = {
  166. --[[getData = function(name)
  167. local data = system.loadPlayerData(name)
  168. if data == nil then
  169. set default 0/0/0/0
  170. end
  171. return data end
  172. end,]]
  173. },
  174.  
  175. }
  176. eventNewGame = function()
  177. started = false
  178. wave = 1
  179. points = 0
  180. module.timers.removeAll()
  181. for name,player in pairs(tfm.get.room.playerList) do
  182. players[name].lock = true
  183. tfm.exec.setPlayerScore(name, 0, false)
  184. end
  185. tfm.exec.setGameTime(220)
  186. module.UI.message(messages._start)
  187. module.UI.changeStatusBar(wave)
  188. module.timers.addTimer(module.addMove, waves[wave].seconds, waves[wave].loops, i)
  189. module.timers.addTimer(module.newWave, 60000, 2)
  190. end
  191. eventNewPlayer = function (n)
  192. if started == true then
  193. players[n].lock = true;
  194. end;
  195. module.UI.message(messages._welcome, n);
  196. end;
  197. function eventKeyboard(name, key, down, x, y)
  198. if key~= 72 and players[name].lock == false and started == true then
  199. if key == moves[i].key or key == moves[i].key_ then
  200. module.UI.message(messages._right, name)
  201. tfm.exec.setPlayerScore(name, 3, true)
  202. players[name].lock = true
  203. else
  204. module.UI.message(messages._wrong, name)
  205. tfm.exec.setPlayerScore(name, -2, true)
  206. players[name].lock = true
  207. end
  208. end
  209. if key == 72 and not players[name].opennedPopup then
  210. module.UI.addPopup(1, messages._help, name, 230, 100, 327, 210)
  211. elseif key == 72 and players[name].opennedPopup then
  212. module.UI.removePopup(1, name)
  213. end
  214. end
  215. function eventTextAreaCallback(textAreaID, name, callback)
  216. if callback == 'close' then
  217. module.UI.removePopup(1, name)
  218. end
  219. end
  220. eventPlayerDied = function(name)
  221. local i = 0
  222. n = name
  223. for name,player in pairs(tfm.get.room.playerList) do
  224. if not player.isDead then
  225. i = i + 1
  226. end
  227. end
  228. if i == 1 then
  229. n = name
  230. tfm.exec.playerVictory(name)
  231. module.UI.message(string.format(messages._win, name))
  232. end
  233. if i == 0 then
  234. tfm.exec.setGameTime(0)
  235. module.UI.message(messages._draw)
  236. end
  237. end;
  238. eventLoop = function(time, remain)
  239. -- timer
  240. local timersToRemove = {}
  241. for id = 1, #timerList do
  242. local timer = timerList[id]
  243. if type(timer) == 'table' then
  244. if not timer.isComplete then
  245. timer.currentTime = timer.currentTime + 500
  246. if timer.currentTime >= timer.time then
  247. timer.currentTime = 0
  248. timer.currentLoop = timer.currentLoop + 1
  249. if timer.loops > 0 then
  250. if timer.currentLoop >= timer.loops then
  251. timer.isComplete = true
  252. end
  253. end
  254. if type(timer.callback) == 'function' then
  255. timer.callback(timer.currentLoop, table.unpack(timer.arguments))
  256. end
  257. end
  258. end
  259. if timer.isComplete then
  260. if type(eventTimerComplete) == 'function' then
  261. eventTimerComplete(id, timer.label)
  262. end
  263. timersToRemove[#timersToRemove+1] = id
  264. end
  265. end
  266. end
  267. if time >= 10000 and started == false then
  268. started = true
  269. module.UI.message(messages._go)
  270. end
  271. if remain <= 0 then
  272. tfm.exec.newGame(6680501)
  273. elseif remain <= 40 then
  274. started = false
  275. for name,player in pairs(tfm.get.room.playerList) do
  276. if player.score < points then
  277. tfm.exec.killPlayer(name)
  278. end
  279. end
  280. end
  281. end
  282.  
  283.  
  284. module.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement