Well I made this derma frame and command, it works perfectly. But when u die, and type !crate the frame NEVER pops up? why?
[CODE]hook.Add( "PlayerSay", "OpenCrateGui", function( ply, text, team )
if ( text == "!crate" ) and ply:Alive() then
ply:PrintMessage( HUD_PRINTTALK, "Sorry, you must be dead to use crates!" )
if( not ply:Alive() ) then
vgui.Create( "DFrame" ):SetPos( 100, 100 )
vgui.Create( "DFrame" ):SetSize( 500, 500 )
vgui.Create( "DFrame" ):SetTitle( "Startup" )
vgui.Create( "DFrame" ):SetVisible( true )
vgui.Create( "DFrame" ):SetDraggable( false )
vgui.Create( "DFrame" ):ShowCloseButton( true )
vgui.Create( "DFrame" ):MakePopup()
return ""
end
return ""
end
end )[/CODE]
Try this.
[CODE]hook.Add( "PlayerSay", "OpenCrateGui", function( ply, text, team )
if (string.sub(text, 1, 6) == "!crate") and ply:Alive() then
ply:PrintMessage( HUD_PRINTTALK, "Sorry, you must be dead to use crates!" )
if( not ply:Alive() ) then
vgui.Create( "DFrame" ):SetPos( 100, 100 )
vgui.Create( "DFrame" ):SetSize( 500, 500 )
vgui.Create( "DFrame" ):SetTitle( "Startup" )
vgui.Create( "DFrame" ):SetVisible( true )
vgui.Create( "DFrame" ):SetDraggable( false )
vgui.Create( "DFrame" ):ShowCloseButton( true )
vgui.Create( "DFrame" ):MakePopup()
return ""
end
return ""
end
end )[/CODE]
PlayerSay is serverside, vgui is clientside - send a net message
[QUOTE=NiandraLades;50669784]PlayerSay is serverside, vgui is clientside - send a net message[/QUOTE]
net.Send?
[editline]8th July 2016[/editline]
[QUOTE=Knoxed;50669014]Try this.
[CODE]hook.Add( "PlayerSay", "OpenCrateGui", function( ply, text, team )
if (string.sub(text, 1, 6) == "!crate") and ply:Alive() then
ply:PrintMessage( HUD_PRINTTALK, "Sorry, you must be dead to use crates!" )
if( not ply:Alive() ) then
vgui.Create( "DFrame" ):SetPos( 100, 100 )
vgui.Create( "DFrame" ):SetSize( 500, 500 )
vgui.Create( "DFrame" ):SetTitle( "Startup" )
vgui.Create( "DFrame" ):SetVisible( true )
vgui.Create( "DFrame" ):SetDraggable( false )
vgui.Create( "DFrame" ):ShowCloseButton( true )
vgui.Create( "DFrame" ):MakePopup()
return ""
end
return ""
end
end )[/CODE][/QUOTE]
No, the Top part works perfectly. The part below it, does not work entirely. If you'r dead, and type !crate it dosent work. If you'r alive and type !crate it does? Wtf is going on?
Pretty sure that's bullshit since PlayerSay is server-side. And why aren't you just creating the dframe and storing it in a var:
[CODE]
local frame = vgui.Create("DFrame")
frame:SetPos(0, 0)
etc...
[/CODE]
[QUOTE=jacobcooper18;50670875]net.Send?[/QUOTE]
"The net library is one of a number of ways to send data between the client and server." - Wiki
[url]http://wiki.garrysmod.com/page/Category:net[/url]
-snip-
Okay, so there are a good amount of things going wrong here.
First off, you're using vgui.Create() as if it were a variable, and basically creating 7 different DFrames, all with a single attribute that you're trying to apply to one frame.
The corrected code looks like this:
[CODE]local crateFrame = vgui.Create( "DFrame" )
crateFrame:SetPos( 100, 100 )
crateFrame:SetSize( 500, 500 )
crateFrame:SetTitle( "Startup" )
crateFrame:SetVisible( true )
crateFrame:SetDraggable( false )
crateFrame:ShowCloseButton( true )
crateFrame:MakePopup()[/CODE]
Not the most pertinent mistake here but it was bugging me.
Next, you're using GM:PlayerSay() -which is a strictly server side function- with vgui, which is client side. If you're wanting to work around this, I'd suggest learning net messages. In this case, you'd check the message on the server with PlayerSay(), then send a message to the client which activates your vgui creation script.
Serverside should look like this:
[CODE]util.AddNetworkString("CrateGuiMessage")
function GM:PlayerSay(ply, text, teamChat)
if(text == "!crate")then --first check if they typed '!crate'
if(not ply:Alive())then --Then check if the player is dead.
net.Start("Crates") --If so, send a message to the client to start the OpenCrateGui function
net.Send()
else
ply:PrintMessage(HUD_PRINTTALK, "Sorry, you must be dead to use crates!") --If not, tell em' they're stupid
end
return "" -- if the text was !crate, set the text that goes to the chat to ""
end
return text -- if not, let the chat print the original text.
end
[/CODE]
and client like this:
[CODE]
net.Receive("CrateGuiMessage", function(length) --receive the message, and run a function
local crateFrame = vgui.Create( "DFrame" )
crateFrame:SetPos( 100, 100 )
crateFrame:SetSize( 500, 500 )
crateFrame:SetTitle( "Startup" )
crateFrame:SetVisible( true )
crateFrame:SetDraggable( false )
crateFrame:ShowCloseButton( true )
crateFrame:MakePopup()
end)[/CODE]
Please don't do the method above, it overrides the gamemode function for PlayerSay and it uses unnecessary networking. All that you need to do to achieve what you want is this:
[CODE]
hook.Add( "OnPlayerChat", "OpenCrateGui", function( ply, text, team, dead ) -- Who would've guessed, there's a clientside hook for chat. Wow.
if text == "!crate" and ( ply == LocalPlayer() ) then
if dead then
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()
else
ply:PrintMessage( HUD_PRINTTALK, "Sorry, you must be dead to use crates!" )
end
return true -- surpress the message
end
end )
[/CODE]
Run that clientside. Simple.
[QUOTE=MPan1;50693608]Please don't do the method above, it overrides the gamemode function for PlayerSay and it uses unnecessary networking. All that you need to do to achieve what you want is this:
[CODE]
hook.Add( "OnPlayerChat", "OpenCrateGui", function( ply, text, team, dead ) -- Who would've guessed, there's a clientside hook for chat. Wow.
if text == "!crate" then
if dead then
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()
else
ply:PrintMessage( HUD_PRINTTALK, "Sorry, you must be dead to use crates!" )
end
return true -- surpress the message
end
end )
[/CODE]
Run that clientside. Simple.[/QUOTE]
That will open a frame on every client
[CODE]
hook.Add( "OnPlayerChat", "OpenCrateGui", function( ply, text, team, dead ) -- Who would've guessed, there's a clientside hook for chat. Wow.
if ( text == "!crate" ) and ( ply == LocalPlayer() ) then
if dead then
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()
else
ply:PrintMessage( HUD_PRINTTALK, "Sorry, you must be dead to use crates!" )
end
return true -- surpress the message
end
end )
[/CODE]
Thanks timz9, I always forget that. Updated.
Sorry, you need to Log In to post a reply to this thread.