Advertisement
austin101

Uber Arena

Mar 11th, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 28.68 KB | None | 0 0
  1. PLUGIN.Title = "uberArena"
  2. PLUGIN.Description = "Automated deathmatch Arena"
  3. PLUGIN.Author = "Senorderp"
  4. PLUGIN.Version = "0.6.8b"
  5.  
  6. function PLUGIN:Init()
  7. --Spawns
  8.     self.UArenaSpawnFile = util.GetDatafile("uarenaspawns")
  9.     local json_txt = json.decode(self.UArenaSpawnFile:GetText())
  10.     if not json_txt then
  11.         json_txt = {}
  12.         self.FirstSpawnLoad = true
  13.     end
  14.     self.UArenaSpawn = json_txt
  15. --ArenaLimbo
  16.     self.ArenaLimboFile = util.GetDatafile("arenalimbo")
  17.     local json_txt2 = json.decode(self.ArenaLimboFile:GetText())
  18.     if not json_txt2 then
  19.         json_txt2 = {}
  20.     end
  21.     self.ArenaLimbo = json_txt2
  22. --Config
  23.     local b, res = config.Read("uberarena")
  24.     self.Config = res or {}
  25.     if (not b) then
  26.         self:LoadDefaultConfig()
  27.         config.Save( "uberarena" )
  28.     end
  29.    
  30.     oxmin_Plugin = plugins.Find( "oxmin" )
  31.     if not oxmin_Plugin or not oxmin then
  32.         self.oxminInstalled = false
  33.     else
  34.         self.FLAG_UAControls = oxmin.AddFlag( "canuaconfig" )
  35.         self.oxminInstalled = true
  36.  
  37.     end
  38. --Add commands
  39.     self:AddChatCommand ("jt", self.RequestJoin)
  40.     self:AddChatCommand ("ua", self.UArenaCommands)
  41.     self:AddChatCommand ("uaconfig", self.AdminUArenaCommands)
  42.     self:AddChatCommand ("leaveq", self.LeaveQ)
  43.     self:AddChatCommand ("uastatus", self.UAStatusCommands)
  44. --Tables
  45.     self.Roster = {}
  46.     self.Team = {}
  47.     self.Team[0] = 0
  48.     self.Team[1] = 0
  49.     self.Team[2] = 0
  50.     self.Team[99] = 0
  51. --Config
  52.     if (not(self.Config.RandomTeams)) then
  53.         self.Config.RandomTeams = false
  54.     end
  55.     self.ArenaOn = self.Config.OnByDefault
  56.     self.QueueTime = self.Config.QueueTime
  57.     self.MinPlayer = self.Config.MinPlayer
  58.     self.MaxPlayer = self.Config.MaxPlayer
  59.     self.ArenaAlert = (self.Config.QueueTime - self.Config.AlertTime)
  60.     self.MatchTime = (self.Config.MatchTime + self.Config.QueueTime)
  61.     self.MinPlayerReward = self.Config.MinPlayerReward
  62.     self.Reward = self.Config.Reward
  63.     self.Medkit = self.Config.Medkit
  64.     self.MedkitQuantity = self.Config.MedkitQuantity
  65.     self.BandageQuantity = self.Config.BandageQuantity --can not be greater than 5
  66.     self.WepAttachments = self.Config.WepAttachments
  67.     self.WepAttachQuan = self.Config.WepAttachQuan
  68.     self.Ammo = self.Config.Ammo
  69.     self.AmmoQuantity = self.Config.AmmoQuantity
  70.     self.T1Armor = self.Config.T1Armor
  71.     self.T1Guns = self.Config.T1Guns
  72.     self.T2Armor = self.Config.T2Armor
  73.     self.T2Guns = self.Config.T2Guns
  74.     self.FriendlyFire = self.Config.FriendlyFire
  75.     self.RandomTeams = self.Config.RandomTeams
  76.  
  77. --Globals
  78.     self.PlayerCount = 0
  79.     self.ArenaTock = 0
  80. --Timer
  81.     disqualtimer = 1
  82.     self.ArenaTimer = timer.Repeat(1, 0, function() self:ArenaTick() end )
  83.     if (self.ArenaOn) and (not(self.FirstSpawnLoad)) then
  84.         self.CanQueue = true
  85.     elseif ((self.ArenaOn) and (self.FirstSpawnLoad == true))then
  86.         self.ArenaOn = nil
  87.         print("uberArena: Set your spawnpoints before turning on!")
  88.     end
  89.     print("uberArena version " .. self.Version .. " successfully loaded!")
  90. end
  91.  
  92. function PLUGIN:UArenaDebug(netuser)
  93.     print("ArenaTock: " .. self.ArenaTock)
  94.     print("user: " .. self.Roster[userID])
  95.     print("netuser: " .. self.Roster[userID].UArenaNetUser)
  96.     print("PlayerCount: " .. self.PlayerCount)
  97.  
  98. end
  99.  
  100. function PLUGIN:UArenaConfigPull()
  101.     self.QueueTime = self.Config.QueueTime
  102.     self.MinPlayer = self.Config.MinPlayer
  103.     self.MaxPlayer = self.Config.MaxPlayer
  104.     self.ArenaAlert = (self.Config.QueueTime - self.Config.AlertTime)
  105.     self.MatchTime = (self.Config.MatchTime + self.Config.QueueTime)
  106.     self.MinPlayerReward = self.Config.MinPlayerReward
  107.     self.Reward = self.Config.Reward
  108.     self.FriendlyFire = self.Config.FriendlyFire
  109.     self.RandomTeams = self.Config.RandomTeams
  110. end
  111. function PLUGIN:LoadDefaultConfig()
  112.     self.Config.OnByDefault = true
  113.     self.Config.FriendlyFire = "on"
  114.     self.Config.QueueTime = 60
  115.     self.Config.MinPlayer = 2
  116.     self.Config.MaxPlayer = 8
  117.     self.Config.AlertTime = 20
  118.     self.Config.MatchTime = 300 -- 5 minutes
  119.     self.Config.MinPlayerReward = 4
  120.     self.Config.Reward = {}
  121.     self.Config.Medkit = "Small Medkit"
  122.     self.Config.MedkitQuantity = 3
  123.     self.Config.BandageQuantity = 5 --can not be greater than 5
  124.     self.Config.WepAttachments = {"Flashlight Mod"}
  125.     self.Config.WepAttachQuan = 1
  126.     self.Config.Ammo = {"9mm Ammo", "Handmade Shell", "Arrow", "Flare"}
  127.     self.Config.AmmoQuantity = 50
  128.     self.Config.T1Armor = {"Leather Boots", "Leather Pants", "Leather Vest", "Leather Helmet"}
  129.     self.Config.T1Guns = {"Hunting Bow", "Revolver", "Pipe Shotgun", "Hand Cannon"}
  130.     self.Config.T2Armor = {"Kevlar Boots", "Kevlar Pants", "Rad Suit Vest", "Rad Suit Helmet"}
  131.     self.Config.T2Guns = {"Hunting Bow", "Revolver", "Pipe Shotgun", "Hand Cannon"}
  132.     self.Config.RandomTeams = false
  133. end
  134.  
  135. function PLUGIN:ArenaTick()
  136.     self.ArenaTock = self.ArenaTock + 1
  137.     if (self.ArenaOn) and (self.CanQueue) then
  138.         self:QueueActive(self.ArenaTock, self.PlayerCount)
  139.     return
  140.     elseif (self.ArenaOn) then
  141.         self:MatchActive(self.ArenaTock)
  142.     return
  143.     end
  144. return
  145. end
  146.  
  147. function PLUGIN:QueueActive(Tock, playercount)
  148.     if (Tock == self.ArenaAlert) then
  149.         self:PreMatchWarning()
  150.     return
  151.     elseif (Tock == self.QueueTime) then
  152.         if playercount >= self.MinPlayer then
  153.             self:UABroadcastChat("A new round has begun in the Arena!")
  154.             self.CanQueue = nil
  155.             self:StartMatch ()
  156.         return
  157.         else
  158.             local key = self.MinPlayer - playercount
  159.             self:UABroadcastChat ("There are not enough players to start a match. " .. key .. " more players required!")
  160.             self:UABroadcastChat("type /jt 1 or 2 to queue. Use /leaveq to leave the arena")
  161.             self:UABroadcastChat("***WARNING*** Joining the arena will clear your inventory!")
  162.             self:UABroadcastChat("Please be sure to remove all items + armor before joining the arena")
  163.             self.ArenaTock = 0     
  164.         return
  165.         end
  166.     return
  167.     end
  168. return
  169. end
  170.  
  171. function PLUGIN:MatchActive(Tock)
  172.     if (self.MatchTime <= 0) then
  173.     return
  174.     else
  175.         local timeleft = (self.MatchTime - Tock)
  176.         local matchwarning = self.MatchTime - 15
  177.         if (Tock == matchwarning) then
  178.             for i in pairs(self.Roster) do
  179.                 if (self.Roster[i].Status == "alive") then
  180.                     self:UABroadcastChat ("15 seconds remaining until match ends!")
  181.                 return
  182.                 end
  183.             end
  184.         elseif (Tock == self.MatchTime) then
  185.             for i in pairs(self.Roster) do
  186.                 rust.Notice(self.Roster[i].UArenaNetUser, "Time limit reached! You have FAILED!")
  187.             end
  188.             self:UABroadcastChat("Match ended in a draw! New match begins in " .. self.QueueTime .. " seconds!")
  189.             self:ForceEnd("timelimit")
  190.             self.ArenaTock = 0
  191.             self.CanQueue = true
  192.         return
  193.         end
  194.     return
  195.     end
  196. return
  197. end
  198.  
  199. function PLUGIN:PreMatchWarning()
  200.     if (self.MinPlayer > self.PlayerCount) then
  201.         local players = self.MinPlayer - self.PlayerCount
  202.         self:UABroadcastChat(self.Config.AlertTime.. " seconds before the next match! " .. players .. " players still needed!")
  203.     return
  204.     else
  205.         self:UABroadcastChat(self.PlayerCount .. " players queued! Next match begins in " .. self.Config.AlertTime.. " seconds!")
  206.     return
  207.     end
  208. return
  209. end
  210.  
  211. function PLUGIN:RequestJoin(netuser, cmd, args)
  212.     local userID = rust.GetUserID(netuser)
  213.     local teamrequest = 0
  214.     local msg = "derp"
  215.     if (self.ArenaOn) then
  216.         if (self.PlayerCount > self.MaxPlayer) then
  217.             rust.Notice (netuser, "There are too many players! Try again next match.")
  218.         return
  219.         elseif (self.CanQueue) then
  220.             for i in pairs(self.Roster) do
  221.                 if i == userID then
  222.                     rust.Notice(netuser, "You are already queued!")
  223.                 return
  224.                 end
  225.             end
  226.             if ((args[1] == "1") or (args[1] == "2")) and (self.RandomTeams == false) then
  227.                 teamrequest = tonumber(args[1])
  228.                 local accept = self:TeamBalance(netuser, teamrequest)
  229.                     if accept then
  230.                         self:JoinAccept(netuser, teamrequest)
  231.                     return
  232.                     end
  233.             elseif (self.RandomTeams) then
  234.                 teamrequest = 99
  235.                 self:JoinAccept(netuser, teamrequest)
  236.             return
  237.             elseif (not(args[1] == "1") or not(args[1] == "2")) and (self.RandomTeams == false) then
  238.                 rust.SendChatToUser(netuser, "You must specify a proper team")
  239.             return
  240.             else
  241.             end
  242.         end
  243.     end
  244. end
  245.  
  246. function PLUGIN:JoinAccept(netuser, request)
  247.                 local userID = rust.GetUserID(netuser)
  248.                 local current_coords = netuser.playerClient.lastKnownPosition;
  249.                 local teamjoin = {}
  250.                 teamjoin.Team = request
  251.                 teamjoin.Status = "queued"
  252.                 teamjoin.x = current_coords.x
  253.                 teamjoin.y = current_coords.y
  254.                 teamjoin.z = current_coords.z
  255.                 teamjoin.UArenaNetUser = netuser
  256.                 self.Roster[userID] = teamjoin
  257.                 self.PlayerCount = self.PlayerCount + 1
  258.                 self.Team[request] = self.Team[request] + 1
  259.                 if (request == 99) then
  260.                     msg = "You have joined the queue. You will be placed on a random team at the start of the match!"
  261.                 else
  262.                     msg = "You have successfully joined team " .. self.Roster[userID].Team .. "! EMPTY YOUR INVENTORY!"
  263.                 end
  264.                 rust.Notice(netuser, msg)
  265.                 rust.SendChatToUser(netuser, "If you are victorious; you will respawn where you typed this command.")
  266. end
  267.  
  268. function PLUGIN:TeamBalance(netuser, request)
  269.     for i, v in pairs(self.Team) do
  270.         if (request ~= i) then
  271.             if (self.Team[request] <= v) then  
  272.             return true
  273.             else
  274.                 rust.Notice(netuser, "Teams unbalanced, try again!")
  275.             return false
  276.             end
  277.         end
  278.     end
  279. end
  280.  
  281. function PLUGIN:StartMatch()
  282.     local check = self.Team[1] + self.Team[2]
  283.     if self.PlayerCount >= self.MinPlayer then
  284.         if (self.RandomTeams == true) then
  285.             self:TeamsRandom()
  286.         end
  287.         for i in pairs(self.Roster) do
  288.             local userID = i
  289.             if (self.Roster[userID].Status == "queued") then
  290.                 self:ClearOutInventory(self.Roster[userID].UArenaNetUser, self.Roster[userID].Team)
  291.                 self:UArenaTP(self.Roster[userID].UArenaNetUser, userID, self.Roster[userID].Team)
  292.                 self:LoadOut(self.Roster[userID].UArenaNetUser, self.Roster[userID].Team)
  293.                 self.Roster[userID].Status = "alive"
  294.             end
  295.         end
  296.     else
  297.     return
  298.     end
  299. end
  300.  
  301. function PLUGIN:TeamsRandom()
  302.     local dist = self.Team[99]/2
  303.     for i in pairs(self.Roster) do
  304.         if (self.Roster[i].Status == "queued") then
  305.             if (self.Team[1] >= dist) then
  306.                 self.Roster[i].Team = 2
  307.                 self.Team[2] = self.Team[2] + 1
  308.             elseif (self.Team[2] >= dist) then
  309.                 self.Roster[i].Team = 1
  310.                 self.Team[1] = self.Team[1] + 1
  311.             else
  312.                 team = math.random(1, 2)
  313.                 self.Roster[i].Team = team
  314.                 self.Team[team] = self.Team[team] + 1
  315.             end
  316.         end
  317.     end
  318. return
  319. end
  320.  
  321. function PLUGIN:UArenaTP(netuser, userID, team)
  322.     local coords = netuser.playerClient.lastKnownPosition;
  323.     local key = self.Roster[userID].Team
  324.     coords.x = self.UArenaSpawn[key].x
  325.     coords.y = self.UArenaSpawn[key].y + 3
  326.     coords.z = self.UArenaSpawn[key].z
  327.     rust.ServerManagement():TeleportPlayer(netuser.playerClient.netPlayer, coords)
  328. end
  329.  
  330. function PLUGIN:LoadOut(netuser, team)
  331.     local inv = rust.GetInventory(netuser)
  332.     local item = rust.GetDatablockByName("Rock")
  333.     local belt = rust.InventorySlotPreference(InventorySlotKind.Belt, false, InventorySlotKindFlags.Belt)
  334.     local bag = rust.InventorySlotPreference(InventorySlotKind.Default, false, InventorySlotKindFlags.Belt)
  335.     local pref = rust.InventorySlotPreference( InventorySlotKind.Armor, false, InventorySlotKindFlags.Armor )
  336.     local amount = 1
  337.     local armor = {}
  338.     local guns = {}
  339.     if team == 1 then
  340.         armor = self.T1Armor
  341.         guns = self.T1Guns
  342.     elseif team == 2 then
  343.         armor = self.T2Armor
  344.         guns = self.T2Guns
  345.     end
  346.     for i, v in pairs(armor) do
  347.         item = rust.GetDatablockByName(v)
  348.         inv:AddItemAmount(item, amount, pref)
  349.     end
  350.     pref = belt
  351.     for i, v in pairs(guns) do
  352.         item = rust.GetDatablockByName(v)
  353.         inv:AddItemAmount(item, amount, pref)  
  354.     end
  355.     amount = self.MedkitQuantity
  356.     item = rust.GetDatablockByName(self.Medkit)
  357.     inv:AddItemAmount(item, amount, pref)
  358.     amount = 5
  359.     item = rust.GetDatablockByName("Granola Bar")
  360.     inv:AddItemAmount(item, amount, pref)
  361.     item = rust.GetDatablockByName("Bandage")
  362.     inv:AddItemAmount(item, amount, pref)
  363.     pref = bag
  364.     for i, v in pairs(self.Ammo) do
  365.         amount = self.AmmoQuantity
  366.         item = rust.GetDatablockByName(v)
  367.         inv:AddItemAmount(item, amount, pref)
  368.     end
  369.     for i, v in pairs(self.WepAttachments) do
  370.         amount = self.WepAttachQuan
  371.         item = rust.GetDatablockByName(v)
  372.         inv:AddItemAmount(item, amount, pref)
  373.     end
  374. end
  375.  
  376. function PLUGIN:UArenaLeave(userID)
  377.     local netuser = self.Roster[userID].UArenaNetUser
  378.     local coords = netuser.playerClient.lastKnownPosition;
  379.     coords.x = self.Roster[userID].x
  380.     coords.y = self.Roster[userID].y + 3
  381.     coords.z = self.Roster[userID].z
  382.     rust.ServerManagement():TeleportPlayer(netuser.playerClient.netPlayer, coords)
  383. end
  384.  
  385. function PLUGIN:CheckForWinner()
  386.     local active = {}
  387.     local t = 0
  388.     local TCount = 0
  389.     local team = 0
  390.     for team, v in pairs(self.Team) do
  391.         if (v > 0) then
  392.             active[team] = team
  393.         end
  394.     end
  395.     for k = 1, #active do
  396.         TCount = TCount + 1
  397.     end
  398.     if TCount == 0 then
  399.     return true, 2
  400.     end
  401.     if (TCount == 1) then
  402.     return true, active[1]
  403.     else
  404.     return false, 0
  405.     end
  406. end
  407.  
  408. function PLUGIN:WinDetected(winner)
  409.     print(winner)
  410.     for i in pairs(self.Roster) do
  411.         if (self.Roster[i].Team == winner) then
  412.             if (self.Roster[i].Status == "alive") then
  413.                 self:ClearOutInventory(self.Roster[i].UArenaNetUser)
  414.                 self:UArenaLeave(i)
  415.             end
  416.             self:UArenaRewards(self.Roster[i].UArenaNetUser)
  417.             rust.Notice(self.Roster[i].UArenaNetUser, "Your team won!")
  418.         end
  419.     end
  420.     self:UArenaClear()
  421.     if (self.ArenaOn == true) then
  422.         self:UArenaConfigPull()
  423.        
  424.         --self.ArenaTimer = timer.Repeat(1, 0, function() self:ArenaTick() end )
  425.         self.CanQueue = true
  426.     end
  427.     self:UABroadcastChat("Team " .. winner .. " has come out victorious!")
  428.     self:UABroadcastChat("A new round will start in " .. self.QueueTime .. " seconds.")
  429.     self.ArenaTock = 0
  430. end
  431.  
  432. function PLUGIN:UArenaRewards(netuser)
  433.     local inv = rust.GetInventory(netuser)
  434.     local pref = rust.InventorySlotPreference(InventorySlotKind.Belt, false, InventorySlotKindFlags.Belt)
  435.     local amount = 1
  436.     local item = rust.GetDatablockByName("Large Medkit")
  437.     inv:AddItemAmount(item, amount, pref)
  438.     local item = rust.GetDatablockByName("Rock")
  439.     inv:AddItemAmount (item, amount, pref)
  440.     if ((self.PlayerCount >= self.MinPlayerReward) and (not(self.Reward == {}))) then
  441.         for i, v in pairs(self.Reward) do
  442.             local amount = v
  443.             local item = rust.GetDatablockByName(i)
  444.             inv:AddItemAmount (item, amount, pref)
  445.         end
  446.     end
  447. end
  448.  
  449. function PLUGIN:LeaveQ(netuser, cmd, args)
  450.     if (self.CanQueue) then
  451.         userID = rust.GetUserID(netuser)
  452.         if (self.Roster[userID]) then
  453.             if (self.Roster[userID].Status == "queued") then
  454.                 self:RemoveQueue (netuser)
  455.                 rust.SendChatToUser(netuser, "Removed from queue!")
  456.             return
  457.             end
  458.         end
  459.     else
  460.         --rust.SendChatToUser(netuser, "You aren't in the queue!")
  461.     end
  462. end
  463.  
  464. function PLUGIN:ForceEnd(reason, netuser)
  465.     if (reason == "admin") then
  466.         self.ArenaOn = nil
  467.         rust.SendChatToUser(netuser, "Arena forced off!")
  468.     end
  469.     for i in pairs(self.Roster) do
  470.         if (self.Roster[i].Status == "alive") then
  471.             self:ClearOutInventory(self.Roster[i].UArenaNetUser)
  472.             self:UArenaLeave(i)
  473.         end
  474.     end
  475.     self:UArenaClear()
  476. end
  477.  
  478. function PLUGIN:OnKilled(takedamage, damage)
  479.     if (takedamage:GetComponent("HumanController")) then
  480.         userID = rust.GetUserID(damage.victim.client.netUser)
  481.         if (self.Roster[userID]) then
  482.             if (self.Roster[userID].Status == "alive") then
  483.                 self.Roster[userID].Status = "dead"
  484.                 local key = self.Roster[userID].Team
  485.                 self.Team[key] = self.Team[key] - 1
  486.                 local victory, team = self:CheckForWinner()
  487.                 if (victory) then
  488.                     self:WinDetected(team)
  489.                 end
  490.             elseif (self.Roster[userID].Status == "queued") then
  491.                 self:RemoveQueue (netuser)
  492.              return
  493.             end
  494.         end
  495.     end
  496. end
  497.  
  498. function PLUGIN:OnUserDisconnect(networkplayer)
  499.     local netuser = networkplayer:GetLocalData()
  500. if (not netuser or netuser:GetType().Name ~= "NetUser") then return end
  501.     local userID = rust.GetUserID(netuser)
  502.     if (self.Roster[userID]) then
  503.         if (self.Roster[userID].Status == "alive") then
  504.             self.Roster[userID].Status = "dc"
  505.             local key = self.Roster[userID].Team
  506.             self.Team[key] = self.Team[key] - 1
  507.             local victory, team = self:CheckForWinner()
  508.             if (victory) then
  509.                 self:WinDetected(team)
  510.             end
  511.             self.ArenaLimbo[userID] = true
  512.             self:SaveArenaLimboFile()
  513.             print(netuser.displayName .. " was added to arenalimbo.")
  514.         elseif (self.Roster[userID].Status == "queued") then
  515.             local key = self.Roster[userID].Team
  516.             self.PlayerCount = self.PlayerCount - 1
  517.             self.Team[key] = self.Team[key] - 1
  518.             self.Roster[userID] = nil
  519.         end
  520.     end
  521. end
  522.  
  523. function PLUGIN:RemoveQueue (netuser)
  524.     local key = self.Roster[userID].Team
  525.     self.PlayerCount = self.PlayerCount - 1
  526.     self.Team[key] = self.Team[key] - 1
  527.     self.Roster[userID] = nil
  528. end
  529. function PLUGIN:OnSpawnPlayer(playerclient, usecamp, avatar)
  530.     local netuser = playerclient.NetUser
  531.     local userID = rust.GetUserID( playerclient.NetUser )
  532.     if (self.ArenaLimbo[userID]) then
  533.         timer.Once( 1, function()
  534.         self:ClearOutInventory(netuser)
  535.         end)
  536.         self.ArenaLimbo[userID] = nil
  537.         self:SaveArenaLimboFile()
  538.     end
  539. end
  540.  
  541. function PLUGIN:UArenaSetSpawn(netuser, team)
  542.     local coords = {}
  543.     local current_coords = netuser.playerClient.lastKnownPosition;
  544.     coords.x = current_coords.x
  545.     coords.y = current_coords.y + 3
  546.     coords.z = current_coords.z
  547.     self.UArenaSpawn[team] = coords
  548.     self:SaveSpawnFile()
  549. end
  550.  
  551. function PLUGIN:UArenaClear()
  552.     self.Roster = {}
  553.     self.Team = {}
  554.     self.Team[0] = 0
  555.     self.Team[1] = 0
  556.     self.Team[2] = 0
  557.     self.Team[99] = 0
  558.     self.PlayerCount = 0
  559.     --self.ArenaTimer:Destroy()
  560. end
  561.  
  562. function PLUGIN:ClearOutInventory(netuser)
  563.     local inv = rust.GetInventory(netuser)
  564.     for i = 0, 39 do
  565.         inv:RemoveItem(i)
  566.     end
  567. end
  568.  
  569. function PLUGIN:SaveSpawnFile()
  570.     self.UArenaSpawnFile:SetText(json.encode(self.UArenaSpawn))
  571.     self.UArenaSpawnFile:Save()
  572. end
  573.  
  574. function PLUGIN:SaveArenaLimboFile()
  575.     self.ArenaLimboFile:SetText(json.encode(self.ArenaLimbo))
  576.     self.ArenaLimboFile:Save()
  577.  
  578. end
  579.  
  580. function PLUGIN:SaveConfigFile()
  581.     config.Save( "uberarena" )
  582. end
  583. --self:UABroadcastChat
  584. function PLUGIN:UABroadcastChat(msg)
  585.     rust.BroadcastChat("uberArena", msg)
  586. end
  587.  
  588. function PLUGIN:UArenaDebug(netuser)
  589.     print("ArenaTock: " .. self.ArenaTock)
  590. end
  591.  
  592.  
  593. function PLUGIN:ModifyDamage(takedamage, damage)
  594.     if (self.FriendlyFire == "off") then
  595.         if (takedamage:GetComponent("HumanController")) and (not(self.CanQueue)) then
  596.             local victimID = rust.GetUserID(damage.victim.client.netUser)
  597.             local attackerID = rust.GetUserID(damage.attacker.client.netUser)
  598.             if (not(victimID == attackerID)) then
  599.                 if (self.Roster[victimID].Team == self.Roster[attackerID].Team) then
  600.                     damage.amount = 0
  601.                 return damage
  602.                 end
  603.             end
  604.         end
  605.     end
  606. end
  607.  
  608. function PLUGIN:UArenaCommands(netuser, cmd, args)
  609.     if (args[1] == "status") then
  610.         if (self.ArenaOn) and (self.CanQueue) then
  611.             rust.SendChatToUser(netuser, "You can queue for the next match. There are " .. self.PlayerCount .. " people already queued! Next round begins in " .. self.QueueTime - self.ArenaTock .. " seconds!")
  612.         return
  613.         elseif (self.ArenaOn) then
  614.             rust.SendChatToUser(netuser, "There is a match in progress.")
  615.             rust.SendChatToUser(netuser, "There are " .. self.Team[1] .. " players alive on team one and")
  616.             rust.SendChatToUser(netuser, "There are " .. self.Team[2] .. " players alive on team two!")
  617.             rust.SendChatToUser(netuser, "Time Left: " .. (self.MatchTime - self.ArenaTock) .. " seconds remaining!")
  618.         return
  619.         else
  620.             rust.SendChatToUser (netuser, "The arena is currently disabled!")
  621.         return     
  622.         end
  623.     elseif (args[1] == "help") then
  624.         rust.SendChatToUser(netuser, "uberArena version " .. self.Version)
  625.         rust.SendChatToUser(netuser, "/ua status to see the arenas' current status")
  626.         rust.SendChatToUser(netuser, "/jt 1 or 2 to join a team while the queue is active")
  627.         rust.SendChatToUser(netuser, "/leaveq to leave the queue")
  628.         rust.SendChatToUser(netuser, "Be sure to clear your inventory before you join the queue!")
  629.     return
  630.     end
  631.     value = self.MatchTime - self.ArenaTock
  632. end
  633.  
  634. function PLUGIN:AdminUArenaCommands (netuser, cmd, args)
  635.     if (netuser:CanAdmin()) or (self.oxminInstalled and oxmin_Plugin:HasFlag(netuser, self.FLAG_UAControls, false)) then
  636.         if (args[1] == "debug") then
  637.             self:UArenaDebug(netuser)
  638.         return
  639.         elseif (args[1] == "onbydefault") then
  640.             if (args[2]) == "true" then
  641.                 rust.SendChatToUser(netuser, "Changed setting onbydefault to true. Was " .. self.Config.OnByDefault .. "!")
  642.                 self.Config.OnByDefault = true
  643.                 config.Save("uberarena")
  644.             return
  645.             elseif (args[2] == "false") then
  646.                 rust.SendChatToUser(netuser, "Changed setting onbydefault to false. Was " .. self.Config.OnByDefault .. "!")
  647.                 self.Config.OnByDefault = true
  648.                 config.Save("uberarena")
  649.             return
  650.             else
  651.             rust.SendChatToUser(netuser, "onbydefault must be true or false")
  652.             return
  653.             end
  654.         elseif (args[1] == "arena") then
  655.             if (args[2] == "on") then
  656.                 if (not(self.ArenaOn)) then
  657.                     self.CanQueue = true
  658.                     self.ArenaOn = true
  659.                     --self.ArenaTimer = timer.Repeat(1, 0, function() self:ArenaTick() end )
  660.                     self.ArenaTock = 0
  661.                     self:UArenaConfigPull()
  662.                     rust.SendChatToUser (netuser, "The uberArena is on!")
  663.                 return
  664.                 else
  665.                     rust.SendChatToUser (netuser,"The uberArena is already on!")
  666.                 return
  667.                 end
  668.             elseif  (args[2] == "off") then
  669.                 if (self.ArenaOn) and (self.CanQueue) then
  670.                     self.ArenaOn = nil
  671.                     rust.SendChatToUser (netuser, "The uberArena is off!")
  672.                 return
  673.                 elseif (self.ArenaOn) then
  674.                     self.ArenaOn = nil
  675.                     rust.SendChatToUser (netuser, "It will be disabled after the match ends!")
  676.                 return
  677.                 end
  678.             else
  679.                 rust.SendChatToUser(netuser, "You must turn it on or off! Not " .. args[2])
  680.             return
  681.             end
  682.         elseif  (args[1] == "reset") then
  683.                 if (self.ArenaOn) and (self.CanQueue) then
  684.                     self:ForceEnd("admin", netuser)
  685.                     self.CanQueue = true
  686.                     self.ArenaOn = true
  687.                     self.ArenaTock = 0
  688.                     self:UArenaConfigPull()
  689.                     rust.SendChatToUser (netuser, "The uberArena is off!")
  690.                 return
  691.                 end
  692.         elseif (args[1] == "forceoff") then
  693.             if (self.ArenaOn) and (not(self.CanQueue)) then
  694.                 self:UArenaDebug(netuser)
  695.                 self:ForceEnd("admin", netuser)
  696.                 rust.SendChatToUser(netuser, "Arena forced off!")
  697.             return
  698.             else
  699.                 rust.SendChatToUser(netuser, "Arena doesn't need to be forced off!")
  700.             return
  701.             end
  702.         elseif (args[1] == "friendlyfire") then
  703.             if (args[2] == "on") or (args[2] == "off") then
  704.                 rust.SendChatToUser(netuser, "friendlyfire changed to " .. args[2] .. ". Was " .. self.Config.FriendlyFire .. ". Will apply after next match!")
  705.                 self.Config.FriendlyFire = args[2]
  706.                 config.Save("uberarena")
  707.             return
  708.             else
  709.             rust.SendChatToUser(netuser, "friendly fire must be set to on or off")
  710.             return
  711.             end
  712.         elseif (args[1] == "queuetime") then
  713.             if (args[2]) then
  714.                 rust.SendChatToUser(netuser, "queuetime changed to " .. tonumber(args[2]) .. ". Was " .. self.Config.QueueTime .. ". Will apply after next match!")
  715.                 self.Config.QueueTime = tonumber(args[2])
  716.                 config.Save("uberarena")
  717.             return
  718.             else
  719.                 rust.SendChatToUser(netuser, "Value required (in seconds)!")
  720.             return
  721.             end
  722.         elseif (args[1] == "minplayer") then
  723.             if ((tonumber(args[2]) > 1) and (tonumber(args[2]) < self.Config.MaxPlayer)) then
  724.                 rust.SendChatToUser(netuser, "minplayer changed to " .. tonumber(args[2]) .. ". Was " .. self.Config.MinPlayer .. ". Will apply after next match!")
  725.                 self.Config.MinPlayer = tonumber(args[2])
  726.                 config.Save("uberarena")
  727.             return
  728.             elseif (tonumber(args[2]) > self.Config.MaxPlayer) then
  729.                 rust.SendChatToUser(netuser, "Must be lower than maxplayer(" .. self.Config.MaxPlayer .. ")!")
  730.             return
  731.             else
  732.                 rust.SendChatToUser(netuser, "Must be a number")
  733.             return
  734.             end
  735.         elseif (args[1] == "maxplayer") then
  736.             if (args[2]) and (tonumber(args[2]) > self.Config.MinPlayer) then
  737.                 rust.SendChatToUser(netuser, "maxplayer changed to " .. tonumber(args[2]) .. ". Was " .. self.Config.MaxPlayer .. ". Will apply after next match!")
  738.                 self.ConfigMinPlayer = tonumber(args[2])
  739.                 self.SaveConfigFile()              
  740.             return
  741.             elseif (args[2]) and (tonumber(args[2]) < self.Config.MinPlayer) then
  742.                 rust.SendChatToUser(netuser, "Must be higher than minplayer(" .. self.Config.MinPlayer .. ")!")
  743.             return
  744.             else
  745.                 rust.SendChatToUser(netuser, "Must be a number")
  746.             return
  747.             end
  748.         elseif (args[1] == "spawn") then
  749.             if (args[2]) and (tonumber(args[2]) < 3) then
  750.                 rust.SendChatToUser(netuser, "Team " .. tonumber(args[2]) .. " spawn set!")
  751.                 self:UArenaSetSpawn(netuser, tonumber(args[2]))
  752.             return
  753.             else
  754.                 rust.SendChatToUser(netuser, "Can set team 1 or 2")
  755.             return
  756.             end
  757.         elseif (args[1] == "reward") then
  758.             if (rust.GetDatablockByName(args[2])) then
  759.                 if (args[3] == "remove") and (self.Reward[args[2]]) then
  760.                     rust.SendChatToUser(netuser, args[2] .. " removed from rewards list!")
  761.                     self.Reward[args[2]] = nil
  762.                 return
  763.                 else
  764.                     rust.SendChatToUser (netuser, "Reward " .. args[2] .. " in quantity " .. tonumber(args[3]) .. " was added to the reward list!")
  765.                     self.Config.Reward[args[2]] = tonumber(args[3])
  766.                     config.Save("uberarena")
  767.                 return
  768.                 end
  769.             else
  770.             rust.SendChatToUser(netuser, "Improper syntax.")
  771.             return
  772.             end
  773.         elseif (args[1] == "minplayerreward") then
  774.             if (args[2]) and (tonumber(args[2]) > 0) then
  775.                 rust.SendChatToUser(netuser, "minplayerreward changed to " .. tonumber(args[2]) .. ". Was " .. self.Config.MinPlayerReward .. ". Will apply after next match!")
  776.                 self.Config.MinPlayerReward = tonumber(args[2])
  777.                 config.Save("uberarena")
  778.             return
  779.             else
  780.                 rust.SendChatToUser(netuser, "minplayerreward must be greater than 1")
  781.             return
  782.             end
  783.         elseif (args[1] == "matchlimit") then
  784.             if (args[2]) and (tonumber(args[2]) == 0) then
  785.                 rust.SendChatToUser(netuser, "matchlimit disabled! Will apply after next match!")
  786.                 self.Config.MatchTime = 0
  787.                 config.Save("uberarena")
  788.             return
  789.             elseif (args[2]) and (tonumber(args[2]) > 0) then
  790.                 rust.SendChatToUser(netuser, "matchlimit set to " .. tonumber(args[2]) .. ". Will apply after next match!")
  791.                 self.Config.MatchTime = tonumber(args[2])
  792.                 config.Save("uberarena")
  793.             return
  794.             else
  795.                 rust.SendChatToUser(netuser, "Match time limit (in seconds). Setting it to 0 will remove timelimit!")
  796.             return
  797.             end
  798.         elseif (args[1] == "arenaalert") then
  799.             if (args[2]) and (tonumber(args[2])) then
  800.                 rust.SendChatToUser(netuser, "arenaalert set to " .. tonumber(args[2]) .. ". Was " .. self.Config.AlertTime .. ". Will apply after next match!")
  801.                 self.Config.AlertTime = tonumber(args[2])
  802.                 config.Save("uberarena")
  803.             return
  804.             end
  805.         elseif (args[1] == "randomteams") then
  806.             if (self.RandomTeams == true) then
  807.                 self.Config.RandomTeams = false
  808.             elseif (self.RandomTeams == false) then
  809.                 self.Config.RandomTeams = true
  810.             end
  811.                 rust.SendChatToUser(netuser, "randomteams toggled to " .. tostring(self.Config.RandomTeams) .. ". Will apply after next match!")
  812.                 config.Save("uberarena")
  813.         return
  814.         else
  815.         rust.SendChatToUser(netuser, "Invalid command")
  816.         return
  817.         end
  818.     else
  819.     rust.SendChatToUser (netuser, "You must be logged in as an admin to do this!")
  820.     end
  821. end
  822.  
  823. function PLUGIN:UAStatusCommands(netuser, cmd, args)
  824.     if (netuser:CanAdmin()) or (self.oxminInstalled and oxmin_Plugin:HasFlag(netuser, self.FLAG_UAControls, false)) then
  825.         local oldsetting = "derp"
  826.         local newsetting = "derp"
  827.         local arenastatus = "for next match"
  828.         local proceed = false
  829.         if (self.ArenaOn) and (not(self.CanQueue)) then
  830.             arenastatus = "for current match"
  831.         end
  832.         if (args[1] == "randomteams") then
  833.             oldsetting = self.RandomTeams
  834.             newsetting = self.Config.RandomTeams
  835.         elseif (args[1] == "minplayer") then
  836.             newsetting = self.Config.MinPlayer
  837.             oldsetting = self.MinPlayer
  838.         elseif (args[1] == "maxplayer") then
  839.             newsetting = self.Config.MaxPlayer
  840.             oldsetting = self.MaxPlayer
  841.         elseif (args[1] == "queuetime") then
  842.             newsetting = self.Config.QueueTime
  843.             oldsetting = self.QueueTime
  844.         elseif (args[1] == "arenaalert") then
  845.             newsetting = self.Config.AlertTime
  846.             oldsetting = self.AlertTime
  847.         elseif (args[1] == "minplayerreward") then
  848.             newsetting = self.Config.MinPlayerReward
  849.             oldsetting = self.MinPlayerReward
  850.         elseif (args[1] == "matchlimit") then
  851.             newsetting = self.Config.MatchTime
  852.             oldsetting = self.MatchTime - self.QueueTime
  853.         elseif (args[1] == "friendlyfire") then
  854.             newsetting = self.Config.FriendlyFire
  855.             oldsetting = self.FriendlyFire
  856.         end
  857.         if (tostring(oldsetting)) and (tostring(newsetting)) then
  858.             if (tostring(oldsetting) == tostring(newsetting)) then
  859.                 rust.SendChatToUser(netuser, "Status " .. tostring(arenastatus) .. " is " .. args[1] .. ": " .. tostring(oldsetting) .. "!")
  860.             return
  861.             else
  862.                 rust.SendChatToUser(netuser, "Status " .. tostring(arenastatus) .. " is " .. args[1] .. ": " .. tostring(oldsetting) .. ". Will be " .. tostring(newsetting) .. " the match after that!")
  863.             end
  864.         else
  865.         end
  866.     end
  867. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement