• Opening Derma With a Chat Command
    9 replies, posted
mr current code: [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[/CODE]
[URL="wiki.garrysmod.com/page/GM/PlayerSay"]wiki.garrysmod.com/page/GM/PlayerSay[/URL]
Use playersay and umsgs to open the menu.
[QUOTE=RedNinja;47663761]umsgs[/QUOTE] Please, [url]http://wiki.garrysmod.com/page/Category:net[/url]
Serverside: [code] util.AddNetworkString("Whatever") hook.Add("PlayerSay", "asd", function(ply, text, teamonly) if text == whatever then net.Start("Whatever") net.Send(ply) end end) [/code] Clientside: [code] net.Receive("Whatever", function() --your menu code here end) [/code]
Thanks, It worked! but i need to know how to load lua file to server and client in same time
[QUOTE=NiandraLades;47664855]Serverside: [code]snip[/code][/QUOTE] Or use OnPlayerChat to avoid using a net message.
[code] 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 [/code] 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? [CODE] 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) [/CODE] 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!
Sorry, you need to Log In to post a reply to this thread.