2023-09-13 22:15:43 -04:00
|
|
|
|
2023-09-24 01:19:23 -04:00
|
|
|
if SERVER then
|
2023-09-25 17:26:52 -04:00
|
|
|
util.AddNetworkString( "benny_syncinv" )
|
|
|
|
util.AddNetworkString( "benny_sendinvitem" )
|
|
|
|
util.AddNetworkString( "benny_discardinvitem" )
|
2023-09-24 01:19:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
concommand.Add("benny_debug_give", function(ply, cmd, args)
|
|
|
|
assert(SERVER, "not server")
|
|
|
|
local inv = ply:INV_Get()
|
|
|
|
local str = UUID_generate()
|
|
|
|
|
2023-11-29 18:40:45 -05:00
|
|
|
local class = WeaponGet(args[1])
|
2023-09-24 01:19:23 -04:00
|
|
|
|
2023-09-24 17:50:42 -04:00
|
|
|
assert(class, "Invalid Class.")
|
|
|
|
|
2023-09-24 01:19:23 -04:00
|
|
|
local item = {
|
2023-11-16 02:11:42 -05:00
|
|
|
Class = args[1],
|
2023-11-12 19:59:12 -05:00
|
|
|
Acquisition = CurTime(),
|
2023-09-24 01:19:23 -04:00
|
|
|
}
|
|
|
|
|
2023-11-16 22:00:11 -05:00
|
|
|
if class.Features == "firearm" then
|
|
|
|
item.Loaded = ""
|
|
|
|
elseif class.Features == "magazine" then
|
|
|
|
item.Ammo = class.Ammo
|
|
|
|
end
|
|
|
|
|
2023-09-24 01:19:23 -04:00
|
|
|
inv[str] = item
|
|
|
|
|
|
|
|
-- PROTO: WriteTable.
|
2023-09-25 17:26:52 -04:00
|
|
|
net.Start( "benny_sendinvitem" )
|
2023-09-24 01:19:23 -04:00
|
|
|
net.WriteString( str )
|
|
|
|
net.WriteTable( item )
|
|
|
|
net.Send( ply )
|
2023-11-16 02:11:42 -05:00
|
|
|
end,
|
|
|
|
function(cmd, args)
|
|
|
|
args = string.Trim(args:lower())
|
|
|
|
local meow = {}
|
|
|
|
for i, v in SortedPairs( WEAPONS ) do
|
|
|
|
if string.lower(i):find(args) then
|
|
|
|
table.insert( meow, cmd .. " " .. i )
|
|
|
|
end
|
2023-09-24 01:19:23 -04:00
|
|
|
end
|
2023-11-16 02:11:42 -05:00
|
|
|
return meow
|
|
|
|
end, "arg 1: player ent index, arg 2: classname")
|
2023-09-24 01:19:23 -04:00
|
|
|
|
2023-09-24 18:38:00 -04:00
|
|
|
-- PROTO: Move this all into weapon code.
|
|
|
|
concommand.Add("benny_inv_equip", function( ply, cmd, args )
|
2023-11-17 21:12:25 -05:00
|
|
|
local wep = ply:BennyCheck()
|
2023-11-17 22:56:41 -05:00
|
|
|
if wep then
|
2023-11-29 00:39:42 -05:00
|
|
|
local hand = args[2]!=nil and tobool(args[2])
|
2023-11-17 22:56:41 -05:00
|
|
|
local id = args[1]
|
|
|
|
local swap_or_replace = tobool(args[3])
|
|
|
|
|
|
|
|
local L, R = true, false
|
|
|
|
local curr_r = wep:D_GetID( false )
|
|
|
|
local curr_l = wep:D_GetID( true )
|
|
|
|
|
|
|
|
if hand == R then
|
|
|
|
if curr_r == id then
|
|
|
|
-- We already have this equipped
|
|
|
|
return
|
|
|
|
elseif swap_or_replace and curr_r != "" then
|
|
|
|
-- We already have something equipped here, move it to the offhand
|
|
|
|
wep:BDeploy( L, curr_r )
|
|
|
|
elseif curr_l == id then
|
|
|
|
-- You have the gun we want, snatched
|
|
|
|
wep:BHolster( L )
|
|
|
|
end
|
|
|
|
wep:BDeploy( R, id )
|
|
|
|
elseif hand == L then
|
|
|
|
if curr_l == id then
|
|
|
|
-- We already have this equipped
|
|
|
|
return
|
|
|
|
elseif swap_or_replace and curr_l != "" then
|
|
|
|
-- We already have something equipped here, move it to the offhand
|
|
|
|
wep:BDeploy( R, curr_l )
|
|
|
|
elseif curr_r == id then
|
|
|
|
-- You have the gun we want, snatched
|
|
|
|
wep:BHolster( R )
|
|
|
|
end
|
|
|
|
wep:BDeploy( L, id )
|
|
|
|
end
|
|
|
|
end
|
2023-11-16 22:00:11 -05:00
|
|
|
end,
|
|
|
|
function(cmd, args)
|
|
|
|
args = string.Trim(args:lower())
|
|
|
|
local meow = {}
|
|
|
|
for i, v in SortedPairs( Entity(1):INV_Get() ) do
|
|
|
|
if string.lower(i):find(args) then
|
|
|
|
table.insert( meow, cmd .. " " .. i )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return meow
|
|
|
|
end, "arg 1: item id, arg 2 does offhand")
|
2023-09-24 18:38:00 -04:00
|
|
|
|
2023-11-13 18:22:28 -05:00
|
|
|
-- PROTO: Move this all into weapon code.
|
|
|
|
concommand.Add("benny_inv_holster", function( ply, cmd, args )
|
2023-11-17 21:12:25 -05:00
|
|
|
local wep = ply:BennyCheck()
|
2023-11-29 02:45:36 -05:00
|
|
|
if wep then
|
|
|
|
if wep:D_GetID( false ) == args[1] then
|
|
|
|
wep:BHolster( false )
|
|
|
|
elseif wep:D_GetID( true ) == args[1] then
|
|
|
|
wep:BHolster( true )
|
|
|
|
end
|
|
|
|
end
|
2023-09-24 18:38:00 -04:00
|
|
|
end)
|
|
|
|
|
2023-09-25 17:26:52 -04:00
|
|
|
concommand.Add("benny_inv_sync", function( ply, cmd, args )
|
|
|
|
local inv = ply:INV_Get()
|
|
|
|
|
|
|
|
-- PROTO: WriteTable.
|
|
|
|
net.Start("benny_syncinv")
|
|
|
|
net.WriteUInt( table.Count( inv ), 4 )
|
|
|
|
for ID, Data in pairs( inv ) do
|
|
|
|
net.WriteString( ID )
|
|
|
|
net.WriteTable( Data )
|
|
|
|
end
|
|
|
|
net.Send( ply )
|
|
|
|
end)
|
|
|
|
|
|
|
|
concommand.Add("benny_inv_discard", function( ply, cmd, args )
|
|
|
|
local inv = ply:INV_Get()
|
|
|
|
local wep = ply:GetActiveWeapon()
|
|
|
|
local item = inv[args[1]]
|
|
|
|
-- PROTO: Check that this is the correct 'benny' weapon.
|
2023-10-09 17:05:55 -04:00
|
|
|
assert( item, "That item doesn't exist. " .. tostring(item) )
|
2023-09-25 17:26:52 -04:00
|
|
|
|
|
|
|
inv[args[1]] = nil
|
|
|
|
net.Start( "benny_discardinvitem" )
|
|
|
|
net.WriteString( args[1] )
|
|
|
|
net.Send( ply )
|
|
|
|
|
|
|
|
if wep:GetWep1() == args[1] then
|
|
|
|
wep:SetWep1( "" )
|
2023-11-17 21:12:25 -05:00
|
|
|
wep:SetWep1_Clip( "" )
|
2023-09-25 17:26:52 -04:00
|
|
|
wep:SetClip1( 0 )
|
|
|
|
end
|
|
|
|
if wep:GetWep2() == args[1] then
|
|
|
|
wep:SetWep2( "" )
|
2023-11-17 21:12:25 -05:00
|
|
|
wep:SetWep2_Clip( "" )
|
2023-09-25 17:26:52 -04:00
|
|
|
wep:SetClip2( 0 )
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Network to client
|
|
|
|
if CLIENT then
|
|
|
|
net.Receive( "benny_syncinv", function( len, ply )
|
|
|
|
local ply = LocalPlayer()
|
|
|
|
local inv = ply:INV_Get()
|
|
|
|
|
|
|
|
table.Empty( inv )
|
|
|
|
for i=1, net.ReadUInt( 4 ) do
|
|
|
|
inv[net.ReadString()] = net.ReadTable()
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
net.Receive( "benny_sendinvitem", function( len, ply )
|
|
|
|
local ply = LocalPlayer()
|
|
|
|
ply:INV_Get()[net.ReadString()] = net.ReadTable()
|
|
|
|
end)
|
|
|
|
net.Receive( "benny_discardinvitem", function( len, ply )
|
|
|
|
local ply = LocalPlayer()
|
|
|
|
ply:INV_Get()[net.ReadString()] = nil
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2023-11-06 14:03:24 -05:00
|
|
|
hook.Add( "PlayerDeathSound", "Benny_PlayerDeathSound", function( ply )
|
|
|
|
return true -- we don't want the default sound!
|
|
|
|
end )
|
|
|
|
|
2023-12-04 18:20:18 -05:00
|
|
|
if CLIENT then
|
|
|
|
hook.Add( "PlayerButtonDown", "Benny_PlayerButtonDown_Dev", function( ply, button )
|
|
|
|
local wep = ply:BennyCheck()
|
2023-11-29 18:00:08 -05:00
|
|
|
|
2023-12-04 18:20:18 -05:00
|
|
|
if button == KEY_F1 then
|
|
|
|
OpenSettingsMenu()
|
|
|
|
elseif button == KEY_F2 then
|
2023-12-08 00:29:09 -05:00
|
|
|
OpenDebugInv()
|
2023-12-04 18:20:18 -05:00
|
|
|
elseif button == KEY_F3 then
|
|
|
|
OpenSMenu()
|
|
|
|
elseif button == KEY_F4 then
|
|
|
|
OpenDeadeye()
|
|
|
|
elseif button == KEY_F5 then
|
|
|
|
elseif button == KEY_F6 then
|
|
|
|
elseif button == KEY_F7 then
|
|
|
|
elseif button == KEY_F8 then
|
|
|
|
elseif button == KEY_F9 then
|
|
|
|
elseif button == KEY_F11 then
|
|
|
|
elseif button == KEY_F12 then
|
2023-11-13 18:22:28 -05:00
|
|
|
end
|
2023-12-04 18:20:18 -05:00
|
|
|
end)
|
2023-09-13 22:15:43 -04:00
|
|
|
end
|