Better weapon spawning and discarding logic

This commit is contained in:
Fesiug 2023-12-30 21:18:41 -05:00
parent 2e0f0cbcb5
commit 4a3eb4b949
1 changed files with 39 additions and 14 deletions

View File

@ -1,21 +1,16 @@
if SERVER then if SERVER then
util.AddNetworkString( "benny_syncinv" )
util.AddNetworkString( "benny_sendinvitem" ) util.AddNetworkString( "benny_sendinvitem" )
util.AddNetworkString( "benny_discardinvitem" ) util.AddNetworkString( "benny_discardinvitem" )
end end
concommand.Add("benny_debug_give", function(ply, cmd, args) function BENNY.CreateItem( classname )
assert(SERVER, "not server") local class = WeaponGet(classname)
local inv = ply:INV_Get()
local str = UUID_generate()
local class = WeaponGet(args[1]) assert( class, "Invalid Class " .. tostring(classname) )
assert(class, "Invalid Class " .. tostring(class))
local item = { local item = {
Class = args[1], Class = classname,
Acquisition = CurTime(), Acquisition = CurTime(),
} }
@ -25,12 +20,21 @@ concommand.Add("benny_debug_give", function(ply, cmd, args)
item.Ammo = class.Ammo item.Ammo = class.Ammo
end end
inv[str] = item return item
end
concommand.Add("benny_debug_give", function(ply, cmd, args)
assert(SERVER, "not server")
local inv = ply:INV_Get()
local str = UUID_generate()
local newitem = BENNY.CreateItem( args[1] )
inv[str] = newitem
-- PROTO: WriteTable. -- PROTO: WriteTable.
net.Start( "benny_sendinvitem" ) net.Start( "benny_sendinvitem" )
net.WriteString( str ) net.WriteString( str )
net.WriteTable( item ) net.WriteTable( newitem )
net.Send( ply ) net.Send( ply )
end, end,
function(cmd, args) function(cmd, args)
@ -42,7 +46,16 @@ function(cmd, args)
end end
end end
return meow return meow
end, "arg 1: player ent index, arg 2: classname") end, "arg 1: classname")
if CLIENT then
net.Receive( "benny_sendinvitem", function()
LocalPlayer():INV_Get()[net.ReadString()] = net.ReadTable()
end)
net.Receive( "benny_discardinvitem", function()
LocalPlayer():INV_Get()[net.ReadString()] = nil
end)
end
concommand.Add("benny_inv_discard", function( ply, cmd, args ) concommand.Add("benny_inv_discard", function( ply, cmd, args )
local inv = ply:INV_Get() local inv = ply:INV_Get()
@ -56,16 +69,28 @@ concommand.Add("benny_inv_discard", function( ply, cmd, args )
net.WriteString( args[1] ) net.WriteString( args[1] )
net.Send( ply ) net.Send( ply )
if wep:GetWep1() == args[1] then if wep:D_GetID( false ) == args[1] then
print( "Disequipped " .. args[1] .. " for " .. tostring(wep) )
wep:SetWep1( "" ) wep:SetWep1( "" )
wep:SetWep1_Clip( "" ) wep:SetWep1_Clip( "" )
wep:SetClip1( 0 ) wep:SetClip1( 0 )
end end
if wep:GetWep2() == args[1] then if wep:D_GetID( true ) == args[1] then
print( "Disequipped " .. args[1] .. " for " .. tostring(wep) )
wep:SetWep2( "" ) wep:SetWep2( "" )
wep:SetWep2_Clip( "" ) wep:SetWep2_Clip( "" )
wep:SetClip2( 0 ) wep:SetClip2( 0 )
end end
if wep:D_GetMagID( false ) == args[1] then
inv[wep:D_GetID( false )].Loaded = ""
wep:SetWep1_Clip( "" )
wep:SetClip1( 0 )
end
if wep:D_GetMagID( true ) == args[1] then
inv[wep:D_GetID( true )].Loaded = ""
wep:SetWep2_Clip( "" )
wep:SetClip2( 0 )
end
end) end)
hook.Add( "PlayerDeathSound", "Benny_PlayerDeathSound", function( ply ) hook.Add( "PlayerDeathSound", "Benny_PlayerDeathSound", function( ply )