From 5ea463442974107a1f3dd898b076199f5e6b6538 Mon Sep 17 00:00:00 2001 From: Fesiug Date: Wed, 6 Dec 2023 01:03:35 -0500 Subject: [PATCH] FindMagSmart, FindMag upgrades --- .../benny/entities/weapons/benny/shared.lua | 2 +- .../benny/gamemode/modules/player/cl_hud.lua | 13 +++------- .../gamemode/modules/player/sh_player.lua | 24 ++++++++++++++++++- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/gamemodes/benny/entities/weapons/benny/shared.lua b/gamemodes/benny/entities/weapons/benny/shared.lua index bce3b63..9263a9b 100644 --- a/gamemodes/benny/entities/weapons/benny/shared.lua +++ b/gamemodes/benny/entities/weapons/benny/shared.lua @@ -122,7 +122,7 @@ function SWEP:Reload( hand ) B_Sound( self, wep_class.Sound_MagOut ) wep_table.Loaded = "" else - local maglist = p:INV_FindMag( "mag_" .. wep_table.Class ) + local maglist = p:INV_FindMag( wep_table.Class ) local mag local usedlist = {} diff --git a/gamemodes/benny/gamemode/modules/player/cl_hud.lua b/gamemodes/benny/gamemode/modules/player/cl_hud.lua index a4c6eb2..e77c9a9 100644 --- a/gamemodes/benny/gamemode/modules/player/cl_hud.lua +++ b/gamemodes/benny/gamemode/modules/player/cl_hud.lua @@ -489,7 +489,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() local b2 = ss( 2 ) local b3 = ss( 3 ) local b4 = ss( 4 ) - local maglist = p:INV_FindMag( "mag_" .. wep_table.Class, { [wep:D_GetMagID( hand )] = true, [wep:D_GetMagID( !hand )] = true, } ) + local maglist = p:INV_FindMag( wep_table.Class, { [wep:D_GetMagID( hand )] = true, [wep:D_GetMagID( !hand )] = true, } ) local newmaglist = {} if wep:D_GetMagID( hand ) != "" then @@ -751,16 +751,9 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() draw.SimpleText( invid, "Benny_10", b_x + bump + ss(6), b_y - ss(2+10), scheme["fg"], TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP ) end - -- PROTO: Make FindMagSmart that does all this in sh_player, along with the other one in the Weapon HUD. - local maginv = p:INV_FindMag( "mag_" .. item.Class, (item.Loaded and item.Loaded != "" and { [item.Loaded] = true }) ) - local f_maginv = {} - if item.Loaded != "" then table.insert( f_maginv, item.Loaded ) end - for i, v in ipairs( maginv ) do - table.insert( f_maginv, v ) - end - -- PROTO end + local maginv = p:INV_FindMagSmart( item.Class, nil, id ) local magbump = 0 - for _, mag in ipairs( f_maginv ) do + for _, mag in ipairs( maginv ) do local mitem = inv[mag] local loaded = (item.Loaded == mag) local perc = mitem.Ammo/WeaponGet(mitem.Class).Ammo diff --git a/gamemodes/benny/gamemode/modules/player/sh_player.lua b/gamemodes/benny/gamemode/modules/player/sh_player.lua index 52e5f95..7b3e91e 100644 --- a/gamemodes/benny/gamemode/modules/player/sh_player.lua +++ b/gamemodes/benny/gamemode/modules/player/sh_player.lua @@ -129,7 +129,8 @@ function PT:INV_FindMag( class, exclude ) local inv = self:INV_Get() local results = {} for i, v in pairs( inv ) do - if v.Class == class and (exclude and !exclude[i] or !exclude and true) then + -- PROTO: STANAG mags and such should share, and this'll need to be changed. + if v.Class == ("mag_" .. class) and (exclude and !exclude[i] or !exclude and true) then table.insert( results, i ) end end @@ -138,6 +139,27 @@ function PT:INV_FindMag( class, exclude ) return results end +function PT:INV_FindMagSmart( class, exclude, loader ) + local inv = self:INV_Get() + local loadm = inv[loader] + + local addexc = {} + for i, v in pairs( inv ) do + if v.Loaded and v.Loaded != "" then + addexc[v.Loaded] = true + end + end + local findmag = self:INV_FindMag( class, addexc ) + + local f_maginv = {} + if addexc[loadm.Loaded] or loadm.Loaded != "" then table.insert( f_maginv, loadm.Loaded ) end + for i, v in ipairs( findmag ) do + table.insert( f_maginv, v ) + end + + return f_maginv +end + do local translat = { ["melee"] = { 1, 1 },