All I have tried over the week, is too make a Command in chat. It worked many of times, now that ive tried to add a client sided derma frame and it to open it with !crate seams to not work?
[B]Code:[/B]
lua/autorun/server/sv_init.lua
[CODE]AddCSLuaFile("cl_frame.lua");
ulti.AddNetworkString( 'cmtomenu' )
hook.Add( "OnPlayerSay", "OpenCrateGui", function( ply, text, team )
if (string.sub(text, 1, 6) == "!crate") then
net.Start( 'cmtomenu')
net.Send( ply )
return ""
end
end )[/CODE]
lua/autorun/client/cl_init.lua
[CODE]
function opencratemenu()
local Frame = vgui.Create( "DFrame" )
Frame:SetPos( 100, 100 )
Frame:SetSize( 500, 500 )
Frame:SetTitle( "Startup" )
Frame:SetVisible( true )
Frame:SetDraggable( false )
Frame:ShowCloseButton( true )
Frame:MakePopup()
end
end
net.Recieve( 'cmtomenu', opencratemenu )[/CODE]
Please help!
You spelt Receive wrong - [URL="https://wiki.garrysmod.com/page/net/Receive"]net.Receive[/URL]
You don't need to use the net library for a chat hook. If you use OnPlayerChat, it's already clientside. Just create the menu there.
[editline]9th July 2016[/editline]
:snip: Read Snappy's code below, it checks LocalPlayer() like I forgot to
By the way, the hook you had before was called OnPlayerSay, which doesn't exist. I'm guessing you meant PlayerSay, but even if you used that, it's far less work to use a clientside chat hook instead.
[QUOTE=MPan1;50678640]You don't need to use the net library for a chat hook. If you use OnPlayerChat, it's already clientside. Just create the menu there.
[editline]9th July 2016[/editline]
-snip-
The hook you had before was called OnPlayerSay, which doesn't exist. I'm guessing you meant PlayerSay, but even if you used that, it's far less work to use a clientside chat hook instead.[/QUOTE]
That hook is called anytime the player receives a message, so you'll need to add a check to make sure the LocalPlayer is the one who sent the message.
[CODE]
hook.Add( "OnPlayerChat", "OpenCrateGui", function( ply, text, team, isdead )
if (string.sub(text, 1, 6) == "!crate") && ply == LocalPlayer() then -- added an extra check
local Frame = vgui.Create( "DFrame" )
Frame:SetPos( 100, 100 )
Frame:SetSize( 500, 500 )
Frame:SetTitle( "Startup" )
Frame:SetVisible( true )
Frame:SetDraggable( false )
Frame:ShowCloseButton( true )
Frame:MakePopup()
return true -- surpress the message
end
end )
[/CODE]
I always forget that. Thanks Snappy
[CODE]hook.Add( "OnPlayerChat", "OpenCrateGui", function( ply, text, team )
if (string.sub(text, 1, 6) == "!crate") && ply == LocalPlayer() then
local Frame = vgui.Create( "DFrame" )
Frame:SetPos( 450, 100 )
Frame:SetSize( 500, 500 )
Frame:SetTitle( "" )
Frame:SetVisible( true )
Frame:SetDraggable( false )
Frame:ShowCloseButton( true )
Frame:MakePopup()
return true
end
end )[/CODE]
I tried adding colour but there was an Error, it works perfectly now. But I have no idea how to colour the box without interfering with the other Function?
[QUOTE=jacobcooper18;50683903][CODE]hook.Add( "OnPlayerChat", "OpenCrateGui", function( ply, text, team )
if (string.sub(text, 1, 6) == "!crate") && ply == LocalPlayer() then
local Frame = vgui.Create( "DFrame" )
Frame:SetPos( 450, 100 )
Frame:SetSize( 500, 500 )
Frame:SetTitle( "" )
Frame:SetVisible( true )
Frame:SetDraggable( false )
Frame:ShowCloseButton( true )
Frame:MakePopup()
return true
end
end )[/CODE]
I tried adding colour but there was an Error, it works perfectly now. But I have no idea how to colour the box without interfering with the other Function?[/QUOTE]
Can you not just put Frame:SetColor(255, 255, 255, 255)?
[QUOTE=Thane;50683992]Can you not just put Frame:SetColor(255, 255, 255, 255)?[/QUOTE]
No
[code]
function Frame:Paint( w, h )
-- paint shit
end
[/code]
[QUOTE=timz9;50683995]No
[code]
function Frame:Paint( w, h )
-- paint shit
end
[/code][/QUOTE]
Ah that's right, draw a rounded box with the same size and height as the Frame, and then color it.
[QUOTE=timz9;50683995]No
[code]
function Frame:Paint( w, h )
-- paint shit
end
[/code][/QUOTE]
Problem is, with my code, you cant have a FUNCTION inside of a function o.o
[QUOTE=jacobcooper18;50684020]Problem is, with my code, you cant have a FUNCTION inside of a function o.o[/QUOTE]
All you'd be doing is overriding the Paint method on the Frame. [URL="http://wiki.garrysmod.com/page/PANEL/Paint"]Check here[/URL] then try it out.
[QUOTE=jacobcooper18;50684020]Problem is, with my code, you cant have a FUNCTION inside of a function o.o[/QUOTE]
You can just put it above the [code]return true[/code]
[CODE]hook.Add( "OnPlayerChat", "OpenCrateGui", function( ply, text, team )
if (string.sub(text, 1, 6) == "!crate") && ply == LocalPlayer() then
local Frame = vgui.Create( "DFrame" )
Frame:SetPos( 450, 100 )
Frame:SetSize( 500, 500 )
Frame:SetTitle( "" )
Frame:SetVisible( true )
Frame:SetDraggable( false )
Frame:ShowCloseButton( true )
Frame:MakePopup()
function panel:Paint( w, h )
draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 0, 0 ) )
end
return true
end
end )[/CODE]
I added that, but it still errors. So, I can have functions inside of hook functions? o.o
It's pretty obvious what the problem is. You never set any value to panel.
[editline]11th July 2016[/editline]
It should be [code]function Frame:Paint(w,h)[/code]
Sorry, you need to Log In to post a reply to this thread.