2023-09-13 22:15:43 -04:00
|
|
|
|
2023-09-23 22:51:35 -04:00
|
|
|
function GM:PlayerSpawn( ply )
|
|
|
|
player_manager.SetPlayerClass( ply, "player_benny" )
|
|
|
|
ply:SetModel( "models/player/combine_super_soldier.mdl" )
|
2023-10-31 19:06:20 -04:00
|
|
|
ply:SetViewOffset( Vector( 0, 0, 64 ) )
|
|
|
|
ply:SetViewOffsetDucked( Vector( 0, 0, 50 ) )
|
2023-09-23 22:51:35 -04:00
|
|
|
ply:SetPlayerColor( Vector( 0.275, 0.2, 0.145 ) )
|
2023-09-13 22:15:43 -04:00
|
|
|
ply:Give( "benny" )
|
2023-10-31 19:06:20 -04:00
|
|
|
|
|
|
|
ply:SetCrouchedWalkSpeed( 0.3 )
|
|
|
|
ply:SetDuckSpeed( 0.1 )
|
|
|
|
ply:SetUnDuckSpeed( 0.1 )
|
|
|
|
ply:SetSlowWalkSpeed( 100 )
|
|
|
|
ply:SetWalkSpeed( 160 )
|
|
|
|
ply:SetRunSpeed( 220 )
|
2023-09-24 01:19:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
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")
|
|
|
|
-- PROTO: Check for the correct 'benny' weapon.
|
|
|
|
local ply = Entity( args[1] )
|
|
|
|
local wep = ply:GetActiveWeapon()
|
|
|
|
local inv = ply:INV_Get()
|
|
|
|
local str = UUID_generate()
|
|
|
|
|
|
|
|
local class = WEAPONS[args[3]]
|
|
|
|
|
2023-09-24 17:50:42 -04:00
|
|
|
assert(class, "Invalid Class.")
|
|
|
|
|
2023-09-24 01:19:23 -04:00
|
|
|
local item = {
|
|
|
|
Class = args[3],
|
2023-09-25 17:26:52 -04:00
|
|
|
Loaded = 1,
|
|
|
|
Ammo1 = class.Ammo,
|
|
|
|
Ammo2 = class.Ammo,
|
|
|
|
Ammo3 = class.Ammo,
|
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 )
|
|
|
|
|
|
|
|
local slot = tonumber(args[2])
|
|
|
|
|
|
|
|
if slot == 1 then
|
|
|
|
wep:SetWep1( str )
|
2023-09-25 17:26:52 -04:00
|
|
|
wep:SetWep1Clip( item.Loaded )
|
|
|
|
wep:SetClip1( item[ "Ammo" .. item.Loaded ] )
|
2023-09-24 01:19:23 -04:00
|
|
|
elseif slot == 2 then
|
|
|
|
wep:SetWep2( str )
|
2023-09-25 17:26:52 -04:00
|
|
|
wep:SetWep2Clip( item.Loaded )
|
|
|
|
wep:SetClip2( item[ "Ammo" .. item.Loaded ] )
|
2023-09-24 01:19:23 -04:00
|
|
|
else
|
|
|
|
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2023-09-24 18:38:00 -04:00
|
|
|
-- PROTO: Move this all into weapon code.
|
|
|
|
concommand.Add("benny_inv_equip", 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-24 18:38:00 -04:00
|
|
|
|
|
|
|
wep:SetWep1( args[1] )
|
2023-09-25 17:26:52 -04:00
|
|
|
wep:SetWep1Clip( item.Loaded )
|
|
|
|
|
2023-09-25 20:42:37 -04:00
|
|
|
if item.Loaded != 0 then
|
|
|
|
assert( item[ "Ammo" .. item.Loaded ], "That magazine doesn't exist." )
|
|
|
|
end
|
|
|
|
wep:SetClip1( item.Loaded == 0 and 0 or item[ "Ammo" .. item.Loaded ] )
|
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( "" )
|
|
|
|
wep:SetWep1Clip( 0 )
|
|
|
|
wep:SetClip1( 0 )
|
|
|
|
end
|
|
|
|
if wep:GetWep2() == args[1] then
|
|
|
|
wep:SetWep2( "" )
|
|
|
|
wep:SetWep2Clip( 0 )
|
|
|
|
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
|
|
|
|
|
|
|
|
function GM:ShowHelp( ply )
|
|
|
|
if SERVER then
|
|
|
|
ply:SendLua( [[OpenSMenu()]] )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-31 21:33:07 -04:00
|
|
|
function GM:ShowTeam( ply )
|
|
|
|
if SERVER then
|
|
|
|
ply:SendLua( [[OpenDeadeye()]] )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-09-24 18:38:00 -04:00
|
|
|
-- Debug inv
|
2023-09-24 17:50:42 -04:00
|
|
|
if CLIENT then
|
2023-09-25 17:26:52 -04:00
|
|
|
function GM:OnSpawnMenuOpen()
|
|
|
|
RunConsoleCommand( "benny_debug_inv" )
|
|
|
|
end
|
|
|
|
function GM:OnSpawnMenuClose()
|
|
|
|
if IsValid( base ) then base:Remove() end
|
|
|
|
end
|
|
|
|
|
|
|
|
function OpenSMenu()
|
|
|
|
if IsValid( smenu ) then smenu:Remove() return end
|
|
|
|
smenu = vgui.Create("DFrame")
|
|
|
|
smenu:SetSize( ss(400), ss(240) )
|
|
|
|
smenu:MakePopup()
|
|
|
|
smenu:SetKeyboardInputEnabled( false )
|
|
|
|
smenu:Center()
|
|
|
|
|
|
|
|
function smenu:Paint( w, h )
|
|
|
|
surface.SetDrawColor( schemes["benny"]["bg"] )
|
|
|
|
surface.DrawRect( 0, 0, w, h )
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local itemlist = smenu:Add("DScrollPanel")
|
|
|
|
itemlist:Dock( FILL )
|
2023-10-22 00:37:12 -04:00
|
|
|
|
|
|
|
local List = vgui.Create( "DIconLayout", itemlist )
|
|
|
|
List:Dock( FILL )
|
|
|
|
List:SetSpaceX( 5 )
|
|
|
|
List:SetSpaceY( 5 )
|
2023-09-25 17:26:52 -04:00
|
|
|
|
|
|
|
for ClassName, Class in SortedPairsByMemberValue( WEAPONS, "Name" ) do
|
|
|
|
local button = vgui.Create( "DButton" )
|
2023-10-22 00:37:12 -04:00
|
|
|
List:Add( button )
|
|
|
|
button:SetSize( ss(96), ss(22) )
|
|
|
|
--button:Dock( TOP )
|
2023-09-25 17:26:52 -04:00
|
|
|
button:DockMargin( 0, 0, 0, ss(4) )
|
|
|
|
|
|
|
|
button.Text_Name = Class.Name
|
|
|
|
button.Text_Desc = Class.Description
|
|
|
|
|
|
|
|
-- PROTO: These functions don't need to be remade over and over like this.
|
|
|
|
function button:DoClick()
|
|
|
|
RunConsoleCommand( "benny_debug_give", LocalPlayer():EntIndex(), 0, ClassName )
|
|
|
|
end
|
|
|
|
|
|
|
|
function button:DoRightClick()
|
|
|
|
end
|
|
|
|
|
|
|
|
function button:Paint( w, h )
|
|
|
|
surface.SetDrawColor( schemes["benny"]["fg"] )
|
|
|
|
surface.DrawRect( 0, 0, w, h )
|
|
|
|
|
|
|
|
surface.SetTextColor( schemes["benny"]["bg"] )
|
|
|
|
|
|
|
|
surface.SetFont( "Benny_16" )
|
|
|
|
surface.SetTextPos( ss(4), ss(4) )
|
|
|
|
surface.DrawText( self.Text_Name )
|
|
|
|
|
2023-10-22 00:37:12 -04:00
|
|
|
-- surface.SetFont( "Benny_10" )
|
|
|
|
-- surface.SetTextPos( ss(4), ss(4 + 12) )
|
|
|
|
-- surface.DrawText( self.Text_Desc )
|
2023-09-25 17:26:52 -04:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-09-24 17:50:42 -04:00
|
|
|
local function regen_items( itemlist )
|
|
|
|
local ply = LocalPlayer()
|
|
|
|
itemlist:Clear()
|
|
|
|
|
|
|
|
for i, v in pairs( ply:INV_Get() ) do
|
|
|
|
local button = vgui.Create( "DButton" )
|
|
|
|
itemlist:AddItem( button )
|
|
|
|
button:SetSize( 1, ss(36) )
|
|
|
|
button:Dock( TOP )
|
|
|
|
button:DockMargin( 0, 0, 0, ss(4) )
|
|
|
|
|
2023-09-24 18:38:00 -04:00
|
|
|
button.ID = i
|
2023-09-24 17:50:42 -04:00
|
|
|
local Class = WEAPONS[v.Class]
|
|
|
|
button.Text_Name = Class.Name
|
|
|
|
button.Text_Desc = Class.Description
|
|
|
|
|
2023-09-24 18:38:00 -04:00
|
|
|
-- PROTO: These functions don't need to be remade over and over like this.
|
|
|
|
function button:DoClick()
|
2023-09-25 17:26:52 -04:00
|
|
|
RunConsoleCommand("benny_inv_equip", button.ID)
|
2023-09-25 20:42:37 -04:00
|
|
|
timer.Simple( 0.1, function() if IsValid( itemlist ) then regen_items( itemlist ) end end )
|
2023-09-24 18:38:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function button:DoRightClick()
|
2023-09-25 17:26:52 -04:00
|
|
|
RunConsoleCommand("benny_inv_discard", button.ID)
|
2023-09-25 20:42:37 -04:00
|
|
|
timer.Simple( 0.1, function() if IsValid( itemlist ) then regen_items( itemlist ) end end )
|
2023-09-24 18:38:00 -04:00
|
|
|
end
|
|
|
|
|
2023-09-24 17:50:42 -04:00
|
|
|
function button:Paint( w, h )
|
|
|
|
surface.SetDrawColor( schemes["benny"]["fg"] )
|
|
|
|
surface.DrawRect( 0, 0, w, h )
|
|
|
|
|
|
|
|
surface.SetTextColor( schemes["benny"]["bg"] )
|
|
|
|
|
|
|
|
surface.SetFont( "Benny_16" )
|
|
|
|
surface.SetTextPos( ss(4), ss(4) )
|
|
|
|
surface.DrawText( self.Text_Name )
|
|
|
|
|
2023-09-25 17:26:52 -04:00
|
|
|
surface.SetFont( "Benny_12" )
|
2023-09-24 17:50:42 -04:00
|
|
|
surface.SetTextPos( ss(4), ss(4 + 12) )
|
|
|
|
surface.DrawText( self.Text_Desc )
|
|
|
|
|
2023-09-25 17:26:52 -04:00
|
|
|
surface.SetFont( "Benny_12" )
|
|
|
|
local tx = surface.GetTextSize( self.ID )
|
|
|
|
surface.SetTextPos( w - ss(4) - tx, ss(4) )
|
2023-09-24 18:38:00 -04:00
|
|
|
surface.DrawText( self.ID )
|
2023-09-24 17:50:42 -04:00
|
|
|
return true
|
|
|
|
end
|
2023-09-24 16:26:55 -04:00
|
|
|
end
|
|
|
|
end
|
2023-09-24 17:50:42 -04:00
|
|
|
concommand.Add("benny_debug_inv", function()
|
|
|
|
if IsValid( base ) then base:Remove() end
|
|
|
|
base = vgui.Create("DFrame")
|
2023-09-25 17:26:52 -04:00
|
|
|
base:SetSize( ss(400), ss(240) )
|
2023-09-24 17:50:42 -04:00
|
|
|
base:MakePopup()
|
2023-09-25 17:26:52 -04:00
|
|
|
base:SetKeyboardInputEnabled( false )
|
2023-09-24 17:50:42 -04:00
|
|
|
base:Center()
|
|
|
|
|
|
|
|
function base:Paint( w, h )
|
|
|
|
surface.SetDrawColor( schemes["benny"]["bg"] )
|
|
|
|
surface.DrawRect( 0, 0, w, h )
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local itemlist = base:Add("DScrollPanel")
|
|
|
|
itemlist:Dock( FILL )
|
|
|
|
|
|
|
|
regen_items( itemlist )
|
|
|
|
end)
|
2023-09-13 22:15:43 -04:00
|
|
|
end
|