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( "Int", 0, "Wep1Clip" )
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
function SWEP:PrimaryAttack()
if !self:B_Wep1() then
if !self:BTable() then
return
end
if self:GetDelay1() > CurTime() then
return
end
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 )
return
end
B_Sound( self, self.B_ClassT1.Sound_Fire )
B_Sound( self, self:BClass( false ).Sound_Fire )
self:B_Ammo1( self:Clip1() - 1 )
self:SetDelay1( CurTime() + self.B_ClassT1.Delay )
self:B_Ammo( false, self:Clip1() - 1 )
self:SetDelay1( CurTime() + self:BClass( false ).Delay )
return true
end
-- BENNY shit
function SWEP:B_Wep1()
return self:GetOwner():INV_Get()[self:GetWep1()]
function SWEP:BTable( alt )
return self:GetOwner():INV_Get()[ alt and self:GetWep2() or self:GetWep1() ]
end
function SWEP:B_Wep2()
return self:GetOwner():INV_Get()[self:GetWep2()]
function SWEP:BClass( alt )
local ta = self:BTable( alt )
if ta then
return WEAPONS[ ta.Class ]
else
return false
end
end
function SWEP:B_Ammo1( value )
assert( self:GetWep1Clip() > 0, "You cannot mess with an EMPTY magazine!")
self:SetClip1( value )
self:B_Wep1()["Ammo" .. self:GetWep1Clip()] = value
end
function SWEP:B_Ammo2( value )
assert( self:GetWep1Clip() > 0, "You cannot mess with an EMPTY magazine!")
self:SetClip2( value )
self:B_Wep2()["Ammo" .. self:GetWep1Clip()] = value
end
function SWEP:B_MaxAmmo1( value )
assert( self:GetWep1Clip() > 0, "You cannot mess with an EMPTY magazine!")
self:SetClip1( value )
self:B_Wep1()["Ammo" .. self:GetWep1Clip()] = value
end
function SWEP:B_Class1()
return WEAPONS[ self:B_Wep1().Class ]
function SWEP:B_Ammo( alt, value )
local clip = (alt and self:GetWep2Clip() or self:GetWep1Clip())
assert( clip > 0, "You cannot mess with an EMPTY magazine!")
if alt then
self:SetClip2( value )
else
self:SetClip1( value )
end
self:BTable( alt )["Ammo" .. clip] = value
end
function SWEP:SecondaryAttack()
@ -113,29 +79,28 @@ function SWEP:SecondaryAttack()
end
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
return false
end
self:SetDelay1( CurTime() + 0.2 )
if self:GetWep1Clip() != 0 then
B_Sound( self, self.B_ClassT1.Sound_MagOut )
B_Sound( self, self:BClass().Sound_MagOut )
self:SetClip1( 0 )
self:SetWep1Clip( 0 )
self:B_Wep1().Loaded = 0
self:BTable().Loaded = 0
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
if v == 0 then B_Sound( self, "Common.NoAmmo" ) return end
self:B_Wep1().Loaded = i
self:BTable().Loaded = i
self:SetWep1Clip( i )
self:SetClip1( v )
break
end
B_Sound( self, self.B_ClassT1.Sound_MagIn )
B_Sound( self, self:BClass().Sound_MagIn )
end
-- self:B_Ammo1( self:B_Class1().Ammo )
end
return true
end

View File

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

View File

@ -197,10 +197,10 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
do -- Weapon
local inv = p:INV_Get()
local wep1 = wep.B_WepT1
local wep1c = wep.B_ClassT1
local wep2 = wep.B_WepT2
local wep2c = wep.B_ClassT2
local wep1 = wep:BTable( false )
local wep1c = wep:BClass( false )
local wep2 = wep:BTable( true )
local wep2c = wep:BClass( true )
if false then -- Debug
local ox, oy = 170, 24
@ -253,13 +253,13 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
surface.DrawText( wep1c.Firemode or "???" )
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 )
surface.SetTextColor( scheme["fg"] )
surface.SetTextPos( sw - b - ss(4) - tw, sh - b - ss(24) )
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.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
@ -267,23 +267,50 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
end
end
local amlist = { wep.B_WepT1["Ammo" .. 1], wep.B_WepT1["Ammo" .. 2], wep.B_WepT1["Ammo" .. 3] }
local i = 1
local amlist = { wep:BTable( false )["Ammo" .. 1], wep:BTable( false )["Ammo" .. 2], wep:BTable( false )["Ammo" .. 3] }
local ind = 1
local bubby = ss(1)
local blen, bhei = 25, 10
for _, v in ipairs( amlist ) do
if v == 0 then continue end
local perc = v / wep.B_ClassT1.Ammo
local active = wep:GetWep1Clip() == _
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.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),
ss(10),
ss(10),
ss(blen),
ss(bhei),
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.DrawRect( sw - b - ss(w-4-2) + ss(29) + ( ss(10+2) * (i-1) ),
sh - b + ss(16) - ss(BOXHEIGHT-4) + ss(10*(1-perc)),
ss(10),
ss(10*perc) )
i = 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) + bubby,
suuze,
ss(bhei) - bubby*2 )
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