Advertisement
suxonov

Updated [06/07/2016]

May 21st, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.78 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 = '<N>You have <V>10 seconds<N> to get ready!',
  58.         _go = '<N>GO!',
  59.         _newWave = '<V>Wave %x<N> starts right now!',
  60.         _died = '<N>Oops, you died :[',
  61.         _win = '<V>%s <N>won!',
  62.         _welcome = '<N>Welcome to our <V>#dance<N>-party! Press <V>[H]<N> to learn more. Report any issues using <V>/c Aviener#0000',
  63.         _right = '<font color="#92D64D">Right! +3</font>',
  64.         _wrong = '<font color="#D64D4D">Wrong! -2</font>',
  65.         _draw = '<N>Nobody has won! :['
  66.     }
  67.  
  68. module = {
  69.         start = function()
  70.             for name,player in pairs(tfm.get.room.playerList) do
  71.                 -- module.players.getData(name)
  72.                 players[name] = {lock = true, opennedPopup = false}
  73.                 for i, key in ipairs(keys) do
  74.                     system.bindKeyboard(name, key, true, true)
  75.                 end
  76.             end
  77.             tfm.exec.setGameTime(10)
  78.             print('<J>## <BL>Game is loaded!')
  79.         end,
  80.         addMove = function()
  81.             if started == true then
  82.                 points = points + 1
  83.                 for name,player in pairs(tfm.get.room.playerList) do
  84.                     if not player.isDead then
  85.                         players[name].lock = false
  86.                     end
  87.                 end
  88.                 i = math.random(1, 4)
  89.                 tfm.exec.addShamanObject(0, 400, 200, moves[i].direction)
  90.                 return moves[i].key, moves[i].key_, points
  91.             end
  92.         end,
  93.         newWave = function()
  94.             if started == true then
  95.                 wave = wave + 1
  96.                 module.UI.changeStatusBar(wave)
  97.             end
  98.             for name,player in pairs(tfm.get.room.playerList) do
  99.                 if player.score < points then
  100.                     tfm.exec.killPlayer(name)
  101.                 end
  102.             end
  103.             module.timers.addTimer(module.addMove, waves[wave].seconds, waves[wave].loops, i)
  104.             module.UI.message(string.format(messages._newWave, wave))
  105.         end,
  106.         timers = {
  107.             addTimer = function(callback, time, loops, label, ...)
  108.                 local id = #timerList + 1
  109.                 timerList[id] = {
  110.                 callback = callback,
  111.                 time = time,
  112.                 loops = loops or 1,
  113.                 label = label,
  114.                 arguments = {...},
  115.                 isComplete = false,
  116.                 currentTime = 0,
  117.                 currentLoop = 0,
  118.                 }
  119.                 return id
  120.             end,
  121.             removeTimer = function(id)
  122.                 if timer[id] then
  123.                     timerList[id] = 0
  124.                     return true
  125.                 end
  126.             return false
  127.             end,
  128.             removeAll = function()
  129.                 timerList = {}
  130.             end,
  131.         },
  132.         --User Interface
  133.         UI = {
  134.             changeStatusBar = function(wave)
  135.                 if wave <= 3 then
  136.                     local code = tfm.get.room.currentMap
  137.                     local author = tfm.get.room.xmlMapInfo.author
  138.                     tfm.exec.setUIMapName('<J>'..author..'<BL> - '..code..'   <font color="#5a5f6e">|</font>   <N>Wave: <V>'..wave..'/3')
  139.                 end
  140.             end,
  141.             message = function(message, name)
  142.                 tfm.exec.chatMessage(message, name)
  143.                 --print (message)
  144.             end,
  145.             addPopup = function(id, text, n, x, y, width, height)
  146.                 players[n].opennedPopup = true
  147.                 ui.addTextArea(id, "", n, x +  - 2, y + 18, width + 24, height + 14, 0x2E221B, 0x2E221B, 1, true)
  148.                 ui.addTextArea(id + 1, "", n, x + - 1, y + 19, width + 22, height + 12, 0x986742, 0x986742, 1, true)
  149.                 ui.addTextArea(id + 2, "", n, x + 2, y + 22, width + 16, height + 6, 0x171311, 0x171311, 1, true)
  150.                 ui.addTextArea(id + 3, "", n, x + 3, y + 23, width + 14, height + 4, 0x0C191C, 0x0C191C, 1, true)
  151.                 ui.addTextArea(id + 4, "", n, x + 4, y + 24, width + 12, height + 2, 0x24474D, 0x24474D, 1, true)
  152.                 ui.addTextArea(id + 5, "", n, x + 5, y + 25, width + 10, height + 0, 0x183337, 0x183337, 1, true)
  153.                 ui.addTextArea(id + 6, text, n, x + 6, y + 26, width + 8, height + - 2, 0x324650, 0x324650, 1, true)
  154.                 ui.addTextArea(id + 7, "", n, x + 12, y + height - 20 + 25, width - 5, 15, 0x5D7D90, 0x5D7D90, 1, true)
  155.                 ui.addTextArea(id + 8, "", n, x + 12, y + height - 20 + 27, width - 5, 15, 0x11171C, 0x11171C, 1, true)
  156.                 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)
  157.             end,   
  158.             removePopup = function(id, n)
  159.                 for id = id, (id + 9) do
  160.                     ui.removeTextArea(id, n)
  161.                 end
  162.                 players[n].opennedPopup = false
  163.             end;
  164.         },
  165.         --Players settings, data and etc
  166.         players = {
  167.             --[[getData = function(name)
  168.                     local data = system.loadPlayerData(name)
  169.                     if data == nil then
  170.                         set default 0/0/0/0
  171.                     end
  172.                     return data end
  173.                 end,]]
  174.         },
  175.                
  176.     }
  177.     eventNewGame = function()
  178.         started = false
  179.         wave = 1
  180.         points = 0
  181.         module.timers.removeAll()
  182.         for name,player in pairs(tfm.get.room.playerList) do
  183.             players[name].lock = true
  184.             tfm.exec.setPlayerScore(name, 0, false)
  185.         end
  186.         tfm.exec.setGameTime(220)
  187.         module.UI.message(messages._start)
  188.         module.UI.changeStatusBar(wave)
  189.         module.timers.addTimer(module.addMove, waves[wave].seconds, waves[wave].loops, i)
  190.         module.timers.addTimer(module.newWave, 60000, 2)
  191.     end
  192.     function eventKeyboard(name, key, down, x, y)
  193.         if key~= 72 and players[name].lock == false and started == true then
  194.             if key == moves[i].key or key == moves[i].key_ then
  195.                 module.UI.message(messages._right, name)
  196.                 tfm.exec.setPlayerScore(name, 3, true)
  197.                 players[name].lock = true
  198.             else
  199.                 module.UI.message(messages._wrong, name)
  200.                 tfm.exec.setPlayerScore(name, -2, true)
  201.                 players[name].lock = true
  202.             end
  203.         end
  204.         if key == 72 and not players[name].opennedPopup then
  205.             module.UI.addPopup(1, messages._help, name, 230, 100, 327, 210)
  206.         elseif key == 72 and players[name].opennedPopup then
  207.             module.UI.removePopup(1, name)
  208.         end
  209.     end
  210.     function eventTextAreaCallback(textAreaID, name, callback)
  211.         if callback == 'close' then
  212.             module.UI.removePopup(1, name)
  213.         end
  214.     end
  215.     eventPlayerDied = function(name)
  216.         local i = 0
  217.         n = name
  218.         for name,player in pairs(tfm.get.room.playerList) do
  219.             if not player.isDead then
  220.                 i = i + 1
  221.             end
  222.         end
  223.         if i == 1 then
  224.             n = name
  225.             tfm.exec.playerVictory(name)
  226.             module.UI.message(string.format(messages._win, name))
  227.         end
  228.         if i == 0 then
  229.             tfm.exec.setGameTime(0)
  230.             module.UI.message(messages._draw)
  231.         end
  232.         module.UI.message(messages._died, name)
  233.     end;
  234.     eventLoop = function(time, remain)
  235.         -- timer
  236.         local timersToRemove = {}
  237.         for id = 1, #timerList do
  238.             local timer = timerList[id]
  239.             if type(timer) == 'table' then
  240.                 if not timer.isComplete then
  241.                     timer.currentTime = timer.currentTime + 500
  242.                     if timer.currentTime >= timer.time then
  243.                         timer.currentTime = 0
  244.                         timer.currentLoop = timer.currentLoop + 1
  245.                         if timer.loops > 0 then
  246.                             if timer.currentLoop >= timer.loops then
  247.                                 timer.isComplete = true
  248.                             end
  249.                         end
  250.                         if type(timer.callback) == 'function' then
  251.                             timer.callback(timer.currentLoop, table.unpack(timer.arguments))
  252.                         end
  253.                     end
  254.                 end
  255.                 if timer.isComplete then
  256.                     if type(eventTimerComplete) == 'function' then
  257.                         eventTimerComplete(id, timer.label)
  258.                     end
  259.                     timersToRemove[#timersToRemove+1] = id
  260.                 end
  261.             end
  262.         end
  263.         if time >= 10000 and started == false then
  264.             started = true
  265.             module.UI.message(messages._go)
  266.         end
  267.         if remain <= 0 then
  268.             tfm.exec.newGame(6680501)
  269.         elseif remain <= 40 then
  270.             started = false
  271.             for name,player in pairs(tfm.get.room.playerList) do
  272.                 if player.score < points then
  273.                     tfm.exec.killPlayer(name)
  274.                 end
  275.             end
  276.         end
  277.     end
  278.    
  279.  
  280. module.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement