Benny/gamemodes/benny/gamemode/debugmenu.lua

58 lines
1.4 KiB
Lua

---------------------
-- Your Name is Benny
---------------------
if SERVER then
util.AddNetworkString( "Benny_DebugMenuSpawn" )
net.Receive( "Benny_DebugMenuSpawn", function( len, ply )
if !ply:IsAdmin() then return end
local ent = ents.Create( "b-item_" .. net.ReadString() )
ent:SetPos( ply:GetEyeTrace().HitPos )
ent:Spawn()
end)
return
end
local function dospawn( self )
net.Start( "Benny_DebugMenuSpawn" )
net.WriteString( self.iName )
net.SendToServer()
end
local function OpenDebugMenu()
if IsValid(DebugMenu) then DebugMenu:Remove() end
DebugMenu = vgui.Create("DFrame")
DebugMenu:SetSize( 400, 300 )
DebugMenu:Center()
DebugMenu:MakePopup()
local opt = DebugMenu:Add("DCollapsibleCategory")
opt:Dock( TOP )
local plist = DebugMenu:Add("DScrollPanel")
opt:SetContents( plist )
for iname, idata in SortedPairs( ITEMS ) do
local button = plist:Add("DButton")
button:Dock( TOP )
button:DockMargin( 4, 4, 4, 0 )
button:SetText( l8( idata.PrintName ) )
button.iName = iname
button.iData = idata
button.DoClick = dospawn
end
end
hook.Add("PlayerButtonDown", "PlayerButtonDown_DebugMenu", function( ply, button )
if button == KEY_F1 then
OpenDebugMenu()
end
end)
hook.Add("PlayerButtonUp", "PlayerButtonUp_DebugMenu", function( ply, button )
if button == KEY_F1 then
--if IsValid(DebugMenu) then DebugMenu:Remove() end
end
end)