Opening Derma With a Chat Command

mr current code:


 if SERVER then 
  AddCSLuaFile ("server.lua")
  concommand.Add("playermodel_set", function(ply, cmd, argStr)
    if ply:GetUserGroup() == "superadmin" or ply:Team()==18 then ply:SetModel(argStr[1])
	else ply:ChatPrint("You cant use this!")  end
	
  end)
 end
 if CLIENT then
 local Frame = vgui.Create( "DFrame" )
Frame:SetTitle( "SELECT MODEL" )
Frame:SetSize( 600, 300 )
Frame:SetPos(200,100)
Frame:MakePopup()
Frame:SetDraggable( true )
Frame:ShowCloseButton( true )

Frame.Paint = function( self)
	draw.RoundedBox( 0, 0, 0, 600, 300, Color( 0, 0, 0, 200 ) ) 

	
local SpawnI = vgui.Create("SpawnIcon")
SpawnI:SetPos(200,100)	
SpawnI:SetParent(Frame)
SpawnI:SetModel("models/weapons/w_knife_ct.mdl")


SpawnI.DoClick = function()
        SpawnI:Close()
	RunConsoleCommand("playermodel_set","models/weapons/w_knife_ct.mdl")
	Frame:Close()
end
end

end

wiki.garrysmod.com/page/GM/PlayerSay

Use playersay and umsgs to open the menu.

Please,

Serverside:



util.AddNetworkString("Whatever")

hook.Add("PlayerSay", "asd", function(ply, text, teamonly)
if text == whatever then
net.Start("Whatever")
net.Send(ply)
end
end)


Clientside:



net.Receive("Whatever", function()
--your menu code here
end)


Thanks, It worked! but i need to know how to load lua file to server and client in same time

Or use OnPlayerChat to avoid using a net message.



if SERVER then

hook.Add("PlayerSay", "DermaCommands", function(ply)
	if(string.sub(text, 1, 6) == "/models")then	
		net.Start("derma_panel_modelsmenu")
		net.Send(ply)
	end
end)

elseif CLIENT then
function Panel()
 local Frame = vgui.Create( "DFrame" )
Frame:SetTitle( "SELECT MODEL" )
Frame:SetSize( 600, 300 )
Frame:SetPos(200,100)
Frame:MakePopup()
Frame:SetDraggable( true )
Frame:ShowCloseButton( true )

Frame.Paint = function( self)
	draw.RoundedBox( 0, 0, 0, 600, 300, Color( 0, 0, 0, 200 ) ) 

	
local SpawnI = vgui.Create("SpawnIcon")
SpawnI:SetPos(200,100)	
SpawnI:SetParent(Frame)
SpawnI:SetModel("models/weapons/w_knife_ct.mdl")


SpawnI.DoClick = function()
        SpawnI:Close()
	RunConsoleCommand("playermodel_set","models/weapons/w_knife_ct.mdl")
	Frame:Close()
end
end
end

net.Receive("derma_panel_modelsmenu", Panel)

end


Thats you’re full and ending code for that, hope you learn something from it!

The last user’s example didn’t end the Paint() function and didn’t define ‘text’ and attempted to Close() a spawnicon that should’ve been Remove()'d, even though it would be automatically if it’s parent panel was closed?



if SERVER then

hook.Add("PlayerSay", "DermaCommands", function(ply, text)
	if(string.sub(text, 1, 6) == "/models")then	
		net.Start("derma_panel_modelsmenu")
		net.Send(ply)
	end
end)

elseif CLIENT then

function Panel()
local Frame = vgui.Create( "DFrame" )
Frame:SetTitle( "SELECT MODEL" )
Frame:SetSize( 600, 300 )
Frame:SetPos(200,100)
Frame:MakePopup()
Frame:SetDraggable( true )
Frame:ShowCloseButton( true )

Frame.Paint = function( self )
	draw.RoundedBox( 0, 0, 0, 600, 300, Color( 0, 0, 0, 200 ) ) 
end
	
local SpawnI = vgui.Create("SpawnIcon")
SpawnI:SetPos(200,100)	
SpawnI:SetParent(Frame)
SpawnI:SetModel("models/weapons/w_knife_ct.mdl")


SpawnI.DoClick = function()
	RunConsoleCommand("playermodel_set","models/weapons/w_knife_ct.mdl")
	Frame:Close()
        end
    end
end

net.Receive("derma_panel_modelsmenu", Panel)


As long as playermodel_set is an existing console command…
By the way, this was adapted from the previous post, but considering it got 3 ‘dumb’ ratings, there’s probably some other problem with this which I overlooked.

Thanks alot, its working well!