Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PLUGIN.Title = "Airdrops"
- PLUGIN.Description = "Temporary hotfix for Rust's broken Airdrops"
- PLUGIN.Version = V(1, 1, 3)
- PLUGIN.Author = "BedIntruder319"
- PLUGIN.HasConfig = true
- Parachutes = {}
- function PLUGIN:Init()
- print("-----------------------------")
- print("Airdrops: Loaded Successfully")
- print("-----------------------------")
- Parachutes = {}
- self:CheckConfig()
- command.AddChatCommand("airdrop", self.Object, "cmdAirdrop")
- command.AddChatCommand("removeparalol", self.Object, "cmdRemovePAra")
- timer.Repeat(self.Config.Settings.SupplyDropDelayInSeconds, 0, function() self:SpawnSupplies(nil, nil) end)
- end
- function PLUGIN:cmdRemovePAra(player, com, args)
- parachutes = UnityEngine.Object.FindObjectsOfTypeAll( global.BaseEntity._type )
- for i = 0, parachutes.Length - 1 do
- if parachutes[i].model then
- if tostring( parachutes[i] ):find("parachute") then
- parachutes[i]:KillMessage()
- end
- end
- end
- end
- function PLUGIN:InitializeTable()
- self.Table = {}
- local itemlist = global.ItemManager.GetItemDefinitions();
- local it = itemlist:GetEnumerator()
- while (it:MoveNext()) do
- local correctname = string.lower(it.Current.displayname)
- self.Table[correctname] = tostring(it.Current.shortname)
- --print(string.lower(it.Current.displayname) .. "|" .. tostring(it.Current.shortname))
- end
- end
- function PLUGIN:OnEntitySpawn(entity)
- if (self.Config.Settings.PreventRustAirdrops) then
- if (entity:GetComponentInParent(global.CargoPlane._type)) then
- print(self.Config.ChatSettings.ChatName .. ": " .. self.Config.ChatSettings.RustAirdropPrevented)
- entity:GetComponent("BaseEntity"):KillMessage()
- end
- end
- end
- function PLUGIN:cmdAirdrop(player, com, args)
- if (player:GetComponent("BaseNetworkable").net.connection.authLevel == self.Config.Settings.RequiredAuthenticationLevel) then
- if (args.Length == 0) then
- self:SpawnSupplies(nil, nil)
- elseif (args.Length == 1) then
- local targetPlayer = self:FindPlayerByName(args[0])
- if (#targetPlayer == 0) then
- player:SendConsoleCommand("chat.add \"" .. self.Config.ChatSettings.ChatName .. "\" \"" .. self.Config.ChatSettings.NoPlayerFoundFromName .. "\"")
- return
- elseif(#targetPlayer > 1) then
- player:SendConsoleCommand("chat.add \"" .. self.Config.ChatSettings.ChatName .. "\" \"" .. self.Config.ChatSettings.MultiplePlayersFoundFromName .. "\"")
- return
- else
- local target = targetPlayer[1]
- self:SpawnSupplies(math.floor(target.transform.position.x), math.floor(target.transform.position.z))
- end
- elseif (args.Length == 2) then
- if (tonumber(args[0]) and tonumber(args[1])) then
- self:SpawnSupplies(tonumber(args[0]), tonumber(args[1]))
- else
- player:SendConsoleCommand("chat.add \"" .. self.Config.ChatSettings.ChatName .. "\" \"" .. self.Config.ChatSettings.InvalidCoordiantes .. "\"")
- end
- else
- player:SendConsoleCommand("chat.add \"" .. self.Config.ChatSettings.ChatName .. "\" \"" .. self.Config.ChatSettings.InvalidCommandUsage .. "\"")
- end
- end
- end
- function PLUGIN:FindPlayerByName(playerName)
- if not playerName then return end
- playerName = string.lower(playerName)
- local matches = {}
- local itPlayerList = global.BasePlayer.activePlayerList:GetEnumerator()
- while itPlayerList:MoveNext() do
- local displayName = string.lower(itPlayerList.Current.displayName)
- if string.find(displayName, playerName, 1, true) then
- table.insert(matches, itPlayerList.Current)
- end
- end
- return matches
- end
- function PLUGIN:SpawnSupplies(x, z)
- local destination = new(UnityEngine.Vector3._type, nil)
- if (x == nil) then
- destination.x = math.random(self.Config.Settings.MinimumXCoord, self.Config.Settings.MaximumXCoord)
- else
- destination.x = x
- end
- destination.y = 500
- if (z == nil) then
- destination.z = math.random(self.Config.Settings.MinimumZCoord, self.Config.Settings.MaximumZCoord)
- else
- destination.z = z
- end
- local quaternion = new(UnityEngine.Quaternion._type, nil)
- quaternion.x = 0
- quaternion.y = 0
- quaternion.z = 0
- local Supply_Drop = global.GameManager.CreateEntity("items/supply_drop", destination, quaternion)
- Supply_Drop:Spawn(true)
- local Parachute = global.GameManager.CreateEntity("parachute", destination, quaternion)
- if Parachute then
- Parachute:SetParent(Supply_Drop, "parachute_attach")
- Parachute:Spawn(true)
- local ParachuteTimer = timer.Once(110, function() self:DestroyParachute(Parachute, Supply_Drop) end)
- local ParachuteInfo = {Parachute, Parachute.transform.position, ParachuteTimer}
- table.insert(Parachutes, ParachuteInfo)
- end
- if (self.Config.ChatSettings.ShowChatNotifications) then
- print(self.Config.ChatSettings.ChatName .. self.Config.ChatSettings.AirdropOccuring .. " " .. destination.x .. ", " .. destination.z)
- global.ConsoleSystem.Broadcast("chat.add \"" .. self.Config.ChatSettings.ChatName .. "\" \"" .. self.Config.ChatSettings.AirdropOccuring .. " " .. destination.x .. ", " .. destination.z .. "\"")
- end
- end
- function PLUGIN:DestroyParachute(parachute, supplydrop)
- if parachute then
- parachute:KillMessage()
- Parachutes = {}
- end
- end
- function PLUGIN:OnPlayerAttack(player, hitinfo)
- if(not self.Table) then self:InitializeTable() end
- if (player.svActiveItem) then
- local hasTool = false
- local weapon = player.svActiveItem.info.displayname
- for _,toolName in pairs(self.Config.Settings.LootTools) do
- if (string.lower(toolName) == string.lower(weapon)) then
- hasTool = true
- end
- end
- if (hasTool) then
- if (hitinfo.HitEntity) then
- if (hitinfo.HitEntity:GetComponentInParent(global.SupplyDrop._type)) then
- hitinfo.HitEntity:GetComponent("BaseEntity"):KillMessage()
- local inv = player.inventory
- local pref = inv.containerMain
- local supplies = self.Config.AirdropSupplies
- for _,supplyItem in pairs(supplies) do
- local name = supplyItem["name"]
- local minAmount = supplyItem["minAmount"]
- local maxAmount = supplyItem["maxAmount"]
- local probability = supplyItem["probability"]
- local value = math.random(minAmount, maxAmount);
- local getItem = math.random(0, 100)
- local name2 = string.lower(name)
- local itemname = self.Table[name2]
- if (getItem <= probability) then
- local item = global.ItemManager.CreateByName(itemname, value)
- if not item then
- return
- end
- inv:GiveItem(item, pref)
- end
- end
- end
- end
- end
- end
- end
- function PLUGIN:Unload()
- Parachutes = {}
- end
- function PLUGIN:LoadDefaultConfig()
- self.Config.PluginSettings = {
- Title = "Airdrops",
- Version = "1.1.3"
- }
- self.Config.Settings = {
- RequiredAuthenticationLevel = 2,
- PreventRustAirdrops = true,
- LootTools = {
- "Salvaged Axe",
- "Hammer",
- "Salvaged Hammer",
- "Hatchet",
- "Salvaged Icepick",
- "Pick Axe",
- "Rock",
- "Stone Hatchet"
- },
- SupplyDropDelayInSeconds = 1800,
- MinimumXCoord = -114,
- MaximumXCoord = 293,
- MinimumZCoord = -178,
- MaximumZCoord = 42
- }
- self.Config.ChatSettings = {
- ChatName = "Airdrops",
- ShowChatNotifications = true,
- RustAirdropPrevented = "A Rust default airdrop event was prevented",
- NoPlayerFoundFromName = "Could not find a player from provided name",
- MultiplePlayersFoundFromName = "Found multiple players with this name or partial",
- InvalidCoordiantes = "The given coordinates are invalid",
- InvalidCommandUsage = "Invalid command usage: /airdrop (x) (z)",
- AirdropOccuring = "An airdrop is occurring at"
- }
- self.Config.AirdropSupplies = {
- {
- ["name"] = "Pistol Bullet",
- ["minAmount"] = 250,
- ["maxAmount"] = 500,
- ["probability"] = 80
- },
- {
- ["name"] = "Revolver",
- ["minAmount"] = 1,
- ["maxAmount"] = 1,
- ["probability"] = 90
- },
- {
- ["name"] = "Thompson",
- ["minAmount"] = 1,
- ["maxAmount"] = 1,
- ["probability"] = 25
- },
- {
- ["name"] = "Cooked Human Meat",
- ["minAmount"] = 20,
- ["maxAmount"] = 40,
- ["probability"] = 90
- },
- {
- ["name"] = "Wood",
- ["minAmount"] = 10000,
- ["maxAmount"] = 25000,
- ["probability"] = 100
- },
- {
- ["name"] = "Stones",
- ["minAmount"] = 7500,
- ["maxAmount"] = 15000,
- ["probability"] = 100
- },
- {
- ["name"] = "Metal Fragments",
- ["minAmount"] = 500,
- ["maxAmount"] = 1500,
- ["probability"] = 75
- },
- }
- end
- function PLUGIN:CheckConfig()
- if self.Config.PluginSettings.Version ~= "1.1.3" then
- self:UpdateConfig()
- end
- end
- function PLUGIN:UpdateConfig()
- self:LoadDefaultConfig()
- self:SaveConfig()
- print("Airdrops: Default configuration file loaded")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement