WeaponGet instead of asking the table direct

This commit is contained in:
Fesiug 2023-11-29 18:40:45 -05:00
parent 526eeeb0df
commit 98e11fda6e
7 changed files with 260 additions and 256 deletions

View File

@ -75,7 +75,7 @@ function SWEP:BDeploy( hand, id )
local inv = p:INV_Get()
local item = inv[id]
local class = WEAPONS[item.Class]
local class = WeaponGet(item.Class)
assert( item, "That item doesn't exist. " .. tostring(item) )
@ -102,7 +102,7 @@ function SWEP:BHolster( hand )
local p = self:GetOwner()
local item = self:BTable( hand )
if item then
local class = WEAPONS[item.Class]
local class = WeaponGet(item.Class)
if class.Custom_Holster then class.Custom_Holster( self, item, class, hand ) end
end

View File

@ -1,2 +1,156 @@
-- Dev inventory
-- Dev inventory
local function regen_items( itemlist )
local ply = LocalPlayer()
local inv = ply:INV_Get()
local active = GetConVar("benny_hud_tempactive"):GetString()
itemlist:Clear()
local maidlist = {}
local catesmade = {}
for i, v in pairs( ply:INV_ListFromBuckets() ) do
local class = inv[v].Class
local Class = WeaponGet(class)
if !catesmade[Class.Type] then
catesmade[Class.Type] = true
local cate = vgui.Create( "DButton" )
itemlist:AddItem( cate )
cate:SetSize( 1, ss(12) )
cate:Dock( TOP )
cate:DockMargin( 0, 0, 0, ss(2) )
cate.Text_Name = Class.Type
function cate:Paint( w, h )
surface.SetDrawColor( schemes[active]["bg"] )
surface.DrawRect( 0, 0, w, h )
surface.SetDrawColor( schemes[active]["fg"] )
surface.DrawOutlinedRect( 0, 0, w, h, ss(0.5) )
surface.SetTextColor( schemes[active]["fg"] )
surface.SetFont( "Benny_10" )
surface.SetTextPos( ss(2), ss(2) )
surface.DrawText( self.Text_Name )
return true
end
end
local button = vgui.Create( "DButton" )
itemlist:AddItem( button )
button:SetSize( 1, ss(24) )
button:Dock( TOP )
button:DockMargin( 0, 0, 0, ss(2) )
button.ID = v
local mag = false
if class:Left( 4 ) == "mag_" then
mag = true
button:SetTall( ss(11) )
end
if !maidlist[class] then
maidlist[class] = table.Flip( ply:INV_Find( class ) )
end
local ml = maidlist[class]
button.Text_Name = Class.Name
button.Text_Desc = Class.Description
button.Text_ID = "[" .. ml[v] .. "] " .. button.ID
-- PROTO: These functions don't need to be remade over and over like this.
function button:DoClick()
local Menu = DermaMenu()
local opt1 = Menu:AddOption( "Equip Right", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "false" )
end)
opt1:SetIcon( "icon16/resultset_last.png" )
local opt3 = Menu:AddOption( "Equip Right, Move Left", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "false", "true" )
end)
opt3:SetIcon( "icon16/resultset_next.png" )
Menu:AddSpacer()
local opt2 = Menu:AddOption( "Equip Left", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "true" )
end)
opt2:SetIcon( "icon16/resultset_first.png" )
local opt4 = Menu:AddOption( "Equip Left, Move Right", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "true", "true" )
end)
opt4:SetIcon( "icon16/resultset_previous.png" )
Menu:AddSpacer()
local opt5 = Menu:AddOption( "Holster", function()
RunConsoleCommand( "benny_inv_holster", button.ID )
end)
opt5:SetIcon( "icon16/control_pause_blue.png" )
local opt6 = Menu:AddOption( "Discard", function()
RunConsoleCommand("benny_inv_discard", button.ID)
self:Remove()
end)
opt6:SetIcon( "icon16/bin.png" )
Menu:Open()
-- timer.Simple( 0.1, function() if IsValid( itemlist ) then regen_items( itemlist ) end end )
end
button.DoRightClick = function( self )
RunConsoleCommand("benny_inv_discard", button.ID)
self:Remove()
end
function button:Paint( w, h )
surface.SetDrawColor( schemes[active]["fg"] )
surface.DrawRect( 0, 0, w, h )
surface.SetTextColor( schemes[active]["bg"] )
surface.SetFont( !mag and "Benny_16" or "Benny_10" )
surface.SetTextPos( ss(2), ss(2) )
surface.DrawText( self.Text_Name )
if !mag then
surface.SetFont( "Benny_12" )
surface.SetTextPos( ss(2), ss(2 + 11) )
surface.DrawText( self.Text_Desc )
end
surface.SetFont( "Benny_10" )
local tx = surface.GetTextSize( self.Text_ID )
surface.SetTextPos( w - ss(2) - tx, ss(2) )
surface.DrawText( self.Text_ID )
return true
end
end
end
concommand.Add("benny_debug_inv", function()
if IsValid( base ) then base:Remove() end
base = vgui.Create("DFrame")
base:SetSize( ss(400), ss(400) )
base:MakePopup()
base:SetKeyboardInputEnabled( false )
base:Center()
local active = GetConVar("benny_hud_tempactive"):GetString()
function base:Paint( w, h )
surface.SetDrawColor( schemes[active]["bg"] )
surface.DrawRect( 0, 0, w, h )
return true
end
local itemlist = base:Add("DScrollPanel")
itemlist:Dock( FILL )
regen_items( itemlist )
end)

View File

@ -1,2 +1,93 @@
-- Dev spawnmenu
-- Dev spawnmenu
function GM:OnSpawnMenuOpen()
RunConsoleCommand( "benny_debug_inv" )
end
function GM:OnSpawnMenuClose()
if IsValid( base ) then base:Remove() end
end
function OpenSMenu()
if IsValid( smenu ) then smenu:Remove() return end
local active = GetConVar("benny_hud_tempactive"):GetString()
smenu = vgui.Create("DFrame")
smenu:SetSize( ss(1+(96+2)*4), ss(360) )
smenu:MakePopup()
smenu:SetKeyboardInputEnabled( false )
smenu:Center()
function smenu:Paint( w, h )
surface.SetDrawColor( schemes[active]["bg"] )
surface.DrawRect( 0, 0, w, h )
return true
end
local itemlist = smenu:Add("DScrollPanel")
itemlist:Dock( FILL )
-- local List = vgui.Create( "DIconLayout", itemlist )
-- List:Dock( FILL )
-- List:SetSpaceX( 5 )
-- List:SetSpaceY( 5 )
local createlist = {}
for ClassName, Class in pairs( WEAPONS ) do
if !createlist[Class.Type] then
createlist[Class.Type] = {}
end
table.insert( createlist[Class.Type], { ClassName = ClassName, Class = Class } )
end
for i, v in SortedPairs( createlist ) do
local Collapse = itemlist:Add( "DCollapsibleCategory" )
Collapse:Dock( TOP )
Collapse:SetLabel( i )
local Lays = itemlist:Add( "DIconLayout" )
Collapse:SetContents( Lays )
Collapse:SetExpanded( i!="magazine" )
Lays:Dock( FILL )
Lays:SetSpaceX( ss(1) )
Lays:SetSpaceY( ss(1) )
for Mew, New in ipairs( v ) do
local button = Lays:Add( "DButton" )
button:SetSize( ss(95), ss(14) )
--button:Dock( TOP )
button:DockMargin( 0, 0, 0, ss(4) )
button.Text_Name = New.Class.Name
button.Text_Desc = New.Class.Description
-- PROTO: These functions don't need to be remade over and over like this.
function button:DoClick()
RunConsoleCommand( "benny_debug_give", New.ClassName )
chat.AddText( "Gave " .. New.Class.Name )
end
function button:DoRightClick()
RunConsoleCommand( "benny_debug_give", "mag_" .. New.ClassName )
chat.AddText( "Gave " .. WeaponGet("mag_"..New.ClassName).Name )
end
function button:Paint( w, h )
surface.SetDrawColor( schemes[active]["fg"] )
surface.DrawRect( 0, 0, w, h )
surface.SetTextColor( schemes[active]["bg"] )
surface.SetFont( "Benny_12" )
surface.SetTextPos( ss(2), ss(2) )
surface.DrawText( self.Text_Name )
-- surface.SetFont( "Benny_10" )
-- surface.SetTextPos( ss(4), ss(4 + 12) )
-- surface.DrawText( self.Text_Desc )
return true
end
end
end
end

View File

@ -520,7 +520,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
surface.DrawOutlinedRect( m_x + bb - chunk, m_y + bb, m_w - b2, m_h - b2, ss( 0.5 ) )
local s1 = (m_h - b2 - b2)
local s2 = (m_h - b2 - b2) * (inv[tag] and ( inv[tag].Ammo / WEAPONS[inv[tag].Class].Ammo ) or 8)
local s2 = (m_h - b2 - b2) * (inv[tag] and ( inv[tag].Ammo / WeaponGet(inv[tag].Class).Ammo ) or 8)
local s3 = math.floor( s2 - s1 )
local m1, m2, m3, m4 = m_x + bb + bb - chunk, m_y + bb + bb - s3, m_w - b2 - b2, s2
@ -681,7 +681,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
bump = bump + (nextwe_no)
else
for d, item in ipairs( bucket ) do
local idata = WEAPONS[inv[item].Class]
local idata = WeaponGet(inv[item].Class)
local sel = item==wep:D_GetID( false )--d==item_selected
surface.SetDrawColor( scheme["bg"] )
surface.DrawRect( bump + Wb, (item_start+ybump) + Hb, size_textx, (sel and size_texty_sel or size_texty) )

View File

@ -10,7 +10,7 @@ concommand.Add("benny_debug_give", function(ply, cmd, args)
local inv = ply:INV_Get()
local str = UUID_generate()
local class = WEAPONS[args[1]]
local class = WeaponGet(args[1])
assert(class, "Invalid Class.")
@ -190,249 +190,4 @@ function GM:ShowSpare2( ply )
if SERVER then
ply:ConCommand( "benny_gui_spscore" )
end
end
-- Debug inv
if CLIENT then
function GM:OnSpawnMenuOpen()
RunConsoleCommand( "benny_debug_inv" )
end
function GM:OnSpawnMenuClose()
if IsValid( base ) then base:Remove() end
end
function OpenSMenu()
if IsValid( smenu ) then smenu:Remove() return end
local active = GetConVar("benny_hud_tempactive"):GetString()
smenu = vgui.Create("DFrame")
smenu:SetSize( ss(1+(96+2)*4), ss(360) )
smenu:MakePopup()
smenu:SetKeyboardInputEnabled( false )
smenu:Center()
function smenu:Paint( w, h )
surface.SetDrawColor( schemes[active]["bg"] )
surface.DrawRect( 0, 0, w, h )
return true
end
local itemlist = smenu:Add("DScrollPanel")
itemlist:Dock( FILL )
-- local List = vgui.Create( "DIconLayout", itemlist )
-- List:Dock( FILL )
-- List:SetSpaceX( 5 )
-- List:SetSpaceY( 5 )
local createlist = {}
for ClassName, Class in pairs( WEAPONS ) do
if !createlist[Class.Type] then
createlist[Class.Type] = {}
end
table.insert( createlist[Class.Type], { ClassName = ClassName, Class = Class } )
end
for i, v in SortedPairs( createlist ) do
local Collapse = itemlist:Add( "DCollapsibleCategory" )
Collapse:Dock( TOP )
Collapse:SetLabel( i )
local Lays = itemlist:Add( "DIconLayout" )
Collapse:SetContents( Lays )
Collapse:SetExpanded( i!="magazine" )
Lays:Dock( FILL )
Lays:SetSpaceX( ss(1) )
Lays:SetSpaceY( ss(1) )
for Mew, New in ipairs( v ) do
local button = Lays:Add( "DButton" )
button:SetSize( ss(95), ss(14) )
--button:Dock( TOP )
button:DockMargin( 0, 0, 0, ss(4) )
button.Text_Name = New.Class.Name
button.Text_Desc = New.Class.Description
-- PROTO: These functions don't need to be remade over and over like this.
function button:DoClick()
RunConsoleCommand( "benny_debug_give", New.ClassName )
end
function button:DoRightClick()
RunConsoleCommand( "benny_debug_give", "mag_" .. New.ClassName )
end
function button:Paint( w, h )
surface.SetDrawColor( schemes[active]["fg"] )
surface.DrawRect( 0, 0, w, h )
surface.SetTextColor( schemes[active]["bg"] )
surface.SetFont( "Benny_12" )
surface.SetTextPos( ss(2), ss(2) )
surface.DrawText( self.Text_Name )
-- surface.SetFont( "Benny_10" )
-- surface.SetTextPos( ss(4), ss(4 + 12) )
-- surface.DrawText( self.Text_Desc )
return true
end
end
end
end
local function regen_items( itemlist )
local ply = LocalPlayer()
local inv = ply:INV_Get()
local active = GetConVar("benny_hud_tempactive"):GetString()
itemlist:Clear()
local maidlist = {}
local catesmade = {}
for i, v in pairs( ply:INV_ListFromBuckets() ) do
local class = inv[v].Class
local Class = WEAPONS[class]
if !catesmade[Class.Type] then
catesmade[Class.Type] = true
local cate = vgui.Create( "DButton" )
itemlist:AddItem( cate )
cate:SetSize( 1, ss(12) )
cate:Dock( TOP )
cate:DockMargin( 0, 0, 0, ss(2) )
cate.Text_Name = Class.Type
function cate:Paint( w, h )
surface.SetDrawColor( schemes[active]["bg"] )
surface.DrawRect( 0, 0, w, h )
surface.SetDrawColor( schemes[active]["fg"] )
surface.DrawOutlinedRect( 0, 0, w, h, ss(0.5) )
surface.SetTextColor( schemes[active]["fg"] )
surface.SetFont( "Benny_10" )
surface.SetTextPos( ss(2), ss(2) )
surface.DrawText( self.Text_Name )
return true
end
end
local button = vgui.Create( "DButton" )
itemlist:AddItem( button )
button:SetSize( 1, ss(24) )
button:Dock( TOP )
button:DockMargin( 0, 0, 0, ss(2) )
button.ID = v
local mag = false
if class:Left( 4 ) == "mag_" then
mag = true
button:SetTall( ss(11) )
end
if !maidlist[class] then
maidlist[class] = table.Flip( ply:INV_Find( class ) )
end
local ml = maidlist[class]
button.Text_Name = Class.Name
button.Text_Desc = Class.Description
button.Text_ID = "[" .. ml[v] .. "] " .. button.ID
-- PROTO: These functions don't need to be remade over and over like this.
function button:DoClick()
local Menu = DermaMenu()
local opt1 = Menu:AddOption( "Equip Right", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "false" )
end)
opt1:SetIcon( "icon16/resultset_last.png" )
local opt3 = Menu:AddOption( "Equip Right, Move Left", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "false", "true" )
end)
opt3:SetIcon( "icon16/resultset_next.png" )
Menu:AddSpacer()
local opt2 = Menu:AddOption( "Equip Left", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "true" )
end)
opt2:SetIcon( "icon16/resultset_first.png" )
local opt4 = Menu:AddOption( "Equip Left, Move Right", function()
RunConsoleCommand( "benny_inv_equip", button.ID, "true", "true" )
end)
opt4:SetIcon( "icon16/resultset_previous.png" )
Menu:AddSpacer()
local opt5 = Menu:AddOption( "Holster", function()
RunConsoleCommand( "benny_inv_holster", button.ID )
end)
opt5:SetIcon( "icon16/control_pause_blue.png" )
local opt6 = Menu:AddOption( "Discard", function()
RunConsoleCommand("benny_inv_discard", button.ID)
self:Remove()
end)
opt6:SetIcon( "icon16/bin.png" )
Menu:Open()
-- timer.Simple( 0.1, function() if IsValid( itemlist ) then regen_items( itemlist ) end end )
end
button.DoRightClick = function( self )
RunConsoleCommand("benny_inv_discard", button.ID)
self:Remove()
end
function button:Paint( w, h )
surface.SetDrawColor( schemes[active]["fg"] )
surface.DrawRect( 0, 0, w, h )
surface.SetTextColor( schemes[active]["bg"] )
surface.SetFont( !mag and "Benny_16" or "Benny_10" )
surface.SetTextPos( ss(2), ss(2) )
surface.DrawText( self.Text_Name )
if !mag then
surface.SetFont( "Benny_12" )
surface.SetTextPos( ss(2), ss(2 + 11) )
surface.DrawText( self.Text_Desc )
end
surface.SetFont( "Benny_10" )
local tx = surface.GetTextSize( self.Text_ID )
surface.SetTextPos( w - ss(2) - tx, ss(2) )
surface.DrawText( self.Text_ID )
return true
end
end
end
concommand.Add("benny_debug_inv", function()
if IsValid( base ) then base:Remove() end
base = vgui.Create("DFrame")
base:SetSize( ss(400), ss(400) )
base:MakePopup()
base:SetKeyboardInputEnabled( false )
base:Center()
local active = GetConVar("benny_hud_tempactive"):GetString()
function base:Paint( w, h )
surface.SetDrawColor( schemes[active]["bg"] )
surface.DrawRect( 0, 0, w, h )
return true
end
local itemlist = base:Add("DScrollPanel")
itemlist:Dock( FILL )
regen_items( itemlist )
end)
end

View File

@ -139,7 +139,7 @@ do
for i, bucket in ipairs( inventorylist ) do
local temp = {}
for id, data in pairs( inv ) do
local idata = WEAPONS[data.Class]
local idata = WeaponGet(data.Class)
local translated = translat[idata.Type]
if i == translated[1] then

View File

@ -11,6 +11,10 @@ FIREMODE_SEMI = {
}
WEAPONS = {}
function WeaponGet( classname )
return WEAPONS[ classname ]
end
AddSound( "1911.Fire", {
"benny/weapons/1911/01.ogg",
"benny/weapons/1911/02.ogg",
@ -887,7 +891,7 @@ do -- Grenades, nothing here is guaranteed.
local function GrenadeCreate( self, data )
-- PROTO: See to getting this done better. Maybe it's spawned while priming the nade for low CL-SV/phys delay?
local p = self:GetOwner()
local class = WEAPONS[data.Class]
local class = WeaponGet(data.Class)
local GENT = ents.Create( class.GrenadeEnt )
GENT:SetOwner( p )
local ang = p:EyeAngles()
@ -906,7 +910,7 @@ do -- Grenades, nothing here is guaranteed.
local function GrenadeThrow( self, data )
local p = self:GetOwner()
local class = WEAPONS[data.Class]
local class = WeaponGet(data.Class)
self:SetGrenadeDown( false )
-- TEMP: Do this right!
if !class.GrenadeCharge then self:SetGrenadeDownStart( CurTime() ) end
@ -929,7 +933,7 @@ do -- Grenades, nothing here is guaranteed.
local function GrenadeThink( self, data )
local p = self:GetOwner()
local class = WEAPONS[data.Class]
local class = WeaponGet(data.Class)
if self:GetGrenadeDown() then
if true or ( CurTime() >= (self:GetGrenadeDownStart() + class.GrenadeFuse) ) then
GrenadeThrow( self, data )