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)
-- Animations that use arms for auto hand switching
local requires_arms = {
local requiresArms = {
hang = true,
hanghardstartvertical = true,
hangheaveup = true,
@ -1520,22 +1520,22 @@ end)
local animtr, animtr_result = nil, nil
local oldnewang = Angle()
local using_hands = false
local weapon_before_hands
local usingHands = false
local lastWeapon
local function JumpThink()
local ply = LocalPlayer()
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
weapon_before_hands = ply:GetActiveWeapon()
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
lastWeapon = ply:GetActiveWeapon()
input.SelectWeapon(ply:GetWeapon("runnerhands"))
using_hands = true
usingHands = true
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
BodyAnim:SetSequence("wallrunverticalstart")
@ -1550,12 +1550,13 @@ local function JumpThink()
if IsValid(ply:GetZipline()) then BodyAnim:SetSequence("zipline") 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 IsValid(weapon_before_hands) then input.SelectWeapon(weapon_before_hands) end
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(lastWeapon) then input.SelectWeapon(lastWeapon) end
using_hands = false
usingHands = false
end
end

View file

@ -2,6 +2,7 @@ local meta = FindMetaTable("Player")
local metavec = FindMetaTable("Vector")
local PUNCH_DAMPING = 9
local PUNCH_SPRING_CONSTANT = 120
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)
@ -22,17 +23,17 @@ function metavec:Approach(x, y, z, speed)
end
local function CLViewPunchThink()
local self = LocalPlayer()
local plr = LocalPlayer()
if not self.ViewPunchVelocity then
self.ViewPunchVelocity = Angle()
self.ViewPunchAngle = Angle()
if not plr.ViewPunchVelocity then
plr.ViewPunchVelocity = Angle()
plr.ViewPunchAngle = Angle()
end
local vpa = self.ViewPunchAngle
local vpv = self.ViewPunchVelocity
local vpa = plr.ViewPunchAngle
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()
vpa = vpa + vpv * 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[2] = math.Clamp(vpa[2], -179.9, 179.9)
vpa[3] = math.Clamp(vpa[3], -89.9, 89.9)
self.ViewPunchAngle = vpa
self.ViewPunchVelocity = vpv
plr.ViewPunchAngle = vpa
plr.ViewPunchVelocity = vpv
else
self.ViewPunchDone = true
plr.ViewPunchDone = true
end
end

View file

@ -11,10 +11,10 @@ local function World_Whitescale()
local propmats = ents.FindByClass("prop_dynamic")
local dupeprops = {}
for k, v in pairs(propmats) do
for _, v in pairs(propmats) do
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)
end

View file

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

View file

@ -4,8 +4,10 @@ local playermeta = FindMetaTable("Player")
CreateConVar("Beatrun_RandomMWLoadouts", 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 = {
{"weapon_357", "weapon_ar2"}
{"weapon_357", "weapon_ar2"},
{"weapon_pistol", "weapon_smg1"}
}
local mtmp = {
@ -17,9 +19,11 @@ local mtmp = {
function vmatrixmeta:FastToTable(tbl)
tbl = tbl or table.Copy(mtmp)
local tbl1 = tbl[1]
local tbl2 = tbl[2]
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()
return tbl
@ -74,66 +78,63 @@ end
function playermeta:UsingRH(wep)
wep = wep or self:GetActiveWeapon()
if IsValid(wep) and wep:GetClass() == "runnerhands" then
return true
if IsValid(wep) and wep:GetClass() == "runnerhands" then 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
return false
if depth > 5 then
depth = 0
return
end
depth = depth + 1
BeatrunGetRandomMWSWEP()
end
end
function Beatrun_GiveAmmo(weapon, ply)
if weapon:GetPrimaryAmmoType() ~= -1 then ply:GiveAmmo(10000, weapon:GetPrimaryAmmoType(), true) end
if weapon:GetSecondaryAmmoType() ~= -1 then ply:GiveAmmo(5, weapon:GetSecondaryAmmoType(), true) end
end
function BeatrunGetRandomARCSWEP()
local allWeps = weapons.GetList()
local swep = allWeps[math.random(#allWeps)]
function Beatrun_getRandomMWBaseSWEP()
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
if swep.Base == "arc9_cod2019_base" and not swep.AdminOnly then return swep.ClassName
else
return Beatrun_getRandomMWBaseSWEP()
if depth > 5 then
depth = 0
return
end
depth = depth + 1
BeatrunGetRandomARCSWEP()
end
end
function Beatrun_getRandomARC9SWEP()
local allWep = weapons.GetList()
local wepIndex = math.random(#allWep)
local wep = allWep[wepIndex]
function BeatrunMakeLoadout()
local arc, mw = GetConVar("Beatrun_RandomARC9Loadouts"):GetBool(), GetConVar("Beatrun_RandomMWLoadouts"):GetBool()
if wep.Base == "arc9_cod2019_base" and not wep.AdminOnly then
return wep
else
return Beatrun_getRandomARC9SWEP()
end
if arc and not mw then return {BeatrunGetRandomARCSWEP(), BeatrunGetRandomARCSWEP()}
elseif not arc and mw then return {BeatrunGetRandomMWSWEP(), BeatrunGetRandomMWSWEP()}
elseif not arc and not mw then return BEATRUN_GAMEMODES_LOADOUTS[math.random(#BEATRUN_GAMEMODES_LOADOUTS)] end
end
function Beatrun_GiveGMWeapon(ply)
if GetConVar("Beatrun_RandomMWLoadouts"):GetBool() and not GetConVar("Beatrun_RandomARC9Loadouts"):GetBool() then
for _ = 0, 1 do
local swep = Beatrun_getRandomMWBaseSWEP()
local w = ply:Give(swep.ClassName)
function BeatrunGiveGMLoadout(ply)
local loadout = BeatrunMakeLoadout()
timer.Simple(1, function()
Beatrun_GiveAmmo(w, ply)
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
for _, v in pairs(loadout) do
local wep = ply:Give(v)
local swep = Beatrun_getRandomARC9SWEP()
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
timer.Simple(1, function() BeatrunGiveAmmo(ply, wep) end)
end
end

View file

@ -22,7 +22,7 @@ if SERVER then
v:Spawn()
end
Beatrun_GiveGMWeapon(v)
BeatrunGiveGMLoadout(v)
end
end
@ -56,7 +56,7 @@ if SERVER then
if datacount > 0 then
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")
datacube:SetPos(pos)

View file

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