Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.28 KB | None | 0 0
  1. isRoom = tfm.get.room.name:find("#")~=nil
  2. roomAdmin,winners = "",{}
  3. isRunning = false
  4.  
  5. do
  6.     local chat,txtarea = tfm.exec.chatMessage,ui.addTextArea
  7.     tfm.exec.chatMessage = function(...)
  8.         if isRoom then
  9.             chat(...)
  10.         end
  11.     end
  12.     ui.addTextArea = function(...)
  13.         if not isRoom or ({...})[1]==3 or ({...})[1]==4 then
  14.             txtarea(...)
  15.         end
  16.     end
  17. end
  18.  
  19. for k,v in next,{"AutoShaman","AutoNewGame","AutoTimeLeft","AutoScore","AfkDeath","MortCommand","DebugCommand"} do
  20.     tfm.exec["disable"..v]()
  21. end
  22.  
  23. table.random=function(t)
  24.     return (type(t)=="table" and t[math.random(#t)] or math.random())
  25. end
  26. system.rank=function(players,lim)
  27.     local p,rank = {},""
  28.     lim = tonumber(lim) or 100
  29.     for m,n in next,players do
  30.         p[#p+1] = {name=n[1],v=n[2]+tfm.get.room.playerList[n[1]].score}
  31.     end
  32.     table.sort(p,function(f,s) return f.v>s.v end)
  33.     for o,n in next,p do
  34.         if o <= lim then
  35.             rank = rank .. "<J>"..o..". <V>" .. n.name .. " <BL>- <VP>" .. n.v .. "x <BL>- <CS>" .. tfm.get.room.playerList[n.name].score .. "x\n"
  36.         end
  37.     end
  38.     return rank
  39. end
  40.  
  41. eventNewPlayer = function(n)
  42.     tfm.exec.chatMessage("<J>Welcome to <VP><B>#presents</B><J>! Choose a gap according to the gift represented and good luck! You will win if your three-gifts-sequence is correct!\n\n<CE>Developed by Bolodefchoco and projected by Ruamorangos",n)
  43.     if isRunning then
  44.         ui.addTextArea(2,"<font size='20'>You will appear in the next sortition!",n,216,65,365,35,1,1,1,true)
  45.         tfm.exec.chatMessage("<VP>You will appear in the next sortition!",n)
  46.     else
  47.         tfm.exec.respawnPlayer(n)
  48.         updateTextAreas()
  49.     end
  50. end
  51.  
  52. choice = {15,true}
  53. block = {5,false}
  54. newMap = {10,false}
  55. currentGift = 1
  56. total = 1
  57. eventNewGame = function()
  58.     if isRunning then
  59.         for i,x in next,{250,400,550} do
  60.             tfm.exec.addPhysicObject(i,x,75,{
  61.                 type = 12,
  62.                 height = 90,
  63.                 width = 90,
  64.                 miceCollision = false,
  65.                 groundCollision = false,
  66.                 color = 0x6A7495
  67.             })
  68.         end
  69.         for i = 0,1 do
  70.             ui.removeTextArea(i)
  71.         end
  72.         choice = {15,true}
  73.         block = {5,false}
  74.         newMap = {10,false}
  75.         currentGift = 1
  76.     else
  77.         updateTextAreas()
  78.     end
  79.     tfm.exec.setGameTime(1e7)
  80. end
  81.  
  82. eventTextAreaCallback = function(i,n,c)
  83.     if n == roomAdmin and c == "new" and time>4 then
  84.         ui.addPopup(0,2,"<p align='center'>Inform the amount of sortitions are going to be done",roomAdmin,217,157,366,true)
  85.     end
  86. end
  87.  
  88. eventPopupAnswer = function(i,n,a)
  89.     a = tonumber(a)
  90.     if a then
  91.         total = (a<1 and 1 or a>15 and 15 or a) or 1
  92.         tfm.exec.chatMessage("<R>"..total.." sortitions are going to be done!")
  93.         newGame()
  94.         cleanTextArea()
  95.     else
  96.         eventTextAreaCallback(nil,roomAdmin,"new")
  97.     end
  98. end
  99.  
  100. string.nick = function(player)
  101.     return player:lower():gsub('%a',string.upper,1)
  102. end
  103.  
  104. cleanTextArea = function()
  105.     for i = 0,4 do
  106.         ui.removeTextArea(i,nil)
  107.     end
  108. end
  109.  
  110. updateTextAreas = function()
  111.     cleanTextArea()
  112.     ui.addTextArea(3,"<p align='center'><J><B><font size='14'><a href='event:new'>New Sortition</a>",roomAdmin,5,25,120,21,1,1,1,true)
  113.     ui.addTextArea(4,"<p align='center'><font size='15'><V><B>LEADERBOARD</B></p></font><R>____________________<p align='left'><font size='12'><N>\n\n<BV>"..system.rank(winners,20),nil,275,40,250,340,1,1,1,true)
  114. end
  115.  
  116. kill = function()
  117.     local gift = gifts[currentGift] - 2099
  118.     for k,v in next,tfm.get.room.playerList do
  119.         if not v.isDead then
  120.             if v.x >= (gift * 120) and v.x <= (gift * 120 + 80) and v.y > 267 then
  121.                 tfm.exec.setPlayerScore(k,1,true)
  122.             else
  123.                 tfm.exec.killPlayer(k)
  124.             end
  125.         end
  126.     end
  127. end
  128.  
  129. newGame = function()
  130.     isRunning = true
  131.     gifts = {
  132.         [1] = table.random({2104,2102,2100,2101,2103,2100,2104,2102,2103,2101,2104,2102,2100,2101,2103,2100,2104,2102,2103,2101,2104,2102,2100,2101,2103,2100,2104,2102,2103,2101}),
  133.         [2] = table.random({2102,2100,2101,2103,2100,2104,2102,2103,2101,2104,2102,2100,2101,2103,2100,2104,2102,2103,2101,2104,2102,2100,2101,2103,2100,2104,2102,2103,2101,2104}),
  134.         [3] = table.random({2100,2101,2103,2100,2104,2102,2103,2101,2104,2102,2100,2101,2103,2100,2104,2102,2103,2101,2104,2102,2100,2101,2103,2100,2104,2102,2103,2101,2104,2102})
  135.     }
  136.     tfm.exec.newGame('<C><P DS="m;250,120,400,120,550,120" D="x_transformice/x_inventaire/'..gifts[1]..'.jpg,230,60;x_transformice/x_inventaire/'..gifts[2]..'.jpg,380,60;x_transformice/x_inventaire/'..gifts[3]..'.jpg,530,60;x_transformice/x_inventaire/2100.jpg,140,320;x_transformice/x_inventaire/2101.jpg,260,320;x_transformice/x_inventaire/2102.jpg,380,320;x_transformice/x_inventaire/2103.jpg,500,320;x_transformice/x_inventaire/2104.jpg,620,320" /><Z><S><S P="1,0.0001,20,0.2,90,1,0,0" H="700" L="15" X="400" c="3" Y="161" T="4" /><S X="100" P="0,0,20,0.2,0,0,0,0" L="40" H="135" c="3" Y="335" T="4" /><S H="135" P="0,0,20,0.2,0,0,0,0" L="40" X="220" c="3" Y="335" T="4" /><S X="340" P="0,0,20,0.2,0,0,0,0" L="40" H="135" c="3" Y="335" T="4" /><S H="135" P="0,0,20,0.2,0,0,0,0" L="40" X="460" c="3" Y="335" T="4" /><S X="580" P="0,0,20,0.2,0,0,0,0" L="40" H="135" c="3" Y="335" T="4" /><S H="40" P="0,0,0.3,0.2,0,0,0,0" L="40" X="100" c="3" Y="160" T="0" /><S X="700" P="0,0,0.3,0.2,0,0,0,0" L="40" H="40" c="3" Y="160" T="0" /><S X="550" P="0,0,0.3,0.2,0,0,0,0" L="40" H="40" c="3" Y="160" T="0" /><S X="400" P="0,0,0.3,0.2,0,0,0,0" L="40" H="40" c="3" Y="160" T="0" /><S X="250" P="0,0,0.3,0.2,0,0,0,0" L="40" H="40" c="3" Y="160" T="0" /><S H="20" P="0,0,0.3,0.2,0,0,0,0" L="800" X="400" Y="10" T="0" /><S H="135" P="0,0,20,0.2,0,0,0,0" L="40" X="700" c="3" Y="335" T="4" /><S X="400" P="0,0,0.3,0.2,0,0,0,0" L="800" H="100" c="3" Y="415" T="0" /><S P="0,0,0.3,0.2,0,0,0,0" H="10" L="50" o="324650" X="745" c="3" Y="138" T="13" /><S X="55" P="0,0,0.3,0.2,0,0,0,0" L="50" o="324650" H="10" c="3" Y="138" T="13" /><S P="0,0,0.3,0.2,0,0,0,0" H="140" L="100" o="324650" X="55" c="3" Y="72" T="12" /><S X="745" P="0,0,0.3,0.2,0,0,0,0" L="100" o="324650" H="140" c="3" Y="72" T="12" /><S P="0,0,0,0,0,0,0,0" H="102" L="581" o="6a7495" X="401" c="4" v="3001" Y="78" T="12" /></S><D /><O /><L><JR M2="10" M1="0" /></L></Z></C>')
  137. end
  138.  
  139. players = function()
  140.     local p = {}
  141.     for k,v in next,tfm.get.room.playerList do
  142.         if not v.isDead then
  143.             p[#p + 1] = k
  144.         end
  145.     end
  146.     return p
  147. end
  148.  
  149. victory = function(none)
  150.     if choice[2] then
  151.         local winner = "%s %s%s!"
  152.         if none or #players() == 0 then
  153.             winner = winner:format("","","Nobody won")
  154.             tfm.exec.chatMessage("<J>Nobody won")
  155.         else
  156.             winner = winner:format(table.concat(players(),", "),"%s","won")
  157.             for k,v in next,players() do
  158.                 tfm.exec.chatMessage("<G>"..v.." <J>won!")
  159.                 local found = {false,0}
  160.                 for i,j in next,winners do
  161.                     if j[1] == v then
  162.                         found = {true,i}
  163.                         break
  164.                     end
  165.                 end
  166.                 if found[1] then
  167.                     winners[found[2]][2] = winners[found[2]][2] + 1
  168.                 else
  169.                     winners[#winners + 1] = {v,1}
  170.                 end
  171.             end
  172.         end
  173.         ui.addTextArea(0,"<B><p align='center'><font size='22' color='#1'>".. winner:format(""),nil,0,222,800,h,1,1,0,true)
  174.         ui.addTextArea(1,"<B><p align='center'><font size='22'><V>".. winner:format("<J>"),nil,0,220,800,h,1,1,0,true)
  175.         newMap[2] = true
  176.     end
  177. end
  178.  
  179. def = function()
  180.     total = total - 1
  181.     if isRoom and total == 0 then
  182.         isRunning = false
  183.         tfm.exec.newGame('<C><P DS="y;315" /><Z><S><S P=",,.3,.2,,,," H="100" L="800" X="400" Y="380" T="0" /></S><D /><O /></Z></C>')
  184.     else
  185.         newGame()
  186.     end
  187. end
  188.  
  189. eventLoop = function(time)
  190.     _G.time = (time/1000)
  191.     local mapName = "<N>Rivals : <V>"..#players()
  192.     if not isRunning then
  193.         mapName = "<N>Mice : <V>"..#players().."   <G>|   <a:active>"..roomAdmin.." is the controler!"
  194.     end
  195.     if _G.time > 4 and isRunning then
  196.         if choice[2] then
  197.             mapName = "<N>Rivals : <V>"..#players().."   <G>|   <J>Choose a gift in less than <PT>"..math.floor(choice[1]).."<J> seconds!"
  198.             choice[1] = choice[1] - .5
  199.             if choice[1] <= 0 then
  200.                 choice = {15,false}
  201.                 block[2] = true
  202.             end
  203.         end
  204.         if block[2] then
  205.             mapName = "<N>Rivals : <V>"..#players().."   <G>|   <R>Those who are out of the correct gift will be dead!"
  206.             block[1] = block[1] - .5
  207.             tfm.exec.addPhysicObject(4,400,270,{
  208.                 type = 4,
  209.                 height = 10,
  210.                 width = 640,
  211.                 miceCollision = true,
  212.                 groundCollision = false
  213.             })
  214.             tfm.exec.removePhysicObject(currentGift)
  215.             if block[1] == 2 then
  216.                 kill()
  217.             end
  218.             if block[1] <= 0 then
  219.                 currentGift = currentGift + 1
  220.                 block = {5,false}
  221.                 choice[2] = true
  222.                 if currentGift == 4 then
  223.                     victory()
  224.                     choice[2] = false
  225.                 end
  226.             end
  227.         else
  228.             tfm.exec.removePhysicObject(4)
  229.         end
  230.         if newMap[2] then
  231.             if isRoom and total < 2 then
  232.                 mapName = "<PS>Sortition ending in <PT>"..math.floor(newMap[1]).."<PS> seconds!"
  233.             else
  234.                 mapName = "<PS>New sortition in <PT>"..math.floor(newMap[1]).."<PS> seconds!"
  235.             end
  236.             newMap[1] = newMap[1] - .5
  237.             if newMap[1] <= 0 then
  238.                 def()
  239.             end
  240.         end
  241.         if #players() == 0 then
  242.             victory(true)
  243.             newMap[2] = true
  244.             choice[2] = false
  245.         end
  246.     end
  247.     ui.setMapName(mapName.."<")
  248. end
  249.  
  250. eventChatCommand = function(n,c)
  251.     if n == roomAdmin and not isRunning then
  252.         if c:sub(1,1) == "c" then
  253.             c = string.nick(c:sub(3))
  254.             if tfm.get.room.playerList[c] then
  255.                 roomAdmin = c
  256.                 ui.removeTextArea(3,n)
  257.                 updateTextAreas()
  258.                 tfm.exec.chatMessage("<ROSE>"..roomAdmin.." is the new controler!")
  259.             end
  260.         end
  261.     end
  262. end
  263.  
  264. for n in next,tfm.get.room.playerList do
  265.     if isRoom and roomAdmin == "" then
  266.         roomAdmin = n
  267.     end
  268. end
  269. def()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement