TheLeetCoder

#Iced. by Mousechris edited by TheLeetCoder.

Oct 27th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. function f(txt) -- just for readability
  2.     return string.format([[<font color="#89A7F5">%s</font>]], txt)
  3. end
  4.  
  5. local welcome = string.format("<N>Hello there! %s is an unofficial minigame that can currently only be played in the tribe house. Please support %s!", f("#Iced"), f("#Iced"))
  6. print(welcome) -- why though?
  7.  
  8. maps = { 4446887 }
  9. players = {}
  10.  
  11. function getMouseCount()
  12.     local count = 0
  13.     for p in pairs(tfm.get.room.playerList) do
  14.         if not tfm.get.room.playerList[p].isDead or players[p].id then
  15.             count = count + 1
  16.         end
  17.     end
  18.     return count
  19. end
  20.  
  21. function eventLoop(time,remaining)
  22.     local n = getMouseCount()
  23.     if remaining <= 0 or n == 0 then
  24.         newRound()
  25.     end
  26. end
  27.  
  28. function newRound()
  29.     tfm.exec.newGame(maps[math.random(#maps)])
  30. end
  31.  
  32. function eventNewGame()
  33.     tfm.exec.snow()
  34.     tfm.exec.setUIMapName(string.format("<N>Welcome to %s! Press %s to turn into an Ice Cube! Press %s to turn into an Ice Plank! Have fun! \n", f("#Iced"), f("Z"), f("X")))
  35.     for player in pairs(tfm.get.room.playerList) do
  36.         if player.isIced then
  37.             player.isIced = false
  38.         end
  39.     end
  40. end
  41.  
  42. function eventNewPlayer(name)
  43.     ui.addTextArea(1, string.format("<p align='center'><b>%s</b></p>", welcome), name, 5, 25, 790, 25, nil, nil, 0)
  44.     tfm.exec.bindKeyboard(name, 87, true, true)
  45.     tfm.exec.bindKeyboard(name, 88, true, true)
  46.     players[name] = { timestamp = os.time(), isIced = false }
  47. end
  48.  
  49. function eventKeyboard(name,key,down,x,y)
  50.     local p = players[name]
  51.     if p.timestamp < os.time() - 800 then
  52.         if not p.isIced then
  53.             p.isIced = true -- player is now iced.
  54.             tfm.exec.movePlayer(name, 400, -520, false, 0, 0, false) -- For avoid dead spamming.
  55.             local id = tfm.exec.addShamanObject((key == 87 and 54 or 45), x, y)
  56.             p.id = id
  57.         elseif p.id then
  58.             local x_ = tfm.get.room.objectList[p.id].x
  59.             if x_ == 0 then
  60.                 tfm.exec.killPlayer(name)
  61.             else
  62.                 p.isIced = false
  63.                 tfm.exec.movePlayer(name, x_, tfm.get.room.objectList[p.id].y)
  64.             end
  65.             tfm.exec.removeObject(p.id)
  66.             p.id = nil
  67.         end
  68.         p.timestamp = os.time()
  69.     end
  70. end
  71.  
  72.  
  73. function main()
  74.     tfm.exec.disableAutoNewGame(true)
  75.     tfm.exec.disableAutoTimeLeft(true)
  76.     tfm.exec.disableAutoShaman(true)
  77.     tfm.exec.newGame(maps[math.random(#maps)])
  78.     for name,player in pairs(tfm.get.room.playerList) do
  79.         eventNewPlayer(name)
  80.     end
  81. end
  82.  
  83. main()
  84.  
  85. function eventPlayerWon(name)
  86.     players[name].id = nil
  87. end
  88.  
  89. function eventPlayerGetCheese(name)
  90.     tfm.exec.playerVictory(name)
  91. end
  92.  
  93. function eventChatCommand(name, command)
  94.     if command == "np" then
  95.         tfm.exec.newGame(maps[math.random(#maps)])
  96.     elseif command == "die" or command == "mort" or command == "kill" then
  97.         tfm.exec.killPlayer(name)
  98.     end
  99. end
Advertisement
Add Comment
Please, Sign In to add comment