From 683a4352343d3678fe1939257dd6979496074634 Mon Sep 17 00:00:00 2001 From: edshot99 Date: Wed, 18 Dec 2024 22:57:06 -0600 Subject: [PATCH] move custom code from fesiug utilities into their own folders --- .../lua/autorun/server/ammo_reserves.lua | 52 +++++++++++++++++++ .../lua/autorun/server/health_and_armor.lua | 16 ++++++ 2 files changed, 68 insertions(+) create mode 100644 ammo_reserves/lua/autorun/server/ammo_reserves.lua create mode 100644 health_and_armor/lua/autorun/server/health_and_armor.lua diff --git a/ammo_reserves/lua/autorun/server/ammo_reserves.lua b/ammo_reserves/lua/autorun/server/ammo_reserves.lua new file mode 100644 index 0000000..d4fc99d --- /dev/null +++ b/ammo_reserves/lua/autorun/server/ammo_reserves.lua @@ -0,0 +1,52 @@ + +hook.Add("PlayerDeath", "edshot_AmmoReservesOnPlayerKill", function(victim, inflictor, attacker) + if attacker:IsValid() and !attacker:IsNextBot() and !attacker:IsNPC() and attacker:IsPlayer() then + local wep = attacker:GetActiveWeapon() + + if IsValid(wep) then + local wepAmmoType1 = wep:GetPrimaryAmmoType() + local wepAmmoType2 = wep:GetSecondaryAmmoType() + + if wepAmmoType1 ~= -1 then + attacker:SetAmmo( 999, wepAmmoType1 ) + end + if wepAmmoType2 ~= -1 then + attacker:SetAmmo( 99, wepAmmoType2 ) + end + end + end +end) + +hook.Add("OnNPCKilled", "edshot_AmmoReservesOnNPCKill", function(npc, attacker, inflictor) + if attacker:IsValid() and !attacker:IsNextBot() and !attacker:IsNPC() and attacker:IsPlayer() then + local wep = attacker:GetActiveWeapon() + + if IsValid(wep) then + local wepAmmoType1 = wep:GetPrimaryAmmoType() + local wepAmmoType2 = wep:GetSecondaryAmmoType() + + if wepAmmoType1 ~= -1 then + attacker:SetAmmo( 999, wepAmmoType1 ) + end + if wepAmmoType2 ~= -1 then + attacker:SetAmmo( 99, wepAmmoType2 ) + end + end + end +end) + +hook.Add("WeaponEquip", "edshot_AmmoReservesOnEquip", function(weapon, owner) + if owner:IsValid() and !owner:IsNextBot() and !owner:IsNPC() and owner:IsPlayer() then + if IsValid(weapon) then + local wepAmmoType1 = weapon:GetPrimaryAmmoType() + local wepAmmoType2 = weapon:GetSecondaryAmmoType() + + if wepAmmoType1 ~= -1 then + owner:SetAmmo( 999, wepAmmoType1 ) + end + if wepAmmoType2 ~= -1 then + owner:SetAmmo( 99, wepAmmoType2 ) + end + end + end +end) diff --git a/health_and_armor/lua/autorun/server/health_and_armor.lua b/health_and_armor/lua/autorun/server/health_and_armor.lua new file mode 100644 index 0000000..785d896 --- /dev/null +++ b/health_and_armor/lua/autorun/server/health_and_armor.lua @@ -0,0 +1,16 @@ + +hook.Add("PlayerDeath", "edshot_HealthAndArmorFromPlayer", function(victim, inflictor, attacker) + if attacker:IsValid() and !attacker:IsNextBot() and !attacker:IsNPC() and attacker:IsPlayer() then + if attacker ~= victim then + attacker:SetHealth( attacker:GetMaxHealth() ) + attacker:SetArmor( attacker:GetMaxArmor() ) + end + end +end) + +hook.Add("OnNPCKilled", "edshot_HealthAndArmorFromNPC", function(npc, attacker, inflictor) + if attacker:IsValid() and !attacker:IsNextBot() and !attacker:IsNPC() and attacker:IsPlayer() then + attacker:SetHealth( attacker:GetMaxHealth() ) + attacker:SetArmor( attacker:GetMaxArmor() ) + end +end)