Can't get predicted wep. switch working well. Yet.

This commit is contained in:
Fesiug 2023-11-17 21:12:25 -05:00
parent 97d5939b91
commit 630a51915d
6 changed files with 110 additions and 86 deletions

View File

@ -71,23 +71,14 @@ function SWEP:BDeploy( hand, id )
assert( item, "That item doesn't exist. " .. tostring(item) ) assert( item, "That item doesn't exist. " .. tostring(item) )
self:D_SetID( hand, id ) self:D_SetID( hand, id )
self:D_SetMagID( hand, "" )
self:D_SetClip( hand, 0 )
if item.Loaded then if item.Loaded then
local mid = inv[ item.Loaded ] local mid = item.Loaded
if mid then local midi = inv[ mid ]
self:D_SetMagID( hand, item.Loaded ) assert( midi, "Deploy: Magazine doesn't exist in the inventory!! " .. tostring(item.Loaded) )
self:D_SetClip( hand, mid.Ammo ) self:D_SetMagID( hand, mid )
end self:D_SetClip( hand, midi.Ammo )
end
-- PROTO: Make grenade/melee/firearm logic way way better.
if class.Features == "firearm" then
-- if item.Loaded != "" then
-- assert( inv[ item.Loaded ], "That magazine doesn't exist." )
-- end
-- self:D_SetClip( hand, item.Loaded == "" and 0 or inv[ "Ammo" .. item.Loaded ] )
else
self:D_SetClip( hand, 0 )
end end
end end

View File

@ -77,7 +77,6 @@ function SWEP:B_Ammo( hand, value )
local p = self:GetOwner() local p = self:GetOwner()
local inv = p:INV_Get() local inv = p:INV_Get()
self:D_SetClip( hand, value ) self:D_SetClip( hand, value )
print( hand, value )
assert( self:D_GetMagID( hand ) != "", "There is no magazine loaded!" ) assert( self:D_GetMagID( hand ) != "", "There is no magazine loaded!" )
inv[ self:D_GetMagID( hand ) ].Ammo = value inv[ self:D_GetMagID( hand ) ].Ammo = value
end end
@ -105,57 +104,45 @@ function SWEP:Reload()
local p = self:GetOwner() local p = self:GetOwner()
local inv = p:INV_Get() local inv = p:INV_Get()
if p:KeyPressed( IN_RELOAD ) then if p:KeyPressed( IN_RELOAD ) then
-- for i=1, 2 do local hand = self:GetTempHandedness()
local hand = self:GetTempHandedness()--true--i==2 local wep_table = self:BTable( hand )
local wep_table = self:BTable( hand ) local wep_class = self:BClass( hand )
local wep_class = self:BClass( hand ) if wep_table then
if wep_table then if wep_class.Reload then
print( "First Test: ", i, wep_table, WEAPONS[wep_table.Class].Name ) if wep_class.Reload( self, wep_table ) then return end
if wep_class.Reload then end
if wep_class.Reload( self, wep_table ) then return end if self:D_GetDelay( hand ) > CurTime() then
end return false
if self:D_GetDelay( hand ) > CurTime() then end
return false
end
local mid = self:D_GetMagID( hand ) local mid = self:D_GetMagID( hand )
if SERVER or (CLIENT and IsFirstTimePredicted()) then
if mid != "" then if mid != "" then
B_Sound( self, wep_class.Sound_MagOut )
if inv[mid].Ammo == 0 then if inv[mid].Ammo == 0 then
if SERVER or (CLIENT and IsFirstTimePredicted()) then if SERVER or (CLIENT and IsFirstTimePredicted()) then
p:INV_Discard( mid ) p:INV_Discard( mid )
end end
end end
self:D_SetClip( hand, 0 )
self:D_SetMagID( hand, "" ) self:D_SetMagID( hand, "" )
self:D_SetClip( hand, 0 )
B_Sound( self, wep_class.Sound_MagOut )
wep_table.Loaded = "" wep_table.Loaded = ""
else else
local maglist = p:INV_FindMag( "mag_" .. wep_table.Class ) local maglist = p:INV_FindMag( "mag_" .. wep_table.Class )
PrintTable( maglist )
local mag = maglist[1] local mag = maglist[1]
if mag then if mag then
if hand then self:D_SetMagID( hand, mag )
self:SetWep2_Clip( mag ) self:D_SetClip( hand, inv[mag].Ammo )
self:SetClip2( inv[mag].Ammo ) wep_table.Loaded = mag
inv[self:GetWep2()].Loaded = mag
else
self:SetWep1_Clip( mag )
self:SetClip1( inv[mag].Ammo )
inv[self:GetWep1()].Loaded = mag
end
-- wep_table.Loaded = mag
-- self:D_SetMagID( hand, mag )
-- self:D_SetClip( hand, inv[mag].Ammo )
B_Sound( self, wep_class.Sound_MagIn ) B_Sound( self, wep_class.Sound_MagIn )
else else
B_Sound( self, "Common.NoAmmo" ) B_Sound( self, "Common.NoAmmo" )
end end
end end
self:TPReload( self:GetTempHandedness() )
end end
-- end self:TPReload( self:GetTempHandedness() )
end
end end
return true return true
end end

View File

@ -240,9 +240,15 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
local scheme = schemes[active] local scheme = schemes[active]
do -- Health do -- Health
local b_w, b_h = ss(142), ss(32)
local b_bh = ss(14)
local b_bh2 = ss(8)
local b_s = ss(4)
local b_s2 = b_s*2
local b_x, b_y = b, sh - b - b_h
-- BG -- BG
surface.SetDrawColor( scheme["bg"] ) surface.SetDrawColor( scheme["bg"] )
surface.DrawRect( b, sh - b - ss(22), ss(140), ss(14+8) ) surface.DrawRect( b_x, b_y, b_w, b_h )
local hp = p:Health()/100 --CurTime()*0.5 % 1 local hp = p:Health()/100 --CurTime()*0.5 % 1
local ti = (CurTime()*0.75 / (hp)) % 1 local ti = (CurTime()*0.75 / (hp)) % 1
@ -250,24 +256,41 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
-- Text underneath -- Text underneath
surface.SetFont( "Benny_18" ) surface.SetFont( "Benny_18" )
surface.SetTextColor( scheme["fg"] ) surface.SetTextColor( scheme["fg"] )
surface.SetTextPos( b + ss(6), sh - b - ss(22) + ss(3) ) surface.SetTextPos( b_x + ss(6), b_y + ss(3) )
surface.DrawText( scheme["name"] ) surface.DrawText( scheme["name"] )
-- Bar -- Bar
surface.SetDrawColor( scheme["fg"] ) surface.SetDrawColor( scheme["fg"] )
surface.DrawRect( b + ss(4), sh - b - ss(22) + ss(4), ss((140*hp)-8), ss(14) ) surface.DrawOutlinedRect( b_x + b_s, b_y + b_s, ss(142-8), b_bh, ss( 0.5 ) )
surface.DrawRect( b_x + b_s + ss(1), b_y + b_s + ss(1), ss(142*hp-8-2), b_bh - ss(2) )
heartbeatcol.a = math.ease.OutQuint(1-ti)*255 heartbeatcol.a = math.ease.OutQuint(1-ti)*255
surface.SetDrawColor( heartbeatcol ) surface.SetDrawColor( heartbeatcol )
surface.SetMaterial( mat_grad ) surface.SetMaterial( mat_grad )
surface.DrawTexturedRect( b + ss(4), sh - b - ss(22) + ss(4), ss((140*hp*ti)-8), ss(14) ) surface.DrawTexturedRect( b_x + b_s + ss(1), b_y + b_s + ss(1), ss(142*hp*ti-8-2), b_bh - ss(2) )
-- Bar text -- Bar text
surface.SetTextColor( scheme["bg"] ) surface.SetTextColor( scheme["bg"] )
surface.SetTextPos( b + ss(6), sh - b - ss(22) + ss(3) ) surface.SetTextPos( b_x + ss(6), b_y + ss(3) )
render.SetScissorRect( b + ss(4), sh - b - ss(22) + ss(4), b + ss(4) + ss((140*hp)-8), sh - b - ss(22) + ss(4) + ss(14), true ) -- Enable the rect render.SetScissorRect( b_x + b_s, b_y + b_s, b_x + b_s + ss(142*hp-8), b_y + b_s + b_bh, true ) -- Enable the rect
surface.DrawText( scheme["name"] ) surface.DrawText( scheme["name"] )
render.SetScissorRect( 0, 0, 0, 0, false ) -- Disable after you are done render.SetScissorRect( 0, 0, 0, 0, false ) -- Disable after you are done
if true then -- Stamina
local perc = CurTime()*0.5 % 2
if perc > 1 then perc = 2-perc end
for i=1, 4 do
local localperc = math.Clamp( math.Remap( perc, (0.25*(i-1)), (0.25*(i)), 0, 1 ), 0, 1 )
surface.SetDrawColor( scheme["fg"] )
surface.DrawOutlinedRect( b_x + b_s + ((i-1)*ss(32+2)), b_y + b_bh + ss(4+2), ss(32), b_bh2, ss(0.5) )
surface.DrawRect( b_x + b_s + ((i-1)*ss(32+2)) + ss(1), b_y + b_bh + ss(4+2) + ss(1), ss(32*localperc) - ss(2), b_bh2 - ss(2) )
end
end
if wep and wep:GetTempHandedness() then
surface.SetDrawColor( scheme["bg"] )
surface.DrawRect( b_x, b_y - ss( 12+3 ), ss( 86 ), ss( 12 ) )
draw.SimpleText( "LEFT-HANDED MODE", "Benny_12", b_x + ss( 2 ), b_y - ss( 12+2 ), scheme["fg"], TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
end
end end
do -- Vaulting do -- Vaulting
@ -348,6 +371,12 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
count = count + 1 count = count + 1
end end
draw.SimpleText( wep:D_GetClip( hand ), "Benny_12", p_x + p_w - pb - ss(1), p_y + p_h - offset - ss(12+3), scheme["fg"], TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) draw.SimpleText( wep:D_GetClip( hand ), "Benny_12", p_x + p_w - pb - ss(1), p_y + p_h - offset - ss(12+3), scheme["fg"], TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP )
if wep:D_GetMagID( hand ) != wep_table.Loaded then
surface.SetDrawColor( scheme["bg"] )
surface.DrawRect( p_x, p_y - ss( 12+3 ), ss( 66 ), ss( 12 ) )
draw.SimpleText( "!! Mag desync.", "Benny_12", p_x + ss( 2 ), p_y - ss( 12+2 ), scheme["fg"], TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
end
end end
if wep_class.Ammo then -- Magazines if wep_class.Ammo then -- Magazines
local m_w, m_h = ss( 14 ), ss( 24 ) local m_w, m_h = ss( 14 ), ss( 24 )
@ -366,7 +395,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
table.insert( newmaglist, v ) table.insert( newmaglist, v )
end end
for id, tag in ipairs( newmaglist ) do for id, tag in ipairs( newmaglist ) do
assert( inv[tag], "That magazine doesn't exist." ) --assert( inv[tag], "That magazine doesn't exist. " .. tag )
local chunk = ((ss(1)+m_w)*(id-1)) local chunk = ((ss(1)+m_w)*(id-1))
surface.SetDrawColor( scheme["bg"] ) surface.SetDrawColor( scheme["bg"] )
surface.DrawRect( m_x - chunk, m_y, m_w, m_h ) surface.DrawRect( m_x - chunk, m_y, m_w, m_h )
@ -727,7 +756,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
end end
end end
if false and p:BennyCheck() then if true and p:BennyCheck() then
local bx, by = sw/2, sh*(0.75) local bx, by = sw/2, sh*(0.75)
local mx = 50 local mx = 50
@ -737,7 +766,9 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
draw.SimpleText( "Clip1: " .. wep:Clip1(), "Trebuchet24", bx-mx, by+24*0, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) draw.SimpleText( "Clip1: " .. wep:Clip1(), "Trebuchet24", bx-mx, by+24*0, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP )
draw.SimpleText( "ID1: " .. wep:GetWep1(), "Trebuchet24", bx-mx, by+24*1, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) draw.SimpleText( "ID1: " .. wep:GetWep1(), "Trebuchet24", bx-mx, by+24*1, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP )
draw.SimpleText( "MagID1: " .. wep:D_GetMagID( false ), "Trebuchet24", bx-mx, by+24*2, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) draw.SimpleText( "MagID1: " .. wep:D_GetMagID( false ), "Trebuchet24", bx-mx, by+24*2, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP )
draw.SimpleText( "T_MagID1: " .. wep1_table.Loaded, "Trebuchet24", bx-mx, by+24*3, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) if wep1_table.Loaded then
draw.SimpleText( "T_MagID1: " .. wep1_table.Loaded, "Trebuchet24", bx-mx, by+24*3, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP )
end
end end
local wep2_table, wep2_class = wep:BTable( true ), wep:BClass( true ) local wep2_table, wep2_class = wep:BTable( true ), wep:BClass( true )
@ -746,7 +777,9 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
draw.SimpleText( "Clip2: " .. wep:Clip2(), "Trebuchet24", bx+mx, by+24*0, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) draw.SimpleText( "Clip2: " .. wep:Clip2(), "Trebuchet24", bx+mx, by+24*0, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
draw.SimpleText( "ID2: " .. wep:GetWep2(), "Trebuchet24", bx+mx, by+24*1, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) draw.SimpleText( "ID2: " .. wep:GetWep2(), "Trebuchet24", bx+mx, by+24*1, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
draw.SimpleText( "MagID2: " .. wep:D_GetMagID( true ), "Trebuchet24", bx+mx, by+24*2, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) draw.SimpleText( "MagID2: " .. wep:D_GetMagID( true ), "Trebuchet24", bx+mx, by+24*2, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
draw.SimpleText( "T_MagID2: " .. wep2_table.Loaded, "Trebuchet24", bx+mx, by+24*3, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) if wep2_table.Loaded then
draw.SimpleText( "T_MagID2: " .. wep2_table.Loaded, "Trebuchet24", bx+mx, by+24*3, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
end
end end
end end
end ) end )
@ -756,9 +789,9 @@ do
local ply = LocalPlayer() local ply = LocalPlayer()
local buckets = ply:INV_Buckets() local buckets = ply:INV_Buckets()
if buckets[bucket_selected] and buckets[bucket_selected][item_selected] then if buckets[bucket_selected] and buckets[bucket_selected][item_selected] then
ply.CLIENTDESIRE = buckets[bucket_selected][item_selected] -- ply.CLIENTDESIRE = buckets[bucket_selected][item_selected]
--RunConsoleCommand( "benny_inv_equip", buckets[bucket_selected][item_selected] ) RunConsoleCommand( "benny_inv_equip", buckets[bucket_selected][item_selected] )
end end
end end
local function Locate( ply, buckets, id ) local function Locate( ply, buckets, id )

View File

@ -46,7 +46,8 @@ end, "arg 1: player ent index, arg 2: classname")
-- PROTO: Move this all into weapon code. -- PROTO: Move this all into weapon code.
concommand.Add("benny_inv_equip", function( ply, cmd, args ) concommand.Add("benny_inv_equip", function( ply, cmd, args )
if ply:BennyCheck() then ply:GetActiveWeapon():BDeploy( args[2] and true or false, args[1] ) end local wep = ply:BennyCheck()
if wep then wep:BDeploy( wep:GetTempHandedness(), args[1] ) end
end, end,
function(cmd, args) function(cmd, args)
args = string.Trim(args:lower()) args = string.Trim(args:lower())
@ -61,7 +62,8 @@ end, "arg 1: item id, arg 2 does offhand")
-- PROTO: Move this all into weapon code. -- PROTO: Move this all into weapon code.
concommand.Add("benny_inv_holster", function( ply, cmd, args ) concommand.Add("benny_inv_holster", function( ply, cmd, args )
if ply:BennyCheck() then ply:GetActiveWeapon():BHolster( ply:GetActiveWeapon():GetTempHandedness() ) end local wep = ply:BennyCheck()
if wep then wep:BHolster( wep:GetTempHandedness() ) end
end) end)
concommand.Add("benny_inv_sync", function( ply, cmd, args ) concommand.Add("benny_inv_sync", function( ply, cmd, args )
@ -91,12 +93,12 @@ concommand.Add("benny_inv_discard", function( ply, cmd, args )
if wep:GetWep1() == args[1] then if wep:GetWep1() == args[1] then
wep:SetWep1( "" ) wep:SetWep1( "" )
wep:SetWep1Clip( 0 ) wep:SetWep1_Clip( "" )
wep:SetClip1( 0 ) wep:SetClip1( 0 )
end end
if wep:GetWep2() == args[1] then if wep:GetWep2() == args[1] then
wep:SetWep2( "" ) wep:SetWep2( "" )
wep:SetWep2Clip( 0 ) wep:SetWep2_Clip( "" )
wep:SetClip2( 0 ) wep:SetClip2( 0 )
end end
end) end)

View File

@ -10,7 +10,7 @@ if easyway then
Player(data.userid).CheckerReady = true Player(data.userid).CheckerReady = true
end ) end )
local checkerinterval = 12 local checkerinterval = 1
util.AddNetworkString( "Benny_Checker" ) util.AddNetworkString( "Benny_Checker" )
hook.Add( "PlayerTick", "Benny_Checker", function( ply ) hook.Add( "PlayerTick", "Benny_Checker", function( ply )
@ -23,7 +23,7 @@ if easyway then
net.WriteString( i ) net.WriteString( i )
net.WriteTable( v ) net.WriteTable( v )
end end
print( net.BytesWritten() ) print( ply, net.BytesWritten() )
net.Send( ply ) net.Send( ply )
ply.CheckerLast = CurTime() ply.CheckerLast = CurTime()
end end
@ -62,6 +62,9 @@ if SERVER then
net.WriteUInt( table.Count(inv), UINTBITS ) net.WriteUInt( table.Count(inv), UINTBITS )
for i, v in pairs( inv ) do for i, v in pairs( inv ) do
net.WriteString( i ) net.WriteString( i )
net.WriteBool( v.Loaded )
if v.Loaded then net.WriteString( v.Loaded ) end
end end
net.Send( ply ) net.Send( ply )
ply.CheckerLast = CurTime() ply.CheckerLast = CurTime()
@ -108,7 +111,13 @@ else
local amt = net.ReadUInt( UINTBITS ) local amt = net.ReadUInt( UINTBITS )
local evallist = {} local evallist = {}
for i=1, amt do for i=1, amt do
evallist[net.ReadString()] = true local id = net.ReadString()
local loaded_exists = net.ReadBool()
local loaded = nil
if loaded_exists then
loaded = net.ReadString()
end
evallist[id] = loaded or true
end end
local inv = ply:INV_Get() local inv = ply:INV_Get()
@ -118,6 +127,9 @@ else
for i, v in pairs( evallist ) do for i, v in pairs( evallist ) do
if inv[i] then if inv[i] then
-- Success -- Success
if isstring(v) then
inv[i].Loaded = v
end
else else
missinglist[i] = true missinglist[i] = true
end end

View File

@ -178,25 +178,24 @@ end
-- weapon select -- weapon select
hook.Add("StartCommand", "Benny_INV_StartCommand", function( ply, cmd ) hook.Add("StartCommand", "Benny_INV_StartCommand", function( ply, cmd )
local wep = ply:BennyCheck() -- local wep = ply:BennyCheck()
if wep then -- if wep then
local inv = ply:INV_Get() -- local hand = wep:GetTempHandedness()
local inv_bucketlist = ply:INV_ListFromBuckets() -- local inv = ply:INV_Get()
local inv_bucketlist_flipped = table.Flip( inv_bucketlist ) -- local inv_bucketlist = ply:INV_ListFromBuckets()
if CLIENT and ply.CLIENTDESIRE and inv[ply.CLIENTDESIRE ] and inv_bucketlist_flipped[ ply.CLIENTDESIRE ] then -- local inv_bucketlist_flipped = table.Flip( inv_bucketlist )
cmd:SetUpMove( inv_bucketlist_flipped[ ply.CLIENTDESIRE ] ) -- if CLIENT and ply.CLIENTDESIRE and inv[ply.CLIENTDESIRE ] and inv_bucketlist_flipped[ ply.CLIENTDESIRE ] then
end -- cmd:SetUpMove( inv_bucketlist_flipped[ ply.CLIENTDESIRE ] )
local id = cmd:GetUpMove() -- end
local hand = wep:GetTempHandedness() -- if CLIENT and (wep:D_GetID( hand ) == ply.CLIENTDESIRE) then
if id > 0 and inv_bucketlist[id] and inv[inv_bucketlist[id]] then -- ply.CLIENTDESIRE = 0
wep:BDeploy( hand, inv_bucketlist[ id ] ) -- print("Fixed")
if CLIENT and (wep:D_GetID( hand ) == ply.CLIENTDESIRE) then -- end
ply.CLIENTDESIRE = 0 -- local id = cmd:GetUpMove()
print("Fixed") -- if id > 0 and inv_bucketlist[id] and inv[inv_bucketlist[id]] then
end -- wep:BDeploy( hand, inv_bucketlist[ id ] )
end -- end
-- end
end
end) end)