Advertisement
Slowmice

CloudGame [LUA]

Oct 12th, 2013
706
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.64 KB | None | 0 0
  1. --Forum topic : http://www.transformice.com/forum/?s=467513&p=0
  2. tfm.exec.disableAutoNewGame(true)
  3. tfm.exec.disableAutoShaman(true)
  4. tfm.exec.disableAutoTimeLeft(true)
  5.  
  6. players={}
  7. toDespawn={}
  8. maps={4007168,2113338,4062696,2818947,1822822,4012245,159709,3999440,3583744,3998852,3997006,743739,467799,139501,172357}
  9.  
  10.  
  11. tfm.exec.setGameTime(120)
  12.  
  13. tfm.exec.setUIShamanName("<font color='#F0B92E'>CloudGame</font>")
  14.  
  15. function eventNewPlayer(name)
  16.     for i,key in ipairs({32,40,83}) do
  17.         tfm.exec.bindKeyboard(name,key,true,true)
  18.     end
  19.     players[name]={
  20.         timestamp=os.time(),
  21.         offsets={x=2, y=10}
  22.     }
  23. end
  24.  
  25. function eventKeyboard(name,key,down,x,y)
  26.     if (key==32 or key==40 or key==83) and started then
  27.         if players[name].timestamp < os.time()-1000 then
  28.             local id
  29.             if tfm.get.room.playerList[name].isFacingRight then
  30.                 id=tfm.exec.addShamanObject(57,x+players[name].offsets.x,y+players[name].offsets.y)
  31.             else
  32.                 id=tfm.exec.addShamanObject(57,x+players[name].offsets.x,y+players[name].offsets.y)
  33.             end
  34.             players[name].timestamp=os.time()
  35.             table.insert(toDespawn,{os.time(),id})
  36.         end
  37.     end
  38. end
  39.  
  40. function eventChatCommand(name,command)
  41.     local arg={}
  42.     for argument in command:gmatch("[^%s]+") do
  43.         table.insert(arg,argument)
  44.     end
  45.     if arg[1]=="off" then
  46.         if tonumber(arg[2]) and tonumber(arg[3]) then
  47.             players[name].offsets={x=tonumber(arg[2]), tonumber(arg[3])}
  48.         else
  49.             players[name].offsets={x=2, y=10}
  50.         end
  51.         tfm.exec.chatMessage("Offsets changed to X:"..players[name].offsets.x.." Y:"..players[name].offsets.y,name)
  52.     end
  53. end
  54.  
  55. function eventNewGame()
  56.     started=false
  57. end
  58.  
  59. function eventLoop(time,remaining)
  60.     if time >= 3000 and not started then
  61.         started=true
  62.     end
  63.     if remaining<=0 then
  64.         tfm.exec.newGame(maps[math.random(#maps)])
  65.     end
  66.     for i,cannon in ipairs(toDespawn) do
  67.         if cannon[1] <= os.time()-3000 then
  68.             tfm.exec.removeObject(cannon[2])
  69.             table.remove(toDespawn,i)
  70.         end
  71.     end
  72. end
  73.  
  74. function eventPlayerDied(name)
  75.     local i=0
  76.     local n
  77.     for pname,player in pairs(tfm.get.room.playerList) do
  78.         if not player.isDead then
  79.             i=i+1
  80.             n=pname
  81.         end
  82.     end
  83.     if i==0 then
  84.         tfm.exec.newGame(maps[math.random(#maps)])
  85.     elseif i==1 then
  86.         tfm.exec.giveCheese(n)
  87.         tfm.exec.playerVictory(n)
  88.     end
  89. end
  90.  
  91. for name,player in pairs(tfm.get.room.playerList) do
  92.     eventNewPlayer(name)
  93. end
  94.  
  95. function eventPlayerDied(playerName)
  96.             tfm.exec.respawnPlayer(playerName)
  97. end
  98.  
  99. tfm.exec.setNameColor("Clowfish","Clowfish", 0xA2FE00)
  100.  
  101. ui.addPopup(1,3,"<B>Ты в комнате #Cloud. Помощь - !help.<B>",player,300,100,200)
  102. admins={Clowfish=true, Clowfish=true}
  103.  
  104. function isAdmin(name)
  105.     return (admins[name] or false)
  106. end
  107.  
  108. function main()
  109.     command.addHandler("map", map);
  110. end
  111.  
  112. function map(player, code)
  113.     if isAdmin(player) then
  114.         tfm.exec.newGame(code)
  115.     end
  116. end
  117.  
  118. function eventChatCommand(player, message)
  119.         local args = string.split(message, "%s")
  120.         local text = table.remove(args, 1)
  121.         command.handle(string.lower(text), player, args)
  122. end
  123. command = {handlers = {}}
  124. function command.addHandler(text, handler)
  125.     if command.handlers[text] == nil then
  126.         command.handlers[text] = {}
  127.     end
  128.     table.insert(command.handlers[text], handler)
  129. end
  130.    
  131. function command.removeHandler(text, handler)
  132.     if command.handlers[text] ~= nil then
  133.         local index
  134.         for i, h in ipairs(command.handlers[text]) do
  135.             if handler == h then
  136.                 index = i
  137.             end
  138.         end
  139.         if index ~= nil then
  140.             table.remove(command.handlers[text], index)
  141.             if #command.handlers[text] == 0 then
  142.                 command.handlers[text] = nil
  143.             end
  144.         end
  145.     end
  146. end
  147. function command.handle(text, player, args)
  148.     if command.handlers[text] ~= nil then
  149.         for i, handler in ipairs(command.handlers[text]) do
  150.             handler(player, unpack(args))
  151.         end
  152.     end
  153. end
  154. function string.split(str, s)
  155.     local res = {};
  156.     for part in string.gmatch(str, "[^" .. s .. "]+") do
  157.         table.insert(res, part)
  158.     end
  159.     return res;
  160. end
  161. function unpack (t, i)
  162.     i = i or 1
  163.     if t[i] ~= nil then
  164.         return t[i], unpack(t, i + 1)
  165.     end
  166. end
  167. main();
  168.  
  169. function eventChatCommand(playerName, command)
  170.   if command=="help" then
  171.     ui.addPopup(2,0,"Привет! Это новая мини-игра, управляй облаками(кнопка вниз), первый дойди до норы вместе с сыром!",playerName,220,180,360);
  172.   end
  173. end
  174.  
  175. function eventPlayerWon(playerName)
  176. tfm.exec.newGame(maps[math.random(#maps)])
  177.         ui.addTextArea(1,"<J>"..playerName.."<N> выиграл!",NIL,10,30)
  178.  
  179. tfm.exec.newGame(maps[math.random(#maps)])
  180.  
  181. function
  182. tfm.exec.playerVictory(playerName)
  183.    
  184. tfm.exec.killPlayer(playerName)
  185. end
  186. end
  187.  
  188. tfm.exec.newGame(maps[math.random(#maps)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement