PLUGIN.Title = "uberArena" PLUGIN.Description = "Automated deathmatch Arena" PLUGIN.Author = "Senorderp" PLUGIN.Version = "0.7.1b" PLUGIN.ResourceId = "268" api.Bind(PLUGIN, "uberArena") function PLUGIN:Init() self.BorderActive = false --Spawns self.UArenaSpawnFile = util.GetDatafile("uarenaspawns") local json_txt = json.decode(self.UArenaSpawnFile:GetText()) if not json_txt then json_txt = {} self.FirstSpawnLoad = true end self.UArenaSpawn = json_txt --ArenaLimbo self.ArenaLimboFile = util.GetDatafile("arenalimbo") local json_txt2 = json.decode(self.ArenaLimboFile:GetText()) if not json_txt2 then json_txt2 = {} end self.ArenaLimbo = json_txt2 --Config local b, res = config.Read("uberarena") self.Config = res or {} if (not b) then self:LoadDefaultConfig() config.Save("uberarena") end self.LoadOut = {} local b, res = config.Read("ualoadout") self.LoadoutConfig = res or {} if (not b) then self:LoadDefaultLoadouts() config.Save( "ualoadout" ) end oxmin_Plugin = plugins.Find("oxmin") if ((not(oxmin_Plugin)) or (not(oxmin))) then self.oxminInstalled = false else self.FLAG_UAControls = oxmin.AddFlag("canuaconfig") self.FLAG_UAonoff = oxmin.AddFlag("cancontrolarena") self.oxminInstalled = true end if (api.Exists("economy")) then self.EconExists = true if (not(self.Config.EntranceFee)) then self.Config.EntranceFee = 0 config.Save("uberarena") end self.EntranceFee = self.Config.EntranceFee end if (api.Exists("bushycoin")) then self.BCoinExists = true if (not(self.Config.BCEntranceFee)) then self.Config.BCEntranceFee = 0 config.Save("uberarena") end self.BCEntranceFee = self.Config.BCEntranceFee end --Add commands self:AddChatCommand ("jt", self.RequestJoin) self:AddChatCommand ("ua", self.UArenaCommands) self:AddChatCommand ("uaconfig", self.AdminUArenaCommands) self:AddChatCommand ("leaveq", self.LeaveQ) self:AddChatCommand ("uastatus", self.UAStatusCommands) --Tables self.Roster = {} self.Team = {} self.Team[0] = 0 self.Team[1] = 0 self.Team[2] = 0 self.Team[99] = 0 --Config Additions if (not(self.Config.RandomTeams)) then self.Config.RandomTeams = false config.Save("uberarena") end if (not(self.Config.LoadoutAssignments)) then self.Config.LoadoutAssignments = {} self.Config.LoadoutAssignments[1] = "Team1Loadout" self.Config.LoadoutAssignments[2] = "Team2Loadout" config.Save("uberarena") end if (not(self.Config.EntranceFee)) then self.Config.EntranceFee = 0 config.Save("uberarena") end if (not(self.Config.Border)) then self.Config.Border = {} self.Config.Border[1] = {} self.Config.Border[2] = {} config.Save("uberarena") end if (not(self.Config.SpamChat)) then if (self.Config.SpamChat == false) then else self.Config.SpamChat = true config.Save("uberarena") end end self.ArenaOn = self.Config.OnByDefault self.QueueTime = self.Config.QueueTime self.MinPlayer = self.Config.MinPlayer self.MaxPlayer = self.Config.MaxPlayer self.ArenaAlert = (self.Config.QueueTime - self.Config.AlertTime) self.MatchTime = (self.Config.MatchTime + self.Config.QueueTime) self.MinPlayerReward = self.Config.MinPlayerReward self.Reward = self.Config.Reward self.FriendlyFire = self.Config.FriendlyFire self.RandomTeams = self.Config.RandomTeams self.LoadoutAssignments = self.Config.LoadoutAssignments self.LoadOut = self.LoadoutConfig.LoadOut self.SpamChat = self.Config.SpamChat if (self.Config.Border[1].x) and (self.Config.Border[2].x) then self.BorderActive = true end --Globals self.PlayerCount = 0 self.ArenaTock = 0 --self.GameMode = "Classic TDM" --Timer disqualtimer = 1 self.ArenaTimer = timer.Repeat(1, 0, function() self:ArenaTick() end ) if (self.ArenaOn) and (not(self.FirstSpawnLoad)) then self.CanQueue = true elseif ((self.ArenaOn) and (self.FirstSpawnLoad == true))then self.ArenaOn = nil print("uberArena: Set your spawnpoints before turning on!") end print("uberArena version " .. self.Version .. " successfully loaded!") end function PLUGIN:SendHelpText( netuser ) rust.SendChatToUser(netuser, "/ua status for uberArena status") rust.SendChatToUser(netuser, "/ua help for uberArena commands") end function PLUGIN:UArenaDebug(netuser) print("ArenaTock: " .. self.ArenaTock) print("user: " .. self.Roster[userID]) print("netuser: " .. self.Roster[userID].UArenaNetUser) print("PlayerCount: " .. self.PlayerCount) end function PLUGIN:UArenaConfigPull() self.QueueTime = self.Config.QueueTime self.MinPlayer = self.Config.MinPlayer self.MaxPlayer = self.Config.MaxPlayer self.ArenaAlert = (self.Config.QueueTime - self.Config.AlertTime) self.MatchTime = (self.Config.MatchTime + self.Config.QueueTime) self.MinPlayerReward = self.Config.MinPlayerReward self.Reward = self.Config.Reward self.FriendlyFire = self.Config.FriendlyFire self.RandomTeams = self.Config.RandomTeams self.LoadoutAssignments = self.Config.LoadoutAssignments self.LoadOut = self.LoadoutConfig.LoadOut self.SpamChat = self.Config.SpamChat if (self.EconExists) then self.EntranceFee = self.Config.EntranceFee end if (self.BCoinExists) then self.BCEntranceFee = self.Config.BCEntranceFee end end function PLUGIN:LoadDefaultConfig() self.Config.OnByDefault = true self.Config.FriendlyFire = "on" self.Config.QueueTime = 60 self.Config.MinPlayer = 2 self.Config.MaxPlayer = 8 self.Config.AlertTime = 20 self.Config.MatchTime = 300 -- 5 minutes self.Config.MinPlayerReward = 4 self.Config.Reward = {} self.Config.RandomTeams = false self.Config.LoadoutAssignments = {} self.Config.LoadoutAssignments[1] = "Team1Loadout" self.Config.LoadoutAssignments[2] = "Team2Loadout" self.Config.Border = {} self.Config.Border[1] = {} self.Config.Border[2] = {} self.Config.SpamChat = true end function PLUGIN:LoadDefaultLoadouts() local armor = {"Leather Boots", "Leather Pants", "Leather Vest", "Leather Helmet"} local armor2 = {"Kevlar Boots","Kevlar Pants","Rad Suit Vest","Rad Suit Helmet"} local belt = {} local iem = {"MP5A4", "Shotgun", "M4", "Large Medkit", "Bandage", "Granola Bar"} local amt = {1, 1, 1, 1, 5, 5} belt.item = iem belt.amount = amt local ammo = {} iem2 = {"9mm Ammo", "Shotgun Shells", "556 Ammo"} amt2 = {125, 36, 125} ammo.item = iem2 ammo.amount = amt2 local wepattachments = {} iem3 = {"Flashlight Mod", "Laser Sight", "Holo sight", "Silencer"} amt3 = {1, 1, 1, 1} wepattachments.item = iem3 wepattachments.amount = amt3 local misc = {} iem4 = {"Flare", "Rock"} amt4 = {5, 1} misc.item = iem4 misc.amount = amt4 local loadout = {} local loadout2 = {} loadout.Armor = armor loadout.Belt = belt loadout.Ammo = ammo loadout.WepAttachments = wepattachments loadout.Misc = misc loadout2.Armor = armor2 loadout2.Belt = belt loadout2.Ammo = ammo loadout2.WepAttachments = wepattachments loadout2.Misc = misc self.LoadOut["Team1Loadout"] = loadout self.LoadOut["Team2Loadout"] = loadout2 self.LoadoutConfig.LoadOut = self.LoadOut end function PLUGIN:ArenaTick() self.ArenaTock = self.ArenaTock + 1 if (self.ArenaOn) and (self.CanQueue) then self:QueueActive(self.ArenaTock, self.PlayerCount) return elseif (self.ArenaOn) then self:MatchActive(self.ArenaTock) return end return end function PLUGIN:QueueActive(Tock, playercount) if (Tock == self.ArenaAlert) then if (self.SpamChat) then self:PreMatchWarning() end return elseif (Tock == self.QueueTime) then if playercount >= self.MinPlayer then if (self.SpamChat) then self:UABroadcastChat("A new round has begun in the Arena!") end self.CanQueue = nil self:StartMatch () return else local key = self.MinPlayer - playercount if (self.SpamChat) then self:UABroadcastChat("There are not enough players to start a match. " .. key .. " more players required!") if (self.RandomTeams) then self:UABroadcastChat("type /jt to join a random team!") else self:UABroadcastChat("type /jt 1 or 2 to queue if you aren't already!") end end self.ArenaTock = 0 return end return end return end function PLUGIN:MatchActive(Tock) if (self.MatchTime <= 0) then return else local timeleft = (self.MatchTime - Tock) local matchwarning = self.MatchTime - 15 if (Tock == matchwarning) then for i in pairs(self.Roster) do if (self.Roster[i].Status == "alive") then self.InventoryNotice(self.Roster[i].UArenaNetUser, "15 seconds remaining until match ends!") return end end elseif (Tock == self.MatchTime) then for i in pairs(self.Roster) do rust.Notice(self.Roster[i].UArenaNetUser, "Time limit reached! You have FAILED!") end if (self.SpamChat) then self:UABroadcastChat("Match ended in a draw! New match begins in " .. self.QueueTime .. " seconds!") end self:ForceEnd("timelimit") self.ArenaTock = 0 self.CanQueue = true return end return end return end function PLUGIN:PreMatchWarning() if (self.MinPlayer > self.PlayerCount) then local players = self.MinPlayer - self.PlayerCount self:UABroadcastChat(self.Config.AlertTime.. " seconds before the next match! " .. players .. " players still needed!") return else self:UABroadcastChat(self.PlayerCount .. " players queued! Next match begins in " .. self.Config.AlertTime.. " seconds!") return end return end function PLUGIN:RequestJoin(netuser, cmd, args) local userID = rust.GetUserID(netuser) local teamrequest = 0 local msg = "derp" if (self.ArenaOn) then if (self.PlayerCount > self.MaxPlayer) then rust.Notice (netuser, "There are too many players! Try again next match.") return elseif (self.CanQueue) then if (self.EconExists) and (self.EntranceFee ~= 0) then local b, balance = api.Call("economy", "getMoney", netuser) if (balance < tonumber(self.EntranceFee)) then rust.SendChatToUser(netuser, "Not enough cash to enter the queue!") return end end if (self.BCoinExists) and (self.BCEntranceFee ~= 0) then local call, b, balance = api.Call("bushycoin", "balance", netuser) if (balance < tonumber(self.BCEntranceFee)) then rust.SendChatToUser(netuser, "Not enough coin to enter the queue!") return end end for i in pairs(self.Roster) do if i == userID then rust.Notice(netuser, "You are already queued!") return end end if ((args[1] == "1") or (args[1] == "2")) and (self.RandomTeams == false) then teamrequest = tonumber(args[1]) local accept = self:TeamBalance(netuser, teamrequest) if accept then self:JoinAccept(netuser, teamrequest) return end elseif (self.RandomTeams) then teamrequest = 99 self:JoinAccept(netuser, teamrequest) return elseif (not(args[1] == "1") or not(args[1] == "2")) and (self.RandomTeams == false) then rust.SendChatToUser(netuser, "You must specify a proper team") return else end end end end function PLUGIN:JoinAccept(netuser, request) local userID = rust.GetUserID(netuser) local current_coords = netuser.playerClient.lastKnownPosition; local teamjoin = {} teamjoin.Team = request teamjoin.Status = "queued" teamjoin.x = current_coords.x teamjoin.y = current_coords.y teamjoin.z = current_coords.z teamjoin.UArenaNetUser = netuser self.Roster[userID] = teamjoin self.PlayerCount = self.PlayerCount + 1 self.Team[request] = self.Team[request] + 1 if (self.EconExists) and (self.EntranceFee ~= 0) then api.Call("economy", "takeMoneyFrom", netuser, self.EntranceFee) end if (self.BCoinExists) and (self.BCEntranceFee ~= 0) then api.Call("bushycoin", "deduct", netuser, self.BCEntranceFee) local call, b, balance = api.Call("bushycoin", "balance", netuser) rust.SendChatToUser(netuser, "Bushy Coin balance is: " .. balance .. "(- " .. self.BCEntranceFee .. " )") end if (request == 99) then msg = "You have joined the queue. You will be placed on a random team at the start of the match!" else msg = "You have successfully joined team " .. self.Roster[userID].Team .. "! EMPTY YOUR INVENTORY!" end rust.Notice(netuser, msg) rust.SendChatToUser(netuser, "If you are victorious; you will respawn where you typed this command.") end function PLUGIN:TeamBalance(netuser, request) for i, v in pairs(self.Team) do if (request ~= i) then if (self.Team[request] <= v) then return true else rust.Notice(netuser, "Teams unbalanced, try again!") return false end end end end function PLUGIN:StartMatch() local check = self.Team[1] + self.Team[2] if self.PlayerCount >= self.MinPlayer then if (self.RandomTeams == true) then self:TeamsRandom() end for i in pairs(self.Roster) do local userID = i if (self.Roster[userID].Status == "queued") then self:ClearOutInventory(self.Roster[userID].UArenaNetUser, self.Roster[userID].Team) self:UArenaTP(self.Roster[userID].UArenaNetUser, userID, self.Roster[userID].Team) self:UALoadOut(self.Roster[userID].UArenaNetUser, self.LoadoutAssignments[self.Roster[userID].Team]) self.Roster[userID].Status = "alive" end end else return end end function PLUGIN:TeamsRandom() local dist = self.Team[99]/2 for i in pairs(self.Roster) do if (self.Roster[i].Status == "queued") then if (self.Team[1] >= dist) then self.Roster[i].Team = 2 self.Team[2] = self.Team[2] + 1 elseif (self.Team[2] >= dist) then self.Roster[i].Team = 1 self.Team[1] = self.Team[1] + 1 else team = math.random(1, 2) self.Roster[i].Team = team self.Team[team] = self.Team[team] + 1 end end end return end function PLUGIN:UArenaTP(netuser, userID, team) local coords = netuser.playerClient.lastKnownPosition; local key = self.Roster[userID].Team coords.x = self.UArenaSpawn[key].x coords.y = self.UArenaSpawn[key].y + 3 coords.z = self.UArenaSpawn[key].z rust.ServerManagement():TeleportPlayer(netuser.playerClient.netPlayer, coords) end function PLUGIN:UALoadOut(netuser, loadoutname) local check = 0 local inv = rust.GetInventory(netuser) local item = rust.GetDatablockByName("Rock") local amount = 1 local pref = rust.InventorySlotPreference( InventorySlotKind.Armor, false, InventorySlotKindFlags.Armor ) for i, v in pairs(self.LoadOut[loadoutname].Armor) do item = rust.GetDatablockByName(v) inv:AddItemAmount(item, amount, pref) end pref = rust.InventorySlotPreference(InventorySlotKind.Belt, false, InventorySlotKindFlags.Belt) for i in pairs(self.LoadOut[loadoutname].Belt.item) do item = rust.GetDatablockByName(self.LoadOut[loadoutname].Belt.item[i]) amount = self.LoadOut[loadoutname].Belt.amount[i] inv:AddItemAmount(item, amount, pref) end pref = rust.InventorySlotPreference(InventorySlotKind.Default, false, InventorySlotKindFlags.Belt) for i in pairs(self.LoadOut[loadoutname].Ammo.item) do item = rust.GetDatablockByName(self.LoadOut[loadoutname].Ammo.item[i]) amount = self.LoadOut[loadoutname].Ammo.amount[i] inv:AddItemAmount(item, amount, pref) end for i in pairs(self.LoadOut[loadoutname].WepAttachments.item) do item = rust.GetDatablockByName(self.LoadOut[loadoutname].WepAttachments.item[i]) amount = self.LoadOut[loadoutname].WepAttachments.amount[i] inv:AddItemAmount(item, amount, pref) end for i in pairs(self.LoadOut[loadoutname].Misc.item) do item = rust.GetDatablockByName(self.LoadOut[loadoutname].Misc.item[i]) amount = self.LoadOut[loadoutname].Misc.amount[i] inv:AddItemAmount(item, amount, pref) end end function PLUGIN:UArenaLeave(userID) local netuser = self.Roster[userID].UArenaNetUser local coords = netuser.playerClient.lastKnownPosition; coords.x = self.Roster[userID].x coords.y = self.Roster[userID].y + 3 coords.z = self.Roster[userID].z rust.ServerManagement():TeleportPlayer(netuser.playerClient.netPlayer, coords) end function PLUGIN:CheckForWinner() local active = {} local t = 0 local TCount = 0 local team = 0 for team, v in pairs(self.Team) do if (v > 0) then active[team] = team end end for k = 1, #active do TCount = TCount + 1 end if TCount == 0 then return true, 2 end if (TCount == 1) then return true, active[1] else return false, 0 end end function PLUGIN:WinDetected(winner) print(winner) for i in pairs(self.Roster) do if (self.Roster[i].Team == winner) then if (self.Roster[i].Status == "alive") then self:ClearOutInventory(self.Roster[i].UArenaNetUser) self:UArenaLeave(i) end self:UArenaRewards(self.Roster[i].UArenaNetUser) rust.Notice(self.Roster[i].UArenaNetUser, "Your team won!") end end self:UArenaClear() if (self.ArenaOn == true) then self:UArenaConfigPull() self.CanQueue = true end self:UABroadcastChat("Team " .. winner .. " has come out victorious! A new round will start in " .. self.QueueTime .. " seconds.") self.ArenaTock = 0 end function PLUGIN:UArenaRewards(netuser) local inv = rust.GetInventory(netuser) local pref = rust.InventorySlotPreference(InventorySlotKind.Belt, false, InventorySlotKindFlags.Belt) local amount = 1 local item = rust.GetDatablockByName("Large Medkit") inv:AddItemAmount(item, amount, pref) local item = rust.GetDatablockByName("Rock") inv:AddItemAmount (item, amount, pref) if ((self.PlayerCount >= self.MinPlayerReward) and (not(self.Reward == {}))) then for i, v in pairs(self.Reward) do if (i == "cash") and (self.EconExists) then api.Call("economy", "giveMoneyTo", netuser, v) elseif (i == "coin") and (self.BCoinExists) then local call, req, res = api.Call("bushycoin", "add", netuser, v) else local amount = v local item = rust.GetDatablockByName(i) inv:AddItemAmount (item, amount, pref) end end if (BCoinExists) then api.Call("bushycoin", "saveNow") end end end function PLUGIN:LeaveQ(netuser, cmd, args) if (self.CanQueue) then userID = rust.GetUserID(netuser) if (self.Roster[userID]) then if (self.Roster[userID].Status == "queued") then self:RemoveQueue (netuser) rust.SendChatToUser(netuser, "Removed from queue!") return end end else --rust.SendChatToUser(netuser, "You aren't in the queue!") end end function PLUGIN:ForceEnd(reason, netuser) if (reason == "admin") then self.ArenaOn = nil rust.SendChatToUser(netuser, "Arena forced off!") end for i in pairs(self.Roster) do if (self.Roster[i].Status == "alive") then self:ClearOutInventory(self.Roster[i].UArenaNetUser) self:UArenaLeave(i) end end self:UArenaClear() end local Destroy = util.FindOverloadedMethod(Rust.NetCull._type, "Destroy", bf.public_static, {UnityEngine.GameObject}) function PLUGIN:RemoveBag(netuser) local curPos = netuser.playerClient.lastKnownPosition local lastObj = self:FindNearestLootableObject("LootSack(Clone)", curPos, 30) if(lastObj ~= nil ) then Destroy:Invoke(nil, util.ArrayFromTable(System.Object, {lastObj.gameObject})) end end local FindObjectsOfType = util.GetStaticMethod(UnityEngine.Object, "FindObjectsOfType") function PLUGIN:FindNearestLootableObject(name, position, radius) local lastDist = radius local lastObj = nil local objects = FindObjectsOfType(Rust.LootableObject._type) local object for i = 0, (objects.Length-1) do object = objects[i] if(object.gameObject.Name == name) then local inv = object:GetComponent("Inventory") if (inv) then local pos = object.gameObject.transform.position local dist = math.ceil(Rust.TransformHelpers.Dist2D(position, pos)) if(lastDist >= dist) then lastObj = object end end end end return lastObj end function PLUGIN:OnKilled(takedamage, damage) local playerkiller = false if (takedamage:GetComponent("HumanController")) and (self.Roster[userID].Status == "alive") then userID = rust.GetUserID(damage.victim.client.netUser) local netuser = damage.victim.client.netUser if (self.Roster[userID]) then if (self.Roster[userID].Status == "alive") then if (damage.attacker.client) then playerkiller = true end for i, v in pairs(self.Roster) do if (i == userID) then if (playerkiller) and (not(damage.victim.client.netUser == damage.attacker.client.netUser)) then rust.SendChatToUser(self.Roster[i].UArenaNetUser, "You were killed by " .. damage.victim.client.netUser.displayName .. "!") elseif (damage.victim.client.netUser == damage.attacker.client.netUser) then rust.SendChatToUser(self.Roster[i].UArenaNetUser, "You committed suicide!") else rust.SendChatToUser(self.Roster[i].UArenaNetUser, "You died!") end else if (playerkiller) then rust.InventoryNotice(self.Roster[i].UArenaNetUser, "(Team " .. self.Roster[rust.GetUserID(damage.attacker.client.netUser)].Team .. ")" .. damage.attacker.client.netUser.displayName .. " killed (Team " .. self.Roster[rust.GetUserID(damage.victim.client.netUser)].Team .. ")" .. damage.victim.client.netUser.displayName .. "!") else rust.InventoryNotice(self.Roster[i].UArenaNetUser, "(Team " .. self.Roster[rust.GetUserID(damage.victim.client.netUser)].Team .. ")" .. damage.victim.client.netUser.displayName .. "died!") end end end timer.Once(0, function() self:RemoveBag(netuser) end) self.Roster[userID].Status = "dead" local key = self.Roster[userID].Team self.Team[key] = self.Team[key] - 1 local victory, team = self:CheckForWinner() if (victory) then self:WinDetected(team) end elseif (self.Roster[userID].Status == "queued") then self:RemoveQueue (netuser) return end end end end function PLUGIN:OnUserDisconnect(networkplayer) local netuser = networkplayer:GetLocalData() if (not netuser or netuser:GetType().Name ~= "NetUser") then return end local userID = rust.GetUserID(netuser) if (self.Roster[userID]) then if (self.Roster[userID].Status == "alive") then self.Roster[userID].Status = "dc" local key = self.Roster[userID].Team self.Team[key] = self.Team[key] - 1 local victory, team = self:CheckForWinner() if (victory) then self:WinDetected(team) end self.ArenaLimbo[userID] = true self:SaveArenaLimboFile() print(netuser.displayName .. " was added to arenalimbo.") elseif (self.Roster[userID].Status == "queued") then local key = self.Roster[userID].Team self.PlayerCount = self.PlayerCount - 1 self.Team[key] = self.Team[key] - 1 self.Roster[userID] = nil end end end function PLUGIN:RemoveQueue (netuser) local key = self.Roster[userID].Team self.PlayerCount = self.PlayerCount - 1 self.Team[key] = self.Team[key] - 1 self.Roster[userID] = nil if (self.EconExists) and (self.EntranceFee ~= 0) then api.Call("economy", "giveMoneyTo", netuser, self.EntranceFee) end if (self.BCoinExists) and (self.BCEntranceFee ~= 0) then local call, b, balance = api.Call("bushycoin", "balance", netuser) local newbalance = balance + self.BCEntranceFee api.Call("bushycoin", "add", netuser, self.BCEntranceFee) rust.SendChatToUser(netuser, "Bushy Coin balance is: " .. newbalance .. "(+ " .. self.BCEntranceFee .. " )") end end function PLUGIN:OnSpawnPlayer(playerclient, usecamp, avatar) local netuser = playerclient.NetUser local userID = rust.GetUserID( playerclient.NetUser ) if (self.ArenaLimbo[userID]) then timer.Once( 1, function() self:ClearOutInventory(netuser) end) self.ArenaLimbo[userID] = nil self:SaveArenaLimboFile() end end function PLUGIN:UArenaSetSpawn(netuser, team) local coords = {} local current_coords = netuser.playerClient.lastKnownPosition; coords.x = current_coords.x coords.y = current_coords.y + 3 coords.z = current_coords.z self.UArenaSpawn[team] = coords self:SaveSpawnFile() end function PLUGIN:UArenaClear() self.Roster = {} self.Team = {} self.Team[0] = 0 self.Team[1] = 0 self.Team[2] = 0 self.Team[99] = 0 self.PlayerCount = 0 end function PLUGIN:ClearOutInventory(netuser) local inv = rust.GetInventory(netuser) for i = 0, 39 do inv:RemoveItem(i) end end function PLUGIN:SaveSpawnFile() self.UArenaSpawnFile:SetText(json.encode(self.UArenaSpawn)) self.UArenaSpawnFile:Save() end function PLUGIN:SaveArenaLimboFile() self.ArenaLimboFile:SetText(json.encode(self.ArenaLimbo)) self.ArenaLimboFile:Save() end function PLUGIN:SaveConfigFile() config.Save( "uberarena" ) end --self:UABroadcastChat function PLUGIN:UABroadcastChat(msg) rust.BroadcastChat("uberArena", msg) end function PLUGIN:UArenaDebug(netuser) print("ArenaTock: " .. self.ArenaTock) end function PLUGIN:ModifyDamage(takedamage, damage) if (self.FriendlyFire == "off") then if (damage.attacker.client) then if (takedamage:GetComponent("HumanController")) and (not(self.CanQueue)) then local victimID = rust.GetUserID(damage.victim.client.netUser) local attackerID = rust.GetUserID(damage.attacker.client.netUser) if (not(victimID == attackerID)) then if (self.Roster[victimID].Team == self.Roster[attackerID].Team) then damage.amount = 0 return damage end end end end end local objectloc = takedamage.gameObject:GetComponent("Transform").position if (self.BorderActive) and ((takedamage:GetComponent("StructureComponent")) or (takedamage:GetComponent("DeployableObject"))) then if (objectloc.x > self.Config.Border[1].x) and (objectloc.x < self.Config.Border[2].x) and (objectloc.z < self.Config.Border[1].z) and (objectloc.z > self.Config.Border[2].z) then damage.amount = 0 end return damage end end function PLUGIN:UArenaCommands(netuser, cmd, args) if (args[1] == "status") then if (self.ArenaOn) and (self.CanQueue) then 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!") return elseif (self.ArenaOn) then rust.SendChatToUser(netuser, "There is a match in progress.") rust.SendChatToUser(netuser, "There are " .. self.Team[1] .. " players alive on team one and") rust.SendChatToUser(netuser, "There are " .. self.Team[2] .. " players alive on team two!") rust.SendChatToUser(netuser, "Time Left: " .. (self.MatchTime - self.ArenaTock) .. " seconds remaining!") return else rust.SendChatToUser (netuser, "The arena is currently disabled!") return end elseif (args[1] == "info") then rust.SendChatToUser(netuser, "uberArena by " .. self.Author .. ". Running version " .. tostring(self.Version) .. ".") if (self.EconExists) and (self.EntranceFee ~= 0) then rust.SendChatToUser(netuser, "It costs $" .. Self.EntranceFee .. " to join the queue!") end --rust.SendChatToUser(netuser, "Current game mode: " .. self.GameMode .. ".") elseif (args[1] == "help") then rust.SendChatToUser(netuser, "/ua status to see the arenas' current status") rust.SendChatToUser(netuser, "/jt 1 or 2 to join a team while the queue is active") rust.SendChatToUser(netuser, "/leaveq to leave the queue") rust.SendChatToUser(netuser, "Be sure to clear your inventory before you join the queue!") return end value = self.MatchTime - self.ArenaTock end function PLUGIN:AdminUArenaCommands (netuser, cmd, args) if (netuser:CanAdmin()) or (self.oxminInstalled and (oxmin_Plugin:HasFlag(netuser, self.FLAG_UAControls, false) or oxmin_Plugin:HasFlag(netuser, self.FLAG_UAonoff, false))) then if (args[1] == "arena") then if (args[2] == "on") then if (not(self.ArenaOn)) then self.CanQueue = true self.ArenaOn = true --self.ArenaTimer = timer.Repeat(1, 0, function() self:ArenaTick() end ) self.ArenaTock = 0 self:UArenaConfigPull() rust.SendChatToUser (netuser, "The uberArena is on!") return else rust.SendChatToUser (netuser,"The uberArena is already on!") return end elseif (args[2] == "off") then if (self.ArenaOn) and (self.CanQueue) then self.ArenaOn = nil rust.SendChatToUser (netuser, "The uberArena is off!") return elseif (self.ArenaOn) then self.ArenaOn = nil rust.SendChatToUser (netuser, "It will be disabled after the match ends!") return end else rust.SendChatToUser(netuser, "You must turn it on or off! Not " .. args[2]) return end end end if (netuser:CanAdmin()) or (self.oxminInstalled and oxmin_Plugin:HasFlag(netuser, self.FLAG_UAControls, false)) then if (args[1] == "debug") then self:UArenaDebug(netuser) return elseif (args[1] == "onbydefault") then if (args[2]) == "true" then rust.SendChatToUser(netuser, "Changed setting onbydefault to true. Was " .. tostring(self.Config.OnByDefault) .. "!") self.Config.OnByDefault = true config.Save("uberarena") return elseif (args[2] == "false") then rust.SendChatToUser(netuser, "Changed setting onbydefault to false. Was " .. self.Config.OnByDefault .. "!") self.Config.OnByDefault = true config.Save("uberarena") return else rust.SendChatToUser(netuser, "onbydefault must be true or false") return end elseif (args[1] == "reset") then if (self.ArenaOn) and (self.CanQueue) then self:ForceEnd("admin", netuser) self.CanQueue = true self.ArenaOn = true self.ArenaTock = 0 self:UArenaConfigPull() rust.SendChatToUser (netuser, "The uberArena is off!") return end elseif (args[1] == "forceoff") then if (self.ArenaOn) and (not(self.CanQueue)) then self:UArenaDebug(netuser) self:ForceEnd("admin", netuser) rust.SendChatToUser(netuser, "Arena forced off!") return else rust.SendChatToUser(netuser, "Arena doesn't need to be forced off!") return end elseif (args[1] == "friendlyfire") then if (args[2] == "on") or (args[2] == "off") then rust.SendChatToUser(netuser, "friendlyfire changed to " .. args[2] .. ". Was " .. self.Config.FriendlyFire .. ". Will apply after next match!") self.Config.FriendlyFire = args[2] config.Save("uberarena") return else rust.SendChatToUser(netuser, "friendly fire must be set to on or off") return end elseif (args[1] == "queuetime") then if (args[2]) then rust.SendChatToUser(netuser, "queuetime changed to " .. tonumber(args[2]) .. ". Was " .. self.Config.QueueTime .. ". Will apply after next match!") self.Config.QueueTime = tonumber(args[2]) config.Save("uberarena") return else rust.SendChatToUser(netuser, "Value required (in seconds)!") return end elseif (args[1] == "minplayer") then if ((tonumber(args[2]) > 1) and (tonumber(args[2]) < self.Config.MaxPlayer)) then rust.SendChatToUser(netuser, "minplayer changed to " .. tonumber(args[2]) .. ". Was " .. self.Config.MinPlayer .. ". Will apply after next match!") self.Config.MinPlayer = tonumber(args[2]) config.Save("uberarena") return elseif (tonumber(args[2]) > self.Config.MaxPlayer) then rust.SendChatToUser(netuser, "Must be lower than maxplayer(" .. self.Config.MaxPlayer .. ")!") return else rust.SendChatToUser(netuser, "Must be a number") return end elseif (args[1] == "maxplayer") then if (args[2]) and (tonumber(args[2]) > self.Config.MinPlayer) then rust.SendChatToUser(netuser, "maxplayer changed to " .. tonumber(args[2]) .. ". Was " .. self.Config.MaxPlayer .. ". Will apply after next match!") self.ConfigMinPlayer = tonumber(args[2]) self.SaveConfigFile() return elseif (args[2]) and (tonumber(args[2]) < self.Config.MinPlayer) then rust.SendChatToUser(netuser, "Must be higher than minplayer(" .. self.Config.MinPlayer .. ")!") return else rust.SendChatToUser(netuser, "Must be a number") return end elseif (args[1] == "spawn") then if (args[2]) and (tonumber(args[2]) < 3) then rust.SendChatToUser(netuser, "Team " .. tonumber(args[2]) .. " spawn set!") self:UArenaSetSpawn(netuser, tonumber(args[2])) return else rust.SendChatToUser(netuser, "Can set team 1 or 2") return end elseif (args[1] == "reward") then if ((args[2] == "cash") and (self.EconExists)) then rust.SendChatToUser(netuser, "Cash reward set to $" .. tonumber(args[3]) .. "!") self.Reward["cash"] = tonumber(args[3]) config.Save("uberarena") return elseif ((args[2] == "coin") and (self.BCoinExists)) then self.Reward["coin"] = tonumber(args[3]) rust.SendChatToUser(netuser, "Coin reward set to " .. tonumber(args[3]) .. "!") config.Save("uberarena") return elseif (rust.GetDatablockByName(args[2])) then if (args[3] == "remove") and (self.Reward[args[2]]) then rust.SendChatToUser(netuser, args[2] .. " removed from rewards list!") self.Reward[args[2]] = nil return else rust.SendChatToUser (netuser, "Reward " .. args[2] .. " in quantity " .. tonumber(args[3]) .. " was added to the reward list!") self.Config.Reward[args[2]] = tonumber(args[3]) config.Save("uberarena") return end else rust.SendChatToUser(netuser, "Improper syntax.") return end elseif (args[1] == "minplayerreward") then if (args[2]) and (tonumber(args[2]) > 0) then rust.SendChatToUser(netuser, "minplayerreward changed to " .. tonumber(args[2]) .. ". Was " .. self.Config.MinPlayerReward .. ". Will apply after next match!") self.Config.MinPlayerReward = tonumber(args[2]) config.Save("uberarena") return else rust.SendChatToUser(netuser, "minplayerreward must be greater than 1") return end elseif (args[1] == "matchlimit") then if (args[2]) and (tonumber(args[2]) == 0) then rust.SendChatToUser(netuser, "matchlimit disabled! Will apply after next match!") self.Config.MatchTime = 0 config.Save("uberarena") return elseif (args[2]) and (tonumber(args[2]) > 0) then rust.SendChatToUser(netuser, "matchlimit set to " .. tonumber(args[2]) .. ". Will apply after next match!") self.Config.MatchTime = tonumber(args[2]) config.Save("uberarena") return else rust.SendChatToUser(netuser, "Match time limit (in seconds). Setting it to 0 will remove timelimit!") return end elseif (args[1] == "arenaalert") then if (args[2]) and (tonumber(args[2])) then rust.SendChatToUser(netuser, "arenaalert set to " .. tonumber(args[2]) .. ". Was " .. self.Config.AlertTime .. ". Will apply after next match!") self.Config.AlertTime = tonumber(args[2]) config.Save("uberarena") return end elseif (args[1] == "randomteams") then if (self.RandomTeams == true) then self.Config.RandomTeams = false elseif (self.RandomTeams == false) then self.Config.RandomTeams = true end rust.SendChatToUser(netuser, "randomteams toggled to " .. tostring(self.Config.RandomTeams) .. ". Will apply after next match!") config.Save("uberarena") return elseif (args[1] == "setloadout") and (self.Team[tonumber(args[2])]) then for i, v in pairs(self.LoadOut) do if (args[3] == i) then self.LoadoutAssignments[tonumber(args[2])] = args[3] rust.SendChatToUser(netuser, "Team " .. args[2] .. "'s loadout changed to " .. args[3] .. "!") return end end elseif (args[1] == "entrancefee") and (self.EconExists) and (tonumber(args[2])) then self.Config.EntranceFee = tonumber(args[2]) config.Save("uberarena") rust.SendChatToUser(netuser, "entrancefee set to " .. args[2] .. ". Was " .. self.EntranceFee .. ". Will apply after next match!") elseif (args[1] == "bcentrancefee") and (self.BCoinExists) and (tonumber(args[2])) then self.Config.BCEntranceFee = tonumber(args[2]) config.Save("uberarena") rust.SendChatToUser(netuser, "bcentrancefee set to " .. args[2] .. ". Was " .. self.BCEntranceFee .. ". Will apply after next match!") elseif (args[1] == "spamchat") then if (self.SpamChat == true) then self.Config.SpamChat = false elseif (self.SpamChat == false) then self.Config.SpamChat = true end rust.SendChatToUser(netuser, "spamchat toggled to " .. tostring(self.Config.RandomTeams) .. ". Will apply after next match!") config.Save("uberarena") return elseif (args[1] == "border1") then local Borderset = {} self.Border1 = {} local current_coords = netuser.playerClient.lastKnownPosition; Borderset.x = current_coords.x Borderset.y = current_coords.y Borderset.z = current_coords.z self.Border1 = Borderset rust.SendChatToUser(netuser, "Border 1 set!") elseif (args[1] == "border2") then local Borderset = {} self.Border2 = {} local current_coords = netuser.playerClient.lastKnownPosition; Borderset.x = current_coords.x Borderset.y = current_coords.y Borderset.z = current_coords.z self.Border2 = Borderset rust.SendChatToUser(netuser, "Border 2 set!") elseif (args[1] == "bindborders") then if (self.Border1) and (self.Border2) then if (self.Border1.x > self.Border2.x) then local Borderxexchange = self.Border1.x self.Border1.x = self.Border2.x self.Border2.x = Borderxexchange end if (self.Border1.z < self.Border2.z) then local Borderzexchange = self.Border1.z self.Border1.z = self.Border2.z self.Border2.z = Borderzexchange end self.Config.Border[1] = self.Border1 self.Config.Border[2] = self.Border2 self.BorderActive = true config.Save("uberarena") rust.SendChatToUser(netuser, "Borders bound!") end else rust.SendChatToUser(netuser, "Invalid command") return end else rust.SendChatToUser (netuser, "You must be logged in as an admin to do this!") end end function PLUGIN:UAStatusCommands(netuser, cmd, args) if (args[1]) then if (netuser:CanAdmin()) or (self.oxminInstalled and oxmin_Plugin:HasFlag(netuser, self.FLAG_UAControls, false)) then local oldsetting = "derp" local newsetting = "derp" local arenastatus = "for next match" local proceed = false if (self.ArenaOn) and (not(self.CanQueue)) then arenastatus = "for current match" end if (args[1] == "randomteams") then oldsetting = self.RandomTeams newsetting = self.Config.RandomTeams elseif (args[1] == "minplayer") then newsetting = self.Config.MinPlayer oldsetting = self.MinPlayer elseif (args[1] == "maxplayer") then newsetting = self.Config.MaxPlayer oldsetting = self.MaxPlayer elseif (args[1] == "queuetime") then newsetting = self.Config.QueueTime oldsetting = self.QueueTime elseif (args[1] == "arenaalert") then newsetting = self.Config.AlertTime oldsetting = self.AlertTime elseif (args[1] == "minplayerreward") then newsetting = self.Config.MinPlayerReward oldsetting = self.MinPlayerReward elseif (args[1] == "matchlimit") then newsetting = self.Config.MatchTime oldsetting = self.MatchTime - self.QueueTime elseif (args[1] == "friendlyfire") then newsetting = self.Config.FriendlyFire oldsetting = self.FriendlyFire elseif (args[1] == "loadout") then for i, v in pairs(self.LoadoutAssignments) do rust.SendChatToUser(netuser, "Team " .. i .. "'s loadout: " .. v .. "!") end return elseif (args[1] == "entrancefee") then newsetting = self.Config.EntranceFee oldsetting = self.EntranceFee elseif (args[1] == "bcentrancefee") then newsetting = self.Config.BCEntranceFee oldsetting = self.BCEntranceFee elseif (args[1] == "spamchat") then newsetting = self.Config.SpamChat oldsetting = self.SpamChat elseif (args[1] == "borders") then if (self.BorderActive) then rust.SendChatToUser(netuser, "Borders are active!") else rust.SendChatToUser(netuser, "Borders are not active!") end return end if (tostring(oldsetting)) and (tostring(newsetting)) then if (tostring(oldsetting) == tostring(newsetting)) then rust.SendChatToUser(netuser, "Status " .. tostring(arenastatus) .. " is " .. args[1] .. ": " .. tostring(oldsetting) .. "!") return else rust.SendChatToUser(netuser, "Status " .. tostring(arenastatus) .. " is " .. args[1] .. ": " .. tostring(oldsetting) .. ". Will be " .. tostring(newsetting) .. " the match after that!") end else end end else rust.SendChatToUser(netuser, "Requires a setting. use /ua status for the arena's status") end end