Add GetStat, this makes my life so much easier

This commit is contained in:
Fesiug 2023-12-17 01:05:11 -05:00
parent 7bd16534d1
commit 912e60e129
6 changed files with 20 additions and 14 deletions

View File

@ -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 )

View File

@ -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

View File

@ -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 )

View File

@ -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 )

View File

@ -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") )

View File

@ -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],