From 912e60e129cae8af4982ad35512c85969127cace Mon Sep 17 00:00:00 2001 From: Fesiug Date: Sun, 17 Dec 2023 01:05:11 -0500 Subject: [PATCH] Add GetStat, this makes my life so much easier --- gamemodes/benny/entities/weapons/benny/sh_inv.lua | 12 ++++++++++++ gamemodes/benny/entities/weapons/benny/sh_reload.lua | 8 +------- gamemodes/benny/entities/weapons/benny/shared.lua | 4 +++- gamemodes/benny/gamemode/modules/audio/sh_audio.lua | 2 -- gamemodes/benny/gamemode/modules/player/cl_hud.lua | 6 +++--- gamemodes/benny/gamemode/modules/player/sh_basic.lua | 2 +- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/gamemodes/benny/entities/weapons/benny/sh_inv.lua b/gamemodes/benny/entities/weapons/benny/sh_inv.lua index 40392eb..86a706f 100644 --- a/gamemodes/benny/entities/weapons/benny/sh_inv.lua +++ b/gamemodes/benny/entities/weapons/benny/sh_inv.lua @@ -127,6 +127,18 @@ function SWEP:D_SetClip( hand, value ) return (hand == true) and self:SetClip2( value ) or (hand == false) and self:SetClip1( value ) end +local fallbackstat = { + ["Reload_MagOut"] = 0.2, + ["Reload_MagIn"] = 0.8, + ["Reload_MagIn_Bonus1"] = 0.56, + ["Reload_MagIn_Bonus2"] = 0.56+0.1, + ["Sound_Cock"] = "Glock.Cock", +} + +function SWEP:GetStat( hand, stat ) + return (self:BClass( hand )[stat] or fallbackstat[stat]) +end + function SWEP:C_DualCheck() local p = self:GetOwner() local lt = self:BClass( true ) diff --git a/gamemodes/benny/entities/weapons/benny/sh_reload.lua b/gamemodes/benny/entities/weapons/benny/sh_reload.lua index 96a5733..a45b094 100644 --- a/gamemodes/benny/entities/weapons/benny/sh_reload.lua +++ b/gamemodes/benny/entities/weapons/benny/sh_reload.lua @@ -1,12 +1,6 @@ -- Reload logic -SWEP.GEN_MagOut = 0.2 -SWEP.GEN_MagIn = 0.8 - -SWEP.GEN_MagIn_BonusStart = 0.56 -SWEP.GEN_MagIn_BonusEnd = 0.56+0.1 - function SWEP:Reload( hand ) if hand == nil then return end -- Needs to be called from the custom ones local p = self:GetOwner() @@ -25,7 +19,7 @@ function SWEP:Reload( hand ) local rtt = self:D_GetReloadType( hand ) -- TODO: Unshitify this. if rtt == 1 then - if (rt+self.GEN_MagIn_BonusStart) <= RealTime() and RealTime() <= (rt+self.GEN_MagIn_BonusEnd) then + if (rt+self:GetStat( hand, "Reload_MagIn_Bonus1" )) <= RealTime() and RealTime() <= (rt+self:GetStat( hand, "Reload_MagIn_Bonus2" )) then self:D_SetReloading( hand, 0 ) return true else diff --git a/gamemodes/benny/entities/weapons/benny/shared.lua b/gamemodes/benny/entities/weapons/benny/shared.lua index d0a4d8e..008d993 100644 --- a/gamemodes/benny/entities/weapons/benny/shared.lua +++ b/gamemodes/benny/entities/weapons/benny/shared.lua @@ -157,6 +157,8 @@ function SWEP:BThinkHolster( hand ) end if self:D_GetHolstering( hand ) == 1 then self:D_SetHolstering( hand, -1 ) + self:D_SetReloading( hand, -1 ) + self:D_SetReloadType( hand, 0 ) self:BHolster( hand ) local p = self:GetOwner() local req = self:D_GetReqID( hand ) @@ -214,7 +216,7 @@ function SWEP:Think() if self:D_GetReloading( hand ) != -1 then local rlt = self:D_GetReloadType( hand ) -- TODO: Unshitify this. - if RealTime() >= self:D_GetReloading( hand ) + (rlt == 1 and self.GEN_MagIn or rlt == 2 and self.GEN_MagOut) then + if RealTime() >= self:D_GetReloading( hand ) + (rlt == 1 and self:GetStat( hand, "Reload_MagIn" ) or rlt == 2 and self:GetStat( hand, "Reload_MagOut" )) then if rlt == 1 then if SERVER or (CLIENT and IsFirstTimePredicted() ) then self:Reload_MagIn( hand, self:D_GetMagID( hand ), inv ) diff --git a/gamemodes/benny/gamemode/modules/audio/sh_audio.lua b/gamemodes/benny/gamemode/modules/audio/sh_audio.lua index 5f5522f..8042133 100644 --- a/gamemodes/benny/gamemode/modules/audio/sh_audio.lua +++ b/gamemodes/benny/gamemode/modules/audio/sh_audio.lua @@ -71,8 +71,6 @@ function B_Sound( ent, tag ) end end -AddSound( "Common.Deploy", "benny/weapons/common/06-07.ogg", 70, 100, 0.2, CHAN_STATIC ) -AddSound( "Common.Holster", "benny/weapons/common/06-09.ogg", 70, 100, 0.2, CHAN_STATIC ) RegisterCaption("Common.Deploy", "DEBUG", color_white, "[deploy]", 0.1, 0.5, false, true ) RegisterCaption("Common.Holster", "DEBUG", color_white, "[holster]", 0.1, 0.5, false, true ) RegisterCaption("Common.ReloadFail", "DEBUG", color_white, "[fail]", 0.1, 0.5, false, true ) diff --git a/gamemodes/benny/gamemode/modules/player/cl_hud.lua b/gamemodes/benny/gamemode/modules/player/cl_hud.lua index 47573fa..650430d 100644 --- a/gamemodes/benny/gamemode/modules/player/cl_hud.lua +++ b/gamemodes/benny/gamemode/modules/player/cl_hud.lua @@ -908,9 +908,9 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() local wr = wep:D_GetReloading( hand ) local wrt = wep:D_GetReloadType( hand ) if wr > 0 then - local b1 = math.TimeFraction( wr, wr + (wep.GEN_MagIn), wr + (wep.GEN_MagIn_BonusStart) ) - local b2 = math.TimeFraction( wr, wr + (wep.GEN_MagIn), wr + (wep.GEN_MagIn_BonusEnd) ) - wr = math.TimeFraction( wr, wr + (wrt==1 and (wep:BClass( hand ).Reload_MagIn or wep.GEN_MagIn) or wrt==2 and wep.GEN_MagOut), RealTime() ) + local b1 = math.TimeFraction( wr, wr + wep:GetStat( hand, "Reload_MagIn" ), wr + wep:GetStat( hand, "Reload_MagIn_Bonus1" ) ) + local b2 = math.TimeFraction( wr, wr + wep:GetStat( hand, "Reload_MagIn" ), wr + wep:GetStat( hand, "Reload_MagIn_Bonus2" ) ) + wr = math.TimeFraction( wr, wr + (wrt==1 and wep:GetStat( hand, "Reload_MagIn" ) or wrt==2 and wep:GetStat( hand, "Reload_MagOut" )), RealTime() ) local r_x, r_y = sw/2 - r_w/2 + boost, sh/2 - r_h/2 surface.SetDrawColor( schema("bg") ) diff --git a/gamemodes/benny/gamemode/modules/player/sh_basic.lua b/gamemodes/benny/gamemode/modules/player/sh_basic.lua index 9e509d0..a4aaa01 100644 --- a/gamemodes/benny/gamemode/modules/player/sh_basic.lua +++ b/gamemodes/benny/gamemode/modules/player/sh_basic.lua @@ -12,7 +12,7 @@ concommand.Add("benny_debug_give", function(ply, cmd, args) local class = WeaponGet(args[1]) - assert(class, "Invalid Class.") + assert(class, "Invalid Class " .. tostring(class)) local item = { Class = args[1],