From 227da24886f48f0ac819ac9d54c34aace326c591 Mon Sep 17 00:00:00 2001 From: Fesiug Date: Sat, 16 Dec 2023 18:46:14 -0500 Subject: [PATCH] More reloading tweaks --- .../entities/weapons/benny/sh_reload.lua | 100 ++++++++++++------ .../benny/entities/weapons/benny/shared.lua | 7 +- .../benny/gamemode/modules/player/cl_hud.lua | 32 ++++-- .../gamemode/modules/weapons/sh_weapons.lua | 5 +- 4 files changed, 94 insertions(+), 50 deletions(-) diff --git a/gamemodes/benny/entities/weapons/benny/sh_reload.lua b/gamemodes/benny/entities/weapons/benny/sh_reload.lua index c89c347..5e03c04 100644 --- a/gamemodes/benny/entities/weapons/benny/sh_reload.lua +++ b/gamemodes/benny/entities/weapons/benny/sh_reload.lua @@ -1,11 +1,11 @@ -- Reload logic -SWEP.GEN_MagOut = 0 -SWEP.GEN_MagIn = 0.8 +SWEP.GEN_MagOut = 0.2 +SWEP.GEN_MagIn = 1.10 -SWEP.GEN_MagIn_BonusStart = 0.5 -SWEP.GEN_MagIn_BonusEnd = 0.55 +SWEP.GEN_MagIn_BonusStart = 0.60 +SWEP.GEN_MagIn_BonusEnd = 0.60+0.1 function SWEP:Reload( hand ) if hand == nil then return end -- Needs to be called from the custom ones @@ -22,25 +22,34 @@ function SWEP:Reload( hand ) end local rt = self:D_GetReloading( hand ) if rt > 0 then - if (rt+self.GEN_MagIn_BonusStart) <= RealTime() and RealTime() <= (rt+self.GEN_MagIn_BonusEnd) then - self:D_SetReloading( hand, 0 ) - return true + 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 + self:D_SetReloading( hand, 0 ) + return true + else + B_Sound( self, "Common.ReloadFail" ) + self:D_SetReloading( hand, RealTime() ) + return false + end else - B_Sound( self, "Common.ReloadFail" ) - self:D_SetReloading( hand, RealTime() ) return false end end local curmag = self:D_GetMagID( hand ) if curmag != "" then - -- self:D_SetReloading( hand, wep_class.Reload_MagOut or self.GEN_MagOut ) - -- self:D_SetReloadType( hand, 2 ) + self:D_SetReloading( hand, RealTime() ) + self:D_SetReloadType( hand, 2 ) + B_Sound( self, wep_class.Sound_MagOut ) self:Reload_MagOut( hand, self:D_GetMagID( hand ), inv ) - else + elseif self:GetBestLoadableMagazine( wep_table.Class, inv ) then self:D_SetReloading( hand, RealTime() ) self:D_SetReloadType( hand, 1 ) - B_Sound( self, "Common.Unload" ) + B_Sound( self, wep_class.Sound_MagIn ) + else + B_Sound( self, "Common.NoAmmo" ) end self:TPReload( hand ) end @@ -65,40 +74,63 @@ function SWEP:Reload_MagOut( hand, curmag, optinv, optwep_table, optwep_class ) self:D_SetMagID( hand, "" ) self:D_SetClip( hand, 0 ) - B_Sound( self, wep_class.Sound_MagOut ) + --B_Sound( self, wep_class.Sound_MagOut ) wep_table.Loaded = "" end +function SWEP:GetLoadableMagazines( class, optinv ) + local p = self:GetOwner() + local inv = optinv or p:INV_Get() + local wep_table = optwep_table or self:BTable( hand ) + local maglist = p:INV_FindMag( wep_table.Class ) + + local usedlist = {} + for _id, mrow in pairs( inv ) do + if mrow.Loaded and mrow.Loaded != "" then + usedlist[mrow.Loaded] = true + end + end + + return maglist +end + +function SWEP:GetBestLoadableMagazine( class, optinv ) + local p = self:GetOwner() + local inv = optinv or p:INV_Get() + local wep_table = optwep_table or self:BTable( hand ) + local maglist = p:INV_FindMag( wep_table.Class ) + local mag = false + + local usedlist = {} + for _id, mrow in pairs( inv ) do + if mrow.Loaded and mrow.Loaded != "" then + usedlist[mrow.Loaded] = true + end + end + + for num, mid in ipairs( maglist ) do + if usedlist[mid] then + else + mag = mid + break + end + end + + return mag +end + function SWEP:Reload_MagIn( hand, curmag, optinv, optwep_table, optwep_class ) local p = self:GetOwner() local inv = optinv or p:INV_Get() local wep_table = optwep_table or self:BTable( hand ) local wep_class = optwep_class or self:BClass( hand ) - local maglist = p:INV_FindMag( wep_table.Class ) - local mag - - local usedlist = {} - for _id, mrow in pairs( inv ) do - if mrow.Loaded and mrow.Loaded != "" then - usedlist[mrow.Loaded] = true - -- print( mrow.Loaded .. " Added to Mrowlist" ) - end - end - - for num, mid in ipairs( maglist ) do - if usedlist[mid] then - -- print( "oh No we can't use " .. mid ) - else - mag = mid - break - end - end + local mag = self:GetBestLoadableMagazine( wep_table.Class ) if mag then self:D_SetMagID( hand, mag ) self:D_SetClip( hand, inv[mag].Ammo ) wep_table.Loaded = mag - B_Sound( self, wep_class.Sound_MagIn ) + B_Sound( self, wep_class.Sound_MagCock ) else B_Sound( self, "Common.NoAmmo" ) end diff --git a/gamemodes/benny/entities/weapons/benny/shared.lua b/gamemodes/benny/entities/weapons/benny/shared.lua index aa26dd7..d0a4d8e 100644 --- a/gamemodes/benny/entities/weapons/benny/shared.lua +++ b/gamemodes/benny/entities/weapons/benny/shared.lua @@ -212,15 +212,14 @@ function SWEP:Think() do -- Reload logic if self:D_GetReloading( hand ) != -1 then - --self:D_SetReloading( hand, math.Approach( self:D_GetReloading( hand ), 0, FrameTime() ) ) - if RealTime() >= self:D_GetReloading( hand ) + (self:BClass( hand ).Reload_MagIn or self.GEN_MagIn) then - local rlt = self:D_GetReloadType( hand ) + 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 rlt == 1 then if SERVER or (CLIENT and IsFirstTimePredicted() ) then self:Reload_MagIn( hand, self:D_GetMagID( hand ), inv ) end elseif rlt == 2 then - --self:Reload_MagOut( hand, self:D_GetMagID( hand ), inv ) end self:D_SetReloading( hand, -1 ) self:D_SetReloadType( hand, 0 ) diff --git a/gamemodes/benny/gamemode/modules/player/cl_hud.lua b/gamemodes/benny/gamemode/modules/player/cl_hud.lua index 8c86472..47573fa 100644 --- a/gamemodes/benny/gamemode/modules/player/cl_hud.lua +++ b/gamemodes/benny/gamemode/modules/player/cl_hud.lua @@ -906,10 +906,11 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() if hand then boost = -boost end 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 + (wep:BClass( hand ).Reload_MagIn or wep.GEN_MagIn), RealTime() ) + 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 r_x, r_y = sw/2 - r_w/2 + boost, sh/2 - r_h/2 surface.SetDrawColor( schema("bg") ) @@ -918,17 +919,26 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() surface.SetDrawColor( schema("fg") ) surface.DrawOutlinedRect( r_x - bump2, r_y - bump2, r_w + bump2*2, r_h + bump2*2, ss(0.5) ) - local gump = math.Round( r_h*(1-wr) ) - surface.SetDrawColor( schema("fg") ) - surface.DrawRect( r_x, r_y+gump, r_w, r_h-gump ) + if wrt == 1 then + local gump = math.Round( r_h*(1-wr) ) + surface.SetDrawColor( schema("fg") ) + surface.DrawRect( r_x, r_y+gump, r_w, r_h-gump ) + else + local gump = math.Round( r_h*(wr) ) + surface.SetDrawColor( schema("fg") ) + surface.DrawRect( r_x, r_y+gump, r_w, r_h-gump ) + end - local gump1 = math.Round( r_h*(1-b1) ) - local gump2 = math.Round( r_h*(1-b2) ) - surface.SetDrawColor( 255, 100, 100, 100 ) - surface.DrawRect( r_x, r_y+gump2, r_w, gump1-gump2 ) - surface.SetDrawColor( 255, 100, 100 ) - surface.DrawRect( r_x, r_y+gump1, r_w, ss(1) ) - surface.DrawRect( r_x, r_y+gump2, r_w, ss(1) ) + -- TODO: Unshitify this. + if wrt == 1 then + local gump1 = math.Round( r_h*(1-b1) ) + local gump2 = math.Round( r_h*(1-b2) ) + surface.SetDrawColor( 255, 100, 100, 100 ) + surface.DrawRect( r_x, r_y+gump2, r_w, gump1-gump2 ) + surface.SetDrawColor( 255, 100, 100 ) + surface.DrawRect( r_x, r_y+gump1, r_w, ss(1) ) + surface.DrawRect( r_x, r_y+gump2, r_w, ss(1) ) + end end end end diff --git a/gamemodes/benny/gamemode/modules/weapons/sh_weapons.lua b/gamemodes/benny/gamemode/modules/weapons/sh_weapons.lua index 71c9b59..785bd39 100644 --- a/gamemodes/benny/gamemode/modules/weapons/sh_weapons.lua +++ b/gamemodes/benny/gamemode/modules/weapons/sh_weapons.lua @@ -149,6 +149,7 @@ do -- Sound definitions AddSound( "M16A2.MagIn", "benny/weapons/m16a2/magin.ogg", 70, 100, 0.5, CHAN_STATIC ) AddSound( "FNC.MagOut", "benny/weapons/fnc/magout.ogg", 70, 100, 0.5, CHAN_STATIC ) AddSound( "FNC.MagIn", "benny/weapons/fnc/magin.ogg", 70, 100, 0.5, CHAN_STATIC ) + AddSound( "FNC.MagCock", "benny/weapons/fnc/cock.ogg", 70, 100, 0.5, CHAN_STATIC ) AddSound( "AA12.MagOut", "benny/weapons/aa12/magout.ogg", 70, 100, 0.5, CHAN_STATIC ) AddSound( "AA12.MagIn", "benny/weapons/aa12/magin.ogg", 70, 100, 0.5, CHAN_STATIC ) AddSound( "SPAS12.MagOut", { @@ -944,8 +945,9 @@ do -- Rifles Sound_DryFire = "Common.Dryfire.Rifle", Sound_MagOut = "FNC.MagOut", Sound_MagIn = "FNC.MagIn", + Sound_MagCock = "FNC.MagCock", - Delay = (60/600), + Delay = (60/700), Firemodes = FIREMODE_AUTOSEMI, Ammo = 30, Damage = 30, @@ -979,6 +981,7 @@ do -- Rifles Sound_DryFire = "Common.Dryfire.Rifle", Sound_MagOut = "FNC.MagOut", Sound_MagIn = "FNC.MagIn", + Sound_MagCock = "FNC.MagCock", Delay = (60/800), Firemodes = FIREMODE_AUTOSEMI,