Advertisement
Patosho

aieSurvivor (example script)

Dec 18th, 2015
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.61 KB | None | 0 0
  1. defaultLanguage = "es"
  2. tribeHouse = true
  3. roundTime = 123
  4.  
  5. local gameFinished = true
  6. local gameStarted
  7. local gameLoaded
  8. local playersInRoom = 0
  9. local playersAlive
  10. local mice = {}
  11. local isAlive = {}
  12.  
  13. --  messageBox by Hina
  14. local ui_msgbox_time = 8000
  15. local ui_msgbox_max = 5
  16. local ui_msgbox_x,ui_msgbox_y,ui_msgbox_w,ui_msgbox_h,ui_msgbox_dy = 100,50,600,20,35
  17. local ui_msgbox_c,ui_msgbox_bc,ui_msgbox_da = nil,nil,0.2
  18. local ui_msgbox_messages = {}
  19.  
  20. maps = {
  21. '<C><P aie="" /><Z><S><S X="400" Y="395" L="800" H="50" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S X="400" Y="200" L="120" H="20" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S X="55" Y="265" L="30" H="150" T="9" P="0,0,,,,0,0,0" /><S X="745" Y="265" L="30" H="150" T="9" P="0,0,,,,0,0,0" /><S X="660" Y="110" L="40" H="20" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S X="140" Y="110" L="40" H="20" T="0" P="0,0,0.3,0.2,0,0,0,0" /></S><D><DC X="400" Y="175" /><DS X="400" Y="359" /></D><O /></Z></C>'
  22. ,
  23. '<C><P aie="" /><Z><S><S X="400" Y="395" L="800" H="50" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S X="400" Y="200" L="120" H="20" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S X="55" Y="265" L="30" H="150" T="9" P="0,0,,,,0,0,0" /><S X="745" Y="265" L="30" H="150" T="9" P="0,0,,,,0,0,0" /><S X="660" Y="110" L="40" H="20" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S X="140" Y="110" L="40" H="20" T="0" P="0,0,0.3,0.2,0,0,0,0" /></S><D><DC X="400" Y="175" /><DS X="400" Y="359" /></D><O /></Z></C>'
  24. }
  25.  
  26. local text = {
  27.     en = {
  28.         shamanVictory = "%s killed all the mice. The Shaman wins!.";
  29.         miceVictory = "%s failed. The mice win!";
  30.         welcome = "<VP>Welcome to aieSurvivor! Have fun!";
  31.     },
  32.     es = {
  33.         shamanVictory = "%s ha matado a todos los ratones. ¡El chamán gana!";
  34.         miceVictory = "%s ha fallado. ¡Los ratones ganan!";
  35.         welcome = "<VP>¡Bienvenid@ a aieSurvivor! ¡Diviértete!";
  36.     }
  37. }
  38.  
  39. _com = tfm.get.room.community
  40.  
  41. function main()
  42.     tfm.exec.disableAutoNewGame()
  43.     tfm.exec.disableAutoTimeLeft()
  44.    
  45.     for n in pairs(tfm.get.room.playerList) do
  46.         eventNewPlayer(n)
  47.     end
  48.    
  49.     startGame()
  50. end
  51.  
  52. function startGame()
  53.     local newMap
  54.     repeat
  55.         newMap = math.random(#maps)
  56.     until newMap ~= currentMap
  57.     currentMap = newMap
  58.     tfm.exec.newGame(maps[newMap])
  59. end
  60.  
  61. function eventNewGame()
  62.     gameLoaded = true
  63.     gameStarted = false
  64.     gameFinished = false
  65.    
  66.     tfm.exec.setGameTime(roundTime)
  67.    
  68.     playersAlive = playersInRoom
  69.     isAlive = {}
  70.     for name,m in pairs(mice) do
  71.         isAlive[name] = true
  72.         if tfm.get.room.playerList[name].isShaman then shaman = name end
  73.     end
  74. end
  75.  
  76. function endGame()
  77.     gameFinished = true
  78.     tfm.exec.setGameTime(5)
  79.    
  80.     if isAlive[shaman] and playersAlive == 1 then
  81.         message(string.format(lang().shamanVictory, shaman), nil)
  82.         for name in pairs(isAlive) do
  83.             if name ~= shaman then tfm.exec.killPlayer(name) end
  84.         end
  85.         tfm.exec.playEmote(shaman, 0)
  86.     else
  87.         message(string.format(lang().miceVictory, shaman), nil)
  88.         for name in pairs(isAlive) do
  89.             if name ~= shaman then
  90.                 tfm.exec.giveCheese(name)
  91.                 tfm.exec.playerVictory(name)
  92.             end
  93.             tfm.exec.playEmote(shaman, 2)
  94.         end
  95.     end
  96. end
  97.  
  98. function eventNewPlayer(name)
  99.     playersInRoom = playersInRoom + 1
  100.     mice[name] = {
  101.     }
  102.     message(lang().welcome, name)
  103. end
  104.  
  105. function eventPlayerLeft(name)
  106.     playersInRoom = playersInRoom - 1
  107.     mice[name] = nil
  108. end
  109.  
  110. function eventPlayerDied(name)
  111.     if gameFinished then return end
  112.    
  113.     playersAlive = playersAlive - 1
  114.     isAlive[name] = nil
  115.    
  116.     if name == shaman or playersAlive == 1 then
  117.         endGame()
  118.     end
  119. end
  120.  
  121. function eventLoop(t,tr)
  122.     if not gameLoaded then return end
  123.    
  124.     for i=1,ui_msgbox_max do
  125.         local m = ui_msgbox_messages[i]
  126.         if m and m.ts + ui_msgbox_time < os.time() then
  127.             ui_msgbox_messages[i] = nil
  128.             ui.removeTextArea(i, nil)
  129.         end
  130.     end
  131.    
  132.     if not gameStarted then
  133.         if t > 3000 then
  134.             gameStarted = true
  135.         end
  136.         return
  137.     end
  138.    
  139.    
  140.    
  141.     if not gameFinished and tr <= 0 then
  142.         endGame()
  143.     elseif gameFinished and tr <= 0 then
  144.         startGame()
  145.     end
  146. end
  147.  
  148. function message(msg, target)
  149.     if tribeHouse then
  150.         showMsg(msg, target)
  151.     else
  152.         tfm.exec.chatMessage(msg, target)
  153.     end
  154. end
  155.  
  156. function lang()
  157.     return text[_com] or text[defaultLanguage]
  158. end
  159.  
  160. --  messageBox by Hina
  161. function showMsg(msg, tgt)
  162.     local box,j
  163.     if ui_msgbox_messages[ui_msgbox_max] then ui_msgbox_messages[ui_msgbox_max] = nil end
  164.     for i=#ui_msgbox_messages+1,1,-1 do
  165.         if i==1 then
  166.             ui_msgbox_messages[i] = {msg=msg, ts=os.time()}
  167.         else
  168.             ui_msgbox_messages[i] = ui_msgbox_messages[i-1]
  169.         end
  170.         j = i - 1
  171.         ui.addTextArea(i, ui_msgbox_messages[i].msg, tgt, ui_msgbox_x, ui_msgbox_y + j*ui_msgbox_dy, ui_msgbox_w, ui_msgbox_h, ui_msgbox_c, ui_msgbox_bc, 1 - j*ui_msgbox_da, true)
  172.     end
  173. end
  174.  
  175. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement