From c1bfb596b00f0cd0756bf9063cae500ba8ea2a8e Mon Sep 17 00:00:00 2001 From: Fesiug Date: Mon, 9 Oct 2023 15:05:58 -0400 Subject: [PATCH] Moved the buckets. TODO: Cache them --- .../benny/gamemode/modules/player/cl_hud.lua | 35 +---------------- .../gamemode/modules/player/sh_inventory.lua | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/gamemodes/benny/gamemode/modules/player/cl_hud.lua b/gamemodes/benny/gamemode/modules/player/cl_hud.lua index 6c7479d..7b48494 100644 --- a/gamemodes/benny/gamemode/modules/player/cl_hud.lua +++ b/gamemodes/benny/gamemode/modules/player/cl_hud.lua @@ -501,40 +501,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() local item_gap = ss(12+2) local item_gap_sel = ss(36+2) - local translat = { - ["melee"] = { 1, 1 }, - ["special"] = { 1, 2 }, - ["pistol"] = { 2, 1 }, - ["smg"] = { 3, 1 }, - ["shotgun"] = { 3, 2 }, - ["rifle"] = { 4, 1 }, - ["machinegun"] = { 4, 2 }, - } - - local inventorylist = { - [1] = {}, - [2] = {}, - [3] = {}, - [4] = {}, - } - - for i, bucket in ipairs( inventorylist ) do - local temp = {} - for id, data in pairs( inv ) do - local idata = WEAPONS[data.Class] - local translated = translat[idata.Type] - - if i == translated[1] then - table.insert( temp, { id, translated[2] } ) - end - end - table.sort( temp, function(a, b) return b[2] > a[2] end ) - for i, v in ipairs( temp ) do - table.insert( bucket, v[1] ) - end - end - - -- PrintTable( it ) + local inventorylist = p:INV_Buckets() local bump = 0 for i, bucket in ipairs( inventorylist ) do diff --git a/gamemodes/benny/gamemode/modules/player/sh_inventory.lua b/gamemodes/benny/gamemode/modules/player/sh_inventory.lua index 7587264..5b2a08d 100644 --- a/gamemodes/benny/gamemode/modules/player/sh_inventory.lua +++ b/gamemodes/benny/gamemode/modules/player/sh_inventory.lua @@ -7,4 +7,42 @@ function PT:INV_Get() self.INV = {} end return self.INV +end + +do + local translat = { + ["melee"] = { 1, 1 }, + ["special"] = { 1, 2 }, + ["pistol"] = { 2, 1 }, + ["smg"] = { 3, 1 }, + ["shotgun"] = { 3, 2 }, + ["rifle"] = { 4, 1 }, + ["machinegun"] = { 4, 2 }, + } + + -- PROTO: Cache this! + function PT:INV_Buckets() + local inventorylist = { + [1] = {}, + [2] = {}, + [3] = {}, + [4] = {}, + } + for i, bucket in ipairs( inventorylist ) do + local temp = {} + for id, data in pairs( self:INV_Get() ) do + local idata = WEAPONS[data.Class] + local translated = translat[idata.Type] + + if i == translated[1] then + table.insert( temp, { id, translated[2] } ) + end + end + table.sort( temp, function(a, b) return b[2] > a[2] end ) + for i, v in ipairs( temp ) do + table.insert( bucket, v[1] ) + end + end + return inventorylist + end end \ No newline at end of file