refactor: GM loadouts helpers

fix: crash if player doesn't have arc9 or mw weapons installed
This commit is contained in:
Jonny_Bro (Nikita) 2025-02-18 00:24:50 +05:00
parent 4e6630d974
commit 32ac04d317
7 changed files with 80 additions and 79 deletions

View file

@ -2,7 +2,7 @@ local OldAnims = CreateClientConVar("Beatrun_OldAnims", "0", true, false, "")
local AutoHandSwitching = CreateClientConVar("Beatrun_AutoHandSwitching", "1", true, false) local AutoHandSwitching = CreateClientConVar("Beatrun_AutoHandSwitching", "1", true, false)
-- Animations that use arms for auto hand switching -- Animations that use arms for auto hand switching
local requires_arms = { local requiresArms = {
hang = true, hang = true,
hanghardstartvertical = true, hanghardstartvertical = true,
hangheaveup = true, hangheaveup = true,
@ -1520,22 +1520,22 @@ end)
local animtr, animtr_result = nil, nil local animtr, animtr_result = nil, nil
local oldnewang = Angle() local oldnewang = Angle()
local using_hands = false local usingHands = false
local weapon_before_hands local lastWeapon
local function JumpThink() local function JumpThink()
local ply = LocalPlayer() local ply = LocalPlayer()
if AutoHandSwitching:GetBool() and ply:Alive() and IsValid(ply:GetWeapon("runnerhands")) then -- Auto hand switching part if AutoHandSwitching:GetBool() and ply:Alive() and IsValid(ply:GetWeapon("runnerhands")) then -- Auto hand switching part
if (ply:GetWallrun() == 1 or ply:GetMantle() > 1 or IsValid(ply:GetZipline()) or IsValid(ply:GetLadder()) or IsValid(ply:GetSwingbar()) or requires_arms[BodyAnimString]) and not using_hands and not ply:UsingRH() then if (ply:GetWallrun() == 1 or ply:GetMantle() > 1 or IsValid(ply:GetZipline()) or IsValid(ply:GetLadder()) or IsValid(ply:GetSwingbar()) or requiresArms[BodyAnimString]) and not usingHands and not ply:UsingRH() then
weapon_before_hands = ply:GetActiveWeapon() lastWeapon = ply:GetActiveWeapon()
input.SelectWeapon(ply:GetWeapon("runnerhands")) input.SelectWeapon(ply:GetWeapon("runnerhands"))
using_hands = true usingHands = true
if ply:GetWallrun() == 1 then -- 1 = verticaL if ply:GetWallrun() == 1 then -- 1 = verticaL
BodyLimitX = 25 -- fixes a bug where if u look behind u will vault over air BodyLimitX = 25 -- Fixes a bug where if u look behind u will vault over air
BodyLimitY = 70 BodyLimitY = 70
BodyAnim:SetSequence("wallrunverticalstart") BodyAnim:SetSequence("wallrunverticalstart")
@ -1550,12 +1550,13 @@ local function JumpThink()
if IsValid(ply:GetZipline()) then BodyAnim:SetSequence("zipline") end if IsValid(ply:GetZipline()) then BodyAnim:SetSequence("zipline") end
end end
if using_hands and not ply:UsingRH() then input.SelectWeapon(ply:GetWeapon("runnerhands")) end --blocks weapon switching -- Blocks weapon switching
if usingHands and not ply:UsingRH() then input.SelectWeapon(ply:GetWeapon("runnerhands")) end
if ply:GetWallrun() == 0 and not requires_arms[BodyAnimString] and ply:GetMantle() == 0 and not IsValid(ply:GetLadder()) and not IsValid(ply:GetSwingbar()) and using_hands and not IsValid(ply:GetZipline()) and ply:UsingRH() then if ply:GetWallrun() == 0 and not requiresArms[BodyAnimString] and ply:GetMantle() == 0 and not IsValid(ply:GetLadder()) and not IsValid(ply:GetSwingbar()) and usingHands and not IsValid(ply:GetZipline()) and ply:UsingRH() then
if IsValid(weapon_before_hands) then input.SelectWeapon(weapon_before_hands) end if IsValid(lastWeapon) then input.SelectWeapon(lastWeapon) end
using_hands = false usingHands = false
end end
end end

View file

@ -2,6 +2,7 @@ local meta = FindMetaTable("Player")
local metavec = FindMetaTable("Vector") local metavec = FindMetaTable("Vector")
local PUNCH_DAMPING = 9 local PUNCH_DAMPING = 9
local PUNCH_SPRING_CONSTANT = 120 local PUNCH_SPRING_CONSTANT = 120
local viewbob_intensity = CreateClientConVar("Beatrun_ViewbobIntensity", "20", true, true, language.GetPhrase("beatrun.convars.viewbob"), -100, 100) local viewbob_intensity = CreateClientConVar("Beatrun_ViewbobIntensity", "20", true, true, language.GetPhrase("beatrun.convars.viewbob"), -100, 100)
local viewbob_stabilized = CreateClientConVar("Beatrun_ViewbobStabilized", "0", true, true, language.GetPhrase("beatrun.convars.viewbobstabilization"), 0, 1) local viewbob_stabilized = CreateClientConVar("Beatrun_ViewbobStabilized", "0", true, true, language.GetPhrase("beatrun.convars.viewbobstabilization"), 0, 1)
@ -22,17 +23,17 @@ function metavec:Approach(x, y, z, speed)
end end
local function CLViewPunchThink() local function CLViewPunchThink()
local self = LocalPlayer() local plr = LocalPlayer()
if not self.ViewPunchVelocity then if not plr.ViewPunchVelocity then
self.ViewPunchVelocity = Angle() plr.ViewPunchVelocity = Angle()
self.ViewPunchAngle = Angle() plr.ViewPunchAngle = Angle()
end end
local vpa = self.ViewPunchAngle local vpa = plr.ViewPunchAngle
local vpv = self.ViewPunchVelocity local vpv = plr.ViewPunchVelocity
if not self.ViewPunchDone and lensqr(vpa) + lensqr(vpv) > 1e-06 then if not plr.ViewPunchDone and lensqr(vpa) + lensqr(vpv) > 1e-06 then
local FT = FrameTime() local FT = FrameTime()
vpa = vpa + vpv * FT vpa = vpa + vpv * FT
local damping = 1 - PUNCH_DAMPING * FT local damping = 1 - PUNCH_DAMPING * FT
@ -48,10 +49,10 @@ local function CLViewPunchThink()
vpa[1] = math.Clamp(vpa[1], -89.9, 89.9) vpa[1] = math.Clamp(vpa[1], -89.9, 89.9)
vpa[2] = math.Clamp(vpa[2], -179.9, 179.9) vpa[2] = math.Clamp(vpa[2], -179.9, 179.9)
vpa[3] = math.Clamp(vpa[3], -89.9, 89.9) vpa[3] = math.Clamp(vpa[3], -89.9, 89.9)
self.ViewPunchAngle = vpa plr.ViewPunchAngle = vpa
self.ViewPunchVelocity = vpv plr.ViewPunchVelocity = vpv
else else
self.ViewPunchDone = true plr.ViewPunchDone = true
end end
end end

View file

@ -11,10 +11,10 @@ local function World_Whitescale()
local propmats = ents.FindByClass("prop_dynamic") local propmats = ents.FindByClass("prop_dynamic")
local dupeprops = {} local dupeprops = {}
for k, v in pairs(propmats) do for _, v in pairs(propmats) do
if dupeprops[v:GetModel()] then continue end if dupeprops[v:GetModel()] then continue end
for k, v in pairs(v:GetMaterials()) do for _, v in pairs(v:GetMaterials()) do
table.insert(worldmats, v) table.insert(worldmats, v)
end end

View file

@ -124,7 +124,7 @@ end
function PLAYER:Loadout() function PLAYER:Loadout()
if GetGlobalBool("GM_DATATHEFT") or GetGlobalBool("GM_DEATHMATCH") then if GetGlobalBool("GM_DATATHEFT") or GetGlobalBool("GM_DEATHMATCH") then
Beatrun_GiveGMWeapon(self.Player) BeatrunGiveGMLoadout(self.Player)
else else
self.Player:RemoveAllAmmo() self.Player:RemoveAllAmmo()
end end
@ -275,11 +275,9 @@ hook.Add("IsSpawnpointSuitable", "CheckSpawnPoint", function(ply, spawnpointent,
end) end)
hook.Add("SetupMove", "SpawnFreeze", function(ply, mv, cmd) hook.Add("SetupMove", "SpawnFreeze", function(ply, mv, cmd)
if ply.SpawnFreezeTime and Course_Name ~= "" and Course_StartPos ~= vector_origin then if ply.SpawnFreezeTime and Course_Name ~= "" and Course_StartPos ~= vector_origin and Course_StartPos and ply.SpawnFreezeTime > CurTime() then
if Course_StartPos and ply.SpawnFreezeTime > CurTime() then
mv:SetOrigin(Course_StartPos) mv:SetOrigin(Course_StartPos)
end end
end
end) end)
hook.Add("ShouldCollide", "NoPlayerCollisions", function(ent1, ent2) hook.Add("ShouldCollide", "NoPlayerCollisions", function(ent1, ent2)

View file

@ -4,8 +4,10 @@ local playermeta = FindMetaTable("Player")
CreateConVar("Beatrun_RandomMWLoadouts", 0, {FCVAR_REPLICATED, FCVAR_ARCHIVE}) CreateConVar("Beatrun_RandomMWLoadouts", 0, {FCVAR_REPLICATED, FCVAR_ARCHIVE})
CreateConVar("Beatrun_RandomARC9Loadouts", 0, {FCVAR_REPLICATED, FCVAR_ARCHIVE}) CreateConVar("Beatrun_RandomARC9Loadouts", 0, {FCVAR_REPLICATED, FCVAR_ARCHIVE})
-- Example loadouts. You can put any SWEP's class name here.
BEATRUN_GAMEMODES_LOADOUTS = { BEATRUN_GAMEMODES_LOADOUTS = {
{"weapon_357", "weapon_ar2"} {"weapon_357", "weapon_ar2"},
{"weapon_pistol", "weapon_smg1"}
} }
local mtmp = { local mtmp = {
@ -17,9 +19,11 @@ local mtmp = {
function vmatrixmeta:FastToTable(tbl) function vmatrixmeta:FastToTable(tbl)
tbl = tbl or table.Copy(mtmp) tbl = tbl or table.Copy(mtmp)
local tbl1 = tbl[1] local tbl1 = tbl[1]
local tbl2 = tbl[2] local tbl2 = tbl[2]
local tbl3 = tbl[3] local tbl3 = tbl[3]
tbl1[1], tbl1[2], tbl1[3], tbl1[4], tbl2[1], tbl2[2], tbl2[3], tbl2[4], tbl3[1], tbl3[2], tbl3[3], tbl3[4] = self:Unpack() tbl1[1], tbl1[2], tbl1[3], tbl1[4], tbl2[1], tbl2[2], tbl2[3], tbl2[4], tbl3[1], tbl3[2], tbl3[3], tbl3[4] = self:Unpack()
return tbl return tbl
@ -74,66 +78,63 @@ end
function playermeta:UsingRH(wep) function playermeta:UsingRH(wep)
wep = wep or self:GetActiveWeapon() wep = wep or self:GetActiveWeapon()
if IsValid(wep) and wep:GetClass() == "runnerhands" then if IsValid(wep) and wep:GetClass() == "runnerhands" then return true
return true else return false end
end
function BeatrunGiveAmmo(ply, wep)
if wep:GetPrimaryAmmoType() ~= -1 then ply:GiveAmmo(10000, wep:GetPrimaryAmmoType(), true) end
if wep:GetSecondaryAmmoType() ~= -1 then ply:GiveAmmo(5, wep:GetSecondaryAmmoType(), true) end
end
local depth = 0
function BeatrunGetRandomMWSWEP()
local allWeps = weapons.GetList()
local swep = allWeps[math.random(#allWeps)]
if swep.Base == "mg_base" and not swep.AdminOnly then return swep.ClassName
else else
return false if depth > 5 then
depth = 0
return
end
depth = depth + 1
BeatrunGetRandomMWSWEP()
end end
end end
function Beatrun_GiveAmmo(weapon, ply) function BeatrunGetRandomARCSWEP()
if weapon:GetPrimaryAmmoType() ~= -1 then ply:GiveAmmo(10000, weapon:GetPrimaryAmmoType(), true) end local allWeps = weapons.GetList()
if weapon:GetSecondaryAmmoType() ~= -1 then ply:GiveAmmo(5, weapon:GetSecondaryAmmoType(), true) end local swep = allWeps[math.random(#allWeps)]
end
function Beatrun_getRandomMWBaseSWEP() if swep.Base == "arc9_cod2019_base" and not swep.AdminOnly then return swep.ClassName
local allWep = weapons.GetList()
local wepIndex = math.random(#allWep)
local wep = allWep[wepIndex]
if wep.Base == "mg_base" and not wep.AdminOnly then
return wep
else else
return Beatrun_getRandomMWBaseSWEP() if depth > 5 then
depth = 0
return
end
depth = depth + 1
BeatrunGetRandomARCSWEP()
end end
end end
function Beatrun_getRandomARC9SWEP() function BeatrunMakeLoadout()
local allWep = weapons.GetList() local arc, mw = GetConVar("Beatrun_RandomARC9Loadouts"):GetBool(), GetConVar("Beatrun_RandomMWLoadouts"):GetBool()
local wepIndex = math.random(#allWep)
local wep = allWep[wepIndex]
if wep.Base == "arc9_cod2019_base" and not wep.AdminOnly then if arc and not mw then return {BeatrunGetRandomARCSWEP(), BeatrunGetRandomARCSWEP()}
return wep elseif not arc and mw then return {BeatrunGetRandomMWSWEP(), BeatrunGetRandomMWSWEP()}
else elseif not arc and not mw then return BEATRUN_GAMEMODES_LOADOUTS[math.random(#BEATRUN_GAMEMODES_LOADOUTS)] end
return Beatrun_getRandomARC9SWEP()
end
end end
function Beatrun_GiveGMWeapon(ply) function BeatrunGiveGMLoadout(ply)
if GetConVar("Beatrun_RandomMWLoadouts"):GetBool() and not GetConVar("Beatrun_RandomARC9Loadouts"):GetBool() then local loadout = BeatrunMakeLoadout()
for _ = 0, 1 do
local swep = Beatrun_getRandomMWBaseSWEP()
local w = ply:Give(swep.ClassName)
timer.Simple(1, function() for _, v in pairs(loadout) do
Beatrun_GiveAmmo(w, ply) local wep = ply:Give(v)
end)
end
elseif GetConVar("Beatrun_RandomARC9Loadouts"):GetBool() and not GetConVar("Beatrun_RandomMWLoadouts"):GetBool() then
for _ = 0, 1 do
-- We don't need ammo because ARC9 got the infinite ammo option
local swep = Beatrun_getRandomARC9SWEP() timer.Simple(1, function() BeatrunGiveAmmo(ply, wep) end)
ply:Give(swep.ClassName)
end
elseif not GetConVar("Beatrun_RandomARC9Loadouts"):GetBool() and not GetConVar("Beatrun_RandomMWLoadouts"):GetBool() then
for _, b in ipairs(BEATRUN_GAMEMODES_LOADOUTS[math.random(#BEATRUN_GAMEMODES_LOADOUTS)]) do
local w = ply:Give(b)
timer.Simple(1, function()
Beatrun_GiveAmmo(w, ply)
end)
end
end end
end end

View file

@ -22,7 +22,7 @@ if SERVER then
v:Spawn() v:Spawn()
end end
Beatrun_GiveGMWeapon(v) BeatrunGiveGMLoadout(v)
end end
end end
@ -56,7 +56,7 @@ if SERVER then
if datacount > 0 then if datacount > 0 then
local pos = ply:GetPos() + Vector(0, 0, 32) local pos = ply:GetPos() + Vector(0, 0, 32)
for i = 1, datacount + 1 do for _ = 1, datacount + 1 do
local datacube = ents.Create("br_datacube") local datacube = ents.Create("br_datacube")
datacube:SetPos(pos) datacube:SetPos(pos)

View file

@ -17,7 +17,7 @@ if SERVER then
v:Spawn() v:Spawn()
end end
Beatrun_GiveGMWeapon(v) BeatrunGiveGMLoadout(v)
end end
end end