More reloading tweaks

This commit is contained in:
Fesiug 2023-12-16 18:46:14 -05:00
parent 3bd3b174c1
commit 227da24886
4 changed files with 94 additions and 50 deletions

View File

@ -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,6 +22,9 @@ function SWEP:Reload( hand )
end
local rt = self:D_GetReloading( hand )
if rt > 0 then
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
@ -30,17 +33,23 @@ function SWEP:Reload( hand )
self:D_SetReloading( hand, RealTime() )
return false
end
else
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

View File

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

View File

@ -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,10 +919,18 @@ 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) )
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
-- 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 )
@ -932,6 +941,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
end
end
end
end
end )
do

View File

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