Advertisement
Guest User

Untitled

a guest
Dec 18th, 2019
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.03 KB | None | 0 0
  1. admin = "Owl#3124"
  2.  
  3. tfm.exec.disableAutoScore(true)
  4. tfm.exec.disableAutoShaman(true)
  5. tfm.exec.disableAutoTimeLeft(true)
  6. tfm.exec.disableAutoNewGame(true)
  7. tfm.exec.newGame("#10",false)
  8.  
  9. playerShoot = {}
  10. playerOffset = {}
  11. teamRed = {}
  12. teamBlue = {}
  13. objectList = {}
  14. validObjectId = {0,1,2,3,4,6,7,10,17,23,26,27,28,29,30,31,32,33,34,35,39,40,45,46,54,57,59,60,61,62,65,67,68,69,80,85,89,90,95}
  15. doom = 0
  16. objectid = 0
  17. team = 0
  18. win = 0
  19. round = 0
  20. starttimer = 0
  21. updatesecond = 0
  22. spawndelay = true
  23. customObject = false
  24. customObjectId = -1
  25. garbage = false
  26. teamOnly = false
  27.  
  28. for name,player in pairs(tfm.get.room.playerList) do
  29.     playerOffset[name] = {}
  30.     playerOffset[name]["xOff"] = 20
  31.     playerOffset[name]["yOff"] = 0
  32. end
  33.  
  34. function try(f, catch_f)
  35.     local status, exception = pcall(f)
  36.     if not status then
  37.     catch_f(exception)
  38.     end
  39. end
  40.  
  41. function splitString(inputstr, sep)
  42.     if sep == nil then
  43.             sep = "%s"
  44.     end
  45.     local t={} ; i=1
  46.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  47.             t[i] = str
  48.             i = i + 1
  49.     end
  50.     return t
  51. end
  52.  
  53. function spairs(t, order)
  54.     local keys = {}
  55.     for k in pairs(t) do keys[#keys+1] = k end
  56.     if order then
  57.         table.sort(keys, function(a,b) return order(t, a, b) end)
  58.     else
  59.         table.sort(keys)
  60.     end
  61.     local i = 0
  62.     return function()
  63.         i = i + 1
  64.         if keys[i] then
  65.             return keys[i], t[keys[i]]
  66.         end
  67.     end
  68. end
  69.  
  70. function eventMouse(name,mx,my)
  71.     alive = tfm.get.room.playerList[name].isDead
  72.     if alive ~= true and win ~= 1 then
  73.         if playerShoot[name] == 2 or spawndelay == false then
  74.             local px,py,xpeed,yspeed,addx;
  75.  
  76.             px = tfm.get.room.playerList[name].x
  77.             py = tfm.get.room.playerList[name].y
  78.  
  79.             if mx > px then
  80.                 addx = playerOffset[name]['xOff']
  81.             else
  82.                 addx = 0-(playerOffset[name]['xOff'])
  83.             end
  84.  
  85.             if my > py then
  86.                 addy = playerOffset[name]['yOff']
  87.             else
  88.                 addy = 0-(playerOffset[name]['yOff'])
  89.             end
  90.  
  91.             if doom == 1 then
  92.                 xspeed = (mx-px)/12
  93.                 yspeed = (my-py)/10
  94.             else
  95.                 if objectid ~= 10 then
  96.                     xspeed = (mx-px)/10
  97.                     yspeed = (my-py)/10
  98.                 else
  99.                     xspeed = (mx-px)/18
  100.                     yspeed = (my-py)/16
  101.                 end
  102.             end
  103.  
  104.             objectDesc = {}
  105.             objectDesc['timer'] = 0
  106.             if customObjectId == "random" and objectid ~= -1 then
  107.                 local objectIdTemp = math.random(1, #validObjectId )
  108.                 objectDesc['objectId'] = tfm.exec.addShamanObject(validObjectId[objectIdTemp], px+addx, py+addy, ang, xspeed, yspeed, false)
  109.             else
  110.                 objectDesc['objectId'] = tfm.exec.addShamanObject(objectid, px+addx, py+addy, ang, xspeed, yspeed, false)
  111.             end
  112.             if garbage ~= true then
  113.                 table.insert(objectList, objectDesc)
  114.             end
  115.             playerShoot[name] = 0
  116.         end
  117.     end
  118. end
  119.  
  120. function eventLoop(spent,remain)
  121.     local ind = 1
  122.     for i=1,#objectList do
  123.         if objectList[ind].timer == 2 then
  124.             tfm.exec.removeObject ( objectList[ind].objectId )
  125.             table.remove( objectList, ind )
  126.         else
  127.             objectList[ind].timer = objectList[ind].timer+1
  128.             ind = ind+1
  129.         end
  130.     end
  131.  
  132.     try(function()
  133.         for name,player in pairs(tfm.get.room.playerList) do
  134.             if playerShoot[name] < 2 then
  135.                 playerShoot[name] = playerShoot[name]+1
  136.             end
  137.         end
  138.     end,function(e) end)
  139.  
  140.     if spent > 83000 or remain <= 0 then
  141.         if win == 0 then
  142.             if team == 1 then
  143.                 local redAlive = 0
  144.                 local blueAlive = 0
  145.                 for i=1,#teamRed,1 do
  146.                     try(function()
  147.                         if tfm.get.room.playerList[teamRed[i]].isDead == false then
  148.                             redAlive = redAlive+1
  149.                         end
  150.                     end,function(e) print (e) end)
  151.                 end
  152.                 for i=1,#teamBlue,1 do
  153.                     try(function()
  154.                         if tfm.get.room.playerList[teamBlue[i]].isDead == false then
  155.                             blueAlive = blueAlive+1
  156.                         end
  157.                     end,function(e)  print (e)  end)
  158.                 end
  159.                 if redAlive > blueAlive then
  160.                     print ("Red Win (Most Player Survived)")
  161.                     tfm.exec.setGameTime(10,true)
  162.                     win = 1
  163.                     for i=1,#teamRed,1 do
  164.                         try(function()
  165.                             if tfm.get.room.playerList[teamRed[1]].isDead ~= true then
  166.                                 tfm.exec.setPlayerScore(teamRed[1],2,true)
  167.                             else
  168.                                 tfm.exec.setPlayerScore(teamRed[1],1,true)
  169.                             end
  170.                         end,function(e)  print (e)  end)
  171.                         table.remove(teamRed,1)
  172.                     end
  173.                 elseif blueAlive > redAlive then
  174.                     print ("Blue Win (Most Player Survived)")
  175.                     tfm.exec.setGameTime(10,true)
  176.                     win = 1
  177.                     for i=1,#teamBlue,1 do
  178.                         try(function()
  179.                             if tfm.get.room.playerList[teamBlue[1]].isDead ~= true then
  180.                                 tfm.exec.setPlayerScore(teamBlue[1],2,true)
  181.                             else
  182.                                 tfm.exec.setPlayerScore(teamBlue[1],1,true)
  183.                             end
  184.                         end,function(e)  print (e)  end)
  185.                         table.remove(teamBlue,1)
  186.                     end
  187.                 else
  188.                     print ("Round Draw (All alive players got 1 score")
  189.                     for i=1,#teamRed,1 do
  190.                         try(function()
  191.                             tfm.exec.setPlayerScore(teamRed[1],1,true)
  192.                         end,function(e)  print (e)  end)
  193.                         table.remove(teamRed,1)
  194.                     end
  195.                     for i=1,#teamBlue,1 do
  196.                         try(function()
  197.                             tfm.exec.setPlayerScore(teamBlue[1],1,true)
  198.                         end,function(e)  print (e)  end)
  199.                         table.remove(teamBlue,1)
  200.                     end
  201.                 end
  202.             else
  203.                 for name,player in pairs(tfm.get.room.playerList) do
  204.                     if(tfm.get.room.playerList[name].isDead == false) then
  205.                         tfm.exec.setPlayerScore(name,2,true)
  206.                     end
  207.                 end
  208.             end
  209.         end
  210.  
  211.         tfm.exec.newGame("#10",false)
  212.     end
  213.     if spent > 3000 and spent < 4000 then
  214.         tfm.exec.killPlayer("Bot#1618")
  215.         ui.removeTextArea(1,nil)
  216.     end
  217.  
  218.     if spent < 6000 then
  219.         updatesecond = updatesecond + 0.5
  220.         if spent > 3000 and updatesecond >= 1 then
  221.             ui.addTextArea(2,starttimer,nil,600,375,0,0)    
  222.             starttimer = starttimer - 1
  223.             updatesecond = 0
  224.         end
  225.         objectid = -1
  226.     elseif spent < 23000 then
  227.         ui.removeTextArea(2,nil)
  228.         if customObject then
  229.             if customObjectId == "random" then
  230.                 local rand = math.random(1,#validObjectId)
  231.                 objectid = validObjectId[rand]
  232.             else
  233.                 objectid = customObjectId
  234.             end
  235.         else
  236.             objectid = 65
  237.         end
  238.     elseif spent < 43000 then
  239.         if customObject then
  240.             if customObjectId == "random" then
  241.                 local rand = math.random(1,#validObjectId)
  242.                 objectid = validObjectId[rand]
  243.             else
  244.                 objectid = customObjectId
  245.             end
  246.             doom = 1
  247.         else
  248.             objectid = 6
  249.         end
  250.     elseif spent < 63000 then
  251.         if customObject then
  252.             if customObjectId == "random" then
  253.                 local rand = math.random(1,#validObjectId)
  254.                 objectid = validObjectId[rand]
  255.             else
  256.                 objectid = customObjectId
  257.             end
  258.             doom = 1
  259.         else
  260.             objectid = 10
  261.         end
  262.     elseif spent < 83000 then
  263.         doom = 1
  264.     end
  265. end
  266.  
  267. function eventChatCommand (name,command)
  268.     local cP = {}
  269.     for param in command:gmatch("[^%s]+") do
  270.         table.insert(cP, param)
  271.     end
  272.  
  273.     if name == admin then
  274.         if command == "skip" then
  275.             tfm.exec.newGame("#10",false)
  276.         elseif command == "spawn" then
  277.             tfm.exec.respawnPlayer(name)
  278.         elseif command == "restart" then
  279.             for name,player in pairs(tfm.get.room.playerList) do
  280.                 tfm.exec.setPlayerScore(name,0,false)
  281.             end
  282.             round = 0
  283.             tfm.exec.newGame("#10",false)
  284.         elseif cP[1] == "anvilonly" then
  285.             if customObject and customObjectId ~= -1 then
  286.                 customObject = false
  287.                 customObjectId = -1
  288.             else
  289.                 customObject = true
  290.                 customObjectId = 10
  291.             end
  292.         elseif cP[1] == "object" then
  293.             if customObject and #cP == 1 then
  294.                 customObject = false
  295.                 customObjectId = -1
  296.             else
  297.                 if cP[2] == "random" then
  298.                     customObject = true
  299.                     customObjectId = "random"
  300.                 else
  301.                     if not tonumber(cP[2])then
  302.                         ui.addPopup(9,0,"Error!",name,300, 300,200, false)
  303.                     else
  304.                         customObject = true
  305.                         customObjectId = cP[2]
  306.                     end
  307.                 end
  308.             end
  309.  
  310.         elseif command == "spawndelay" then
  311.             spawndelay = !spawndelay
  312.  
  313.         elseif command == "garbage" then
  314.                 garbage = !garbage
  315.                
  316.         elseif command == "teamonly" then
  317.             teamOnly = !teamOnly
  318.  
  319.         end
  320.     end
  321.  
  322.     if cP[1] == "off" then
  323.         if not tonumber(cP[2]) or not tonumber(cP[3]) then
  324.             ui.addPopup(9,0,"Error!",name,300, 300,200, false)
  325.         else
  326.             if tonumber(cP[2]) <= 20 and tonumber(cP[2]) >= -20 and tonumber(cP[3]) <= 20 and tonumber(cP[3]) >= -20 then
  327.                 playerOffset[name]["xOff"] = tonumber(cP[2])
  328.                 playerOffset[name]["yOff"] = tonumber(cP[3])
  329.                 ui.addPopup(9,0,"Spawn offset set to \n x="..cP[2].."\n y="..cP[3],name,300, 300,200, false)
  330.             else
  331.                 ui.addPopup(9,0,"Offset can't be smaller than -20 or greater than 20",name, 300, 300,200, false)
  332.             end
  333.         end
  334.     end
  335. end
  336.  
  337. function eventNewPlayer(name)
  338.     playerOffset[name] = {}
  339.     playerOffset[name]["xOff"] = 20
  340.     playerOffset[name]["yOff"] = 0
  341.     playerShoot[name] = 0
  342. end
  343.  
  344. function eventNewGame()
  345.     if round == 10 then
  346.         local playerScore = {}
  347.         local winner = "nil"
  348.         for name,player in pairs(tfm.get.room.playerList) do
  349.             playerScore[name] = tfm.get.room.playerList[name].score
  350.         end
  351.         for name,score in spairs(playerScore, function(t,a,b) return t[b] < t[a] end) do
  352.             winner = name
  353.             break
  354.         end
  355.         for name,player in pairs(tfm.get.room.playerList) do
  356.             ui.addPopup(9,0,winner .. " won the game!",name,500,300,200,false)
  357.             tfm.exec.setPlayerScore(name,0,false)
  358.         end
  359.         round = 0
  360.     end
  361.  
  362.     round = round + 1
  363.     ui.setMapName("BFM! [Round "..round.."/10]")
  364.     starttimer = 3
  365.     doom = 0
  366.     team = 0
  367.     win = 0
  368.     playerShoot = {}
  369.     teamRed = {}
  370.     teamBlue = {}
  371.     for name,player in pairs(tfm.get.room.playerList) do
  372.         playerShoot[name] = 0
  373.         tfm.exec.giveMeep(name,true)
  374.         system.bindMouse(name,true)
  375.         system.bindKeyboard(name,32,true,true)
  376.         tfm.exec.setNameColor(name,0)
  377.     end
  378.  
  379.     if math.random(1,4) == 1 or teamOnly then
  380.         team = 1
  381.         local playerList={}
  382.         for name,player in pairs(tfm.get.room.playerList) do
  383.             if name ~= "Bot#1618" then
  384.                 table.insert(playerList,name)
  385.             end
  386.         end
  387.         for i=1,#playerList,1 do
  388.             local index=math.random(#playerList)
  389.             local name=playerList[index]
  390.             if i%2==0 then
  391.                 tfm.exec.setNameColor(name,0xff3300)
  392.                 ui.addPopup(1,0,"You are on TEAM RED, eleminate TEAM BLUE!",name,300,200,200,false)
  393.                 table.insert(teamRed,name)
  394.             else
  395.                 tfm.exec.setNameColor(name,0x0066ff)
  396.                 ui.addPopup(1,0,"You are on TEAM BLUE, eleminate TEAM RED!",name,300,200,200,false)
  397.                 table.insert(teamBlue,name)
  398.             end
  399.             table.remove(playerList,index)
  400.         end
  401.     end
  402.     tfm.exec.setGameTime(86,true)
  403. end
  404.  
  405. function eventPlayerMeep(name,px,py)
  406.     local facing = tfm.get.room.playerList[name].isFacingRight
  407.     local xspeed,yspeed,addx;
  408.  
  409.     if facing then
  410.         addx = playerOffset[name]["xOff"]
  411.     else
  412.         addx = 0-(playerOffset[name]["xOff"])
  413.     end
  414.    
  415.     if objectid == 65 then
  416.         xspeed = 65
  417.     elseif objectid == 6 then
  418.         xspeed = 45
  419.     elseif objectid == 10 then
  420.         xspeed = 25
  421.     else
  422.         xspeed = 50
  423.     end
  424.  
  425.     if doom == 1 then
  426.         xspeed = xspeed*2
  427.     end
  428.  
  429.     if facing == false then
  430.         xspeed = xspeed-(xspeed*2)
  431.     end
  432.  
  433.     objectDesc = {}
  434.     objectDesc['timer'] = 0        
  435.     objectDesc['objectId'] = tfm.exec.addShamanObject(objectid, px+addx, py-25, ang, xspeed, 2, false)
  436.     table.insert( objectList, objectDesc )
  437.     objectDesc['objectId'] = tfm.exec.addShamanObject(objectid, px+addx, py, ang, xspeed, 2, false)
  438.     table.insert( objectList, objectDesc )
  439.     objectDesc['objectId'] = tfm.exec.addShamanObject(objectid, px+addx, py+25, ang, xspeed, 2, false)
  440. end
  441.  
  442. function eventPlayerDied(nameded)
  443.     if team == 0 then
  444.         local alive = 0
  445.         local winname
  446.         for name,player in pairs(tfm.get.room.playerList) do
  447.             if tfm.get.room.playerList[name].isDead == false then
  448.                 alive = alive+1
  449.                 winname = name
  450.             end
  451.         end
  452.  
  453.         if alive == 1 then
  454.             ui.addTextArea(1,"Winner : " .. winname ,nil,600,375,0)
  455.             print (winname .. " Win")
  456.             tfm.exec.giveMeep(winname,false)
  457.             win = 1
  458.             tfm.exec.setGameTime(10,true)
  459.             tfm.exec.setPlayerScore(winname,3,true)
  460.         end
  461.         if alive == 0 then
  462.             tfm.exec.newGame("#10",false)
  463.         end
  464.     else
  465.         local redAlive = 0
  466.         local blueAlive = 0
  467.         for i=1,#teamRed,1 do
  468.             try(function()
  469.                 if tfm.get.room.playerList[teamRed[i]].isDead == false then
  470.                     redAlive = redAlive+1
  471.                 end
  472.             end,function(e) print (e) end)
  473.         end
  474.         for i=1,#teamBlue,1 do
  475.             try(function()
  476.                 if tfm.get.room.playerList[teamBlue[i]].isDead == false then
  477.                     blueAlive = blueAlive+1
  478.                 end
  479.             end,function(e)  print (e)  end)
  480.         end
  481.  
  482.         if blueAlive == 0 and redAlive ~= 0 then
  483.             print ("Red Win")    
  484.             ui.addTextArea(1,"Winner : Red Team",nil,600,375,0)
  485.             tfm.exec.setGameTime(10,true)
  486.             win = 1
  487.             for i=1,#teamRed,1 do
  488.                 try(function()
  489.                     if tfm.get.room.playerList[teamRed[1]].isDead ~= true then
  490.                         tfm.exec.setPlayerScore(teamRed[1],2,true)
  491.                     else
  492.                         tfm.exec.setPlayerScore(teamRed[1],1,true)
  493.                     end
  494.                     tfm.exec.giveMeep(teamRed[1],false)
  495.                 end,function(e)  print (e)  end)
  496.                 table.remove(teamRed,1)
  497.             end
  498.         end
  499.         if redAlive == 0 and blueAlive ~= 0 then
  500.             print ("Blue Win")
  501.             ui.addTextArea(1,"Winner : Blue Team",nil,600,375,0)
  502.             tfm.exec.setGameTime(10,true)
  503.             win = 1
  504.             for j=1,#teamBlue,1 do
  505.                 try(function()
  506.                     if tfm.get.room.playerList[teamBlue[1]].isDead ~= true then
  507.                         tfm.exec.setPlayerScore(teamBlue[1],2,true)
  508.                     else
  509.                         tfm.exec.setPlayerScore(teamBlue[1],1,true)
  510.                     end
  511.                     tfm.exec.giveMeep(teamBlue[1],false)
  512.                 end,function(e)  print (e) end)
  513.                 table.remove(teamBlue,1)
  514.             end
  515.         end
  516.  
  517.         if redAlive == 0 and blueAlive == 0 then
  518.             tfm.exec.newGame("#10",false)
  519.         end
  520.     end
  521. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement