Clean up table stuff, Magazine GUI

Might be some bugs in it
This commit is contained in:
Fesiug 2023-09-25 20:42:13 -04:00
parent 9a8ad838ff
commit b54da223a4
3 changed files with 75 additions and 83 deletions

View File

@ -27,85 +27,51 @@ function SWEP:SetupDataTables()
self:NetworkVar( "String", 1, "Wep2" ) self:NetworkVar( "String", 1, "Wep2" )
self:NetworkVar( "Int", 0, "Wep1Clip" ) self:NetworkVar( "Int", 0, "Wep1Clip" )
self:NetworkVar( "Int", 1, "Wep2Clip" ) self:NetworkVar( "Int", 1, "Wep2Clip" )
self:NetworkVarNotify( "Wep1", self.OnVarChanged )
self:NetworkVarNotify( "Wep2", self.OnVarChanged )
end
function SWEP:OnReloaded()
self.B_WepT1 = self:GetOwner():INV_Get()[self:GetWep1()]
if self.B_WepT1 then
self.B_ClassT1 = WEAPONS[self.B_WepT1.Class]
end
self.B_WepT2 = self:GetOwner():INV_Get()[self:GetWep2()]
if self.B_WepT2 then
self.B_ClassT2 = WEAPONS[self.B_WepT2.Class]
end
end
function SWEP:OnVarChanged( name, old, new )
if name == "Wep1" then
self.B_WepT1 = self:GetOwner():INV_Get()[new]
if self.B_WepT1 then
self.B_ClassT1 = WEAPONS[self.B_WepT1.Class]
end
elseif name == "Wep2" then
self.B_WepT2 = self:GetOwner():INV_Get()[new]
if self.B_WepT2 then
self.B_ClassT2 = WEAPONS[self.B_WepT2.Class]
end
end
end end
function SWEP:PrimaryAttack() function SWEP:PrimaryAttack()
if !self:B_Wep1() then if !self:BTable() then
return return
end end
if self:GetDelay1() > CurTime() then if self:GetDelay1() > CurTime() then
return return
end end
if self:Clip1() == 0 then if self:Clip1() == 0 then
B_Sound( self, self.B_ClassT1.Sound_DryFire ) B_Sound( self, self:BClass( false ).Sound_DryFire )
self:SetDelay1( CurTime() + 0.2 ) self:SetDelay1( CurTime() + 0.2 )
return return
end end
B_Sound( self, self.B_ClassT1.Sound_Fire ) B_Sound( self, self:BClass( false ).Sound_Fire )
self:B_Ammo1( self:Clip1() - 1 ) self:B_Ammo( false, self:Clip1() - 1 )
self:SetDelay1( CurTime() + self.B_ClassT1.Delay ) self:SetDelay1( CurTime() + self:BClass( false ).Delay )
return true return true
end end
-- BENNY shit -- BENNY shit
function SWEP:B_Wep1() function SWEP:BTable( alt )
return self:GetOwner():INV_Get()[self:GetWep1()] return self:GetOwner():INV_Get()[ alt and self:GetWep2() or self:GetWep1() ]
end end
function SWEP:B_Wep2() function SWEP:BClass( alt )
return self:GetOwner():INV_Get()[self:GetWep2()] local ta = self:BTable( alt )
if ta then
return WEAPONS[ ta.Class ]
else
return false
end
end end
function SWEP:B_Ammo1( value ) function SWEP:B_Ammo( alt, value )
assert( self:GetWep1Clip() > 0, "You cannot mess with an EMPTY magazine!") local clip = (alt and self:GetWep2Clip() or self:GetWep1Clip())
self:SetClip1( value ) assert( clip > 0, "You cannot mess with an EMPTY magazine!")
self:B_Wep1()["Ammo" .. self:GetWep1Clip()] = value if alt then
end
function SWEP:B_Ammo2( value )
assert( self:GetWep1Clip() > 0, "You cannot mess with an EMPTY magazine!")
self:SetClip2( value ) self:SetClip2( value )
self:B_Wep2()["Ammo" .. self:GetWep1Clip()] = value else
end
function SWEP:B_MaxAmmo1( value )
assert( self:GetWep1Clip() > 0, "You cannot mess with an EMPTY magazine!")
self:SetClip1( value ) self:SetClip1( value )
self:B_Wep1()["Ammo" .. self:GetWep1Clip()] = value
end end
self:BTable( alt )["Ammo" .. clip] = value
function SWEP:B_Class1()
return WEAPONS[ self:B_Wep1().Class ]
end end
function SWEP:SecondaryAttack() function SWEP:SecondaryAttack()
@ -113,29 +79,28 @@ function SWEP:SecondaryAttack()
end end
function SWEP:Reload() function SWEP:Reload()
if self:B_Wep1() and self:Clip1() < self:B_Class1().Ammo then if self:BTable( false ) then
if self:GetDelay1() > CurTime() then if self:GetDelay1() > CurTime() then
return false return false
end end
self:SetDelay1( CurTime() + 0.2 ) self:SetDelay1( CurTime() + 0.2 )
if self:GetWep1Clip() != 0 then if self:GetWep1Clip() != 0 then
B_Sound( self, self.B_ClassT1.Sound_MagOut ) B_Sound( self, self:BClass().Sound_MagOut )
self:SetClip1( 0 ) self:SetClip1( 0 )
self:SetWep1Clip( 0 ) self:SetWep1Clip( 0 )
self:B_Wep1().Loaded = 0 self:BTable().Loaded = 0
else else
local maglist = { self:B_Wep1().Ammo1, self:B_Wep1().Ammo2, self:B_Wep1().Ammo3 } local maglist = { self:BTable( false ).Ammo1, self:BTable( false ).Ammo2, self:BTable( false ).Ammo3 }
for i, v in SortedPairsByValue( maglist, true ) do for i, v in SortedPairsByValue( maglist, true ) do
if v == 0 then B_Sound( self, "Common.NoAmmo" ) return end if v == 0 then B_Sound( self, "Common.NoAmmo" ) return end
self:B_Wep1().Loaded = i self:BTable().Loaded = i
self:SetWep1Clip( i ) self:SetWep1Clip( i )
self:SetClip1( v ) self:SetClip1( v )
break break
end end
B_Sound( self, self.B_ClassT1.Sound_MagIn ) B_Sound( self, self:BClass().Sound_MagIn )
end end
-- self:B_Ammo1( self:B_Class1().Ammo )
end end
return true return true
end end

View File

@ -267,7 +267,7 @@ end
function bennyfp( origin, angles, fov ) function bennyfp( origin, angles, fov )
local ply = LocalPlayer() local ply = LocalPlayer()
assert( IsValid( ply:GetActiveWeapon() ) ) if !IsValid( ply:GetActiveWeapon() ) then return origin, angles, fov end
local pos, ang = Vector(), Angle() local pos, ang = Vector(), Angle()

View File

@ -197,10 +197,10 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
do -- Weapon do -- Weapon
local inv = p:INV_Get() local inv = p:INV_Get()
local wep1 = wep.B_WepT1 local wep1 = wep:BTable( false )
local wep1c = wep.B_ClassT1 local wep1c = wep:BClass( false )
local wep2 = wep.B_WepT2 local wep2 = wep:BTable( true )
local wep2c = wep.B_ClassT2 local wep2c = wep:BClass( true )
if false then -- Debug if false then -- Debug
local ox, oy = 170, 24 local ox, oy = 170, 24
@ -253,13 +253,13 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
surface.DrawText( wep1c.Firemode or "???" ) surface.DrawText( wep1c.Firemode or "???" )
surface.SetFont( "Benny_12" ) surface.SetFont( "Benny_12" )
local text = wep:Clip1() .. " - MAG " .. wep:GetWep1Clip() local text = wep:GetWep1Clip() == 0 and "---" or wep:Clip1()-- .. " - MAG " .. wep:GetWep1Clip()
local tw = surface.GetTextSize( text ) local tw = surface.GetTextSize( text )
surface.SetTextColor( scheme["fg"] ) surface.SetTextColor( scheme["fg"] )
surface.SetTextPos( sw - b - ss(4) - tw, sh - b - ss(24) ) surface.SetTextPos( sw - b - ss(4) - tw, sh - b - ss(24) )
surface.DrawText( text ) surface.DrawText( text )
for i=1, math.max( wep:Clip1(), wep.B_ClassT1.Ammo ) do for i=1, math.max( wep:Clip1(), wep:BClass( false ).Ammo ) do
surface.SetDrawColor( scheme["fg"] ) surface.SetDrawColor( scheme["fg"] )
surface.DrawOutlinedRect( sw - b - ss(3+4) - ( ss(5) * (i-1) ), sh - b - ss(8+4), ss(3), ss(8), ss(0.5) ) surface.DrawOutlinedRect( sw - b - ss(3+4) - ( ss(5) * (i-1) ), sh - b - ss(8+4), ss(3), ss(8), ss(0.5) )
if i <= wep:Clip1() then if i <= wep:Clip1() then
@ -267,23 +267,50 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
end end
end end
local amlist = { wep.B_WepT1["Ammo" .. 1], wep.B_WepT1["Ammo" .. 2], wep.B_WepT1["Ammo" .. 3] } local amlist = { wep:BTable( false )["Ammo" .. 1], wep:BTable( false )["Ammo" .. 2], wep:BTable( false )["Ammo" .. 3] }
local i = 1 local ind = 1
local bubby = ss(1)
local blen, bhei = 25, 10
for _, v in ipairs( amlist ) do for _, v in ipairs( amlist ) do
if v == 0 then continue end local active = wep:GetWep1Clip() == _
local perc = v / wep.B_ClassT1.Ammo if v == 0 and !active then continue end
local perc = v / wep:BClass( false ).Ammo
local suuze = ss(blen*perc) - bubby*2*perc
if v != 0 then suuze = math.max( suuze, 1 ) end
surface.SetDrawColor( scheme["fg"] ) surface.SetDrawColor( scheme["fg"] )
surface.DrawOutlinedRect( sw - b - ss(w-4-2) + ss(29) + ( ss(10+2) * (i-1) ), surface.DrawOutlinedRect( sw - b - ss(w-4-2) + ss(29) + ( ss(blen+2) * (ind-1) ),
sh - b + ss(16) - ss(BOXHEIGHT-4), sh - b + ss(16) - ss(BOXHEIGHT-4),
ss(10), ss(blen),
ss(10), ss(bhei),
ss(0.5) ) ss(0.5) )
if active then
surface.SetTextColor( scheme["fg"] )
surface.SetTextPos( sw - b - ss(w-4-2) + ss(29/2) + ( ss(blen+2) * (ind) ) + bubby - ss(4),
sh - b + ss(16) - ss(BOXHEIGHT-4) + bubby - ss(2) )
surface.DrawText( "x" )
end
surface.SetDrawColor( scheme["fg"] ) surface.SetDrawColor( scheme["fg"] )
surface.DrawRect( sw - b - ss(w-4-2) + ss(29) + ( ss(10+2) * (i-1) ), surface.DrawRect( sw - b - ss(w-4-2) + ss(29) + ( ss(blen+2) * (ind-1) ) + bubby,
sh - b + ss(16) - ss(BOXHEIGHT-4) + ss(10*(1-perc)), sh - b + ss(16) - ss(BOXHEIGHT-4) + bubby,
ss(10), suuze,
ss(10*perc) ) ss(bhei) - bubby*2 )
i = i + 1
if active then
render.SetScissorRect( sw - b - ss(w-4-2) + ss(29) + ( ss(blen+2) * (ind-1) ) + bubby,
sh - b + ss(16) - ss(BOXHEIGHT-4) + bubby,
sw - b - ss(w-4-2) + ss(29) + ( ss(blen+2) * (ind-1) ) + bubby + suuze,
sh - b + ss(16) - ss(BOXHEIGHT-4) + bubby + (ss(bhei) - bubby*2), true )
surface.SetTextColor( scheme["bg"] )
surface.SetTextPos( sw - b - ss(w-4-2) + ss(29/2) + ( ss(blen+2) * (ind) ) + bubby - ss(4),
sh - b + ss(16) - ss(BOXHEIGHT-4) + bubby - ss(2) )
surface.DrawText( "x" )
render.SetScissorRect( 0, 0, 0, 0, false )
end
ind = ind + 1
end end
end end
end end