• How do I open a vgui panel with a SENT?
    4 replies, posted
How can I make a vgui panel pupup when you press USE on a SENT?
There are a couple of ways of doing this, but I think that by far the easiest way is to send a usermessage to the player that pressed use, and in the usermessage hook, open the menu. First of all, you need to set the use type to SIMPLE_USE to prevent the menu from being spammed open. This should go in your entities init.lua [lua]function ENT:Initialize() -- Usual initialize code self:SetUseType(SIMPLE_USE) end[/lua] Then you need to send a usermessage to the player who presses use. This also goes in init.lua [lua]function ENT:Use(act, cal) if act and act:IsPlayer() then -- Check that the activator is a player umsg.Start("OpenMenu", act) -- Start a usermessage to send to the activator umsg.End() -- End the usermessage end end[/lua] Now, you need to hook to that usermessage on the client and open your menu. This goes in cl_init.lua [lua]usermessage.Hook("OpenMenu", function(um) -- function to be called when usermessage is received -- open menu end)[/lua] Hope that helps.
-Shnip- Ninja'd :c ^^, and i did it wrong :D
You may also want to send the entity that the player pressed USE on in the usermessage, you can do that like this: [lua]function ENT:Use(act, cal) if act and act:IsPlayer() then umsg.Start("OpenMenu", act) umsg.Entity(act) umsg.End() end end[/lua] [lua]usermessage.Hook("OpenMenu", function(um) local ent = um:ReadEntity() end)[/lua]
[QUOTE=MakeR;22341117]There are a couple of ways of doing this, but I think that by far the easiest way is to send a usermessage to the player that pressed use, and in the usermessage hook, open the menu. First of all, you need to set the use type to SIMPLE_USE to prevent the menu from being spammed open. This should go in your entities init.lua [lua]function ENT:Initialize() -- Usual initialize code self:SetUseType(SIMPLE_USE) end[/lua] Then you need to send a usermessage to the player who presses use. This also goes in init.lua [lua]function ENT:Use(act, cal) if act and act:IsPlayer() then -- Check that the activator is a player umsg.Start("OpenMenu", act) -- Start a usermessage to send to the activator umsg.End() -- End the usermessage end end[/lua] Now, you need to hook to that usermessage on the client and open your menu. This goes in cl_init.lua [lua]usermessage.Hook("OpenMenu", function(um) -- function to be called when usermessage is received -- open menu end)[/lua] Hope that helps.[/QUOTE] Thank you very much. My plan is to make a supply crate, that can supply the player with health, armor and SWEPS. If I upload to gmod.org i`ll mention you in the credits. [editline]09:52AM[/editline] Hey, something is wrong, I cant spawn the SENT anymore! Here is a part of the code, I am not so sure is working. [lua] usermessage.Hook("OpenMenu", function(um) -- function to be called when usermessage is received local DermaPanel = vgui.Create( "DFrame" ) -- Creates the frame itself DermaPanel:SetPos( 50,50 ) -- Position on the players screen DermaPanel:SetSize( 1000, 900 ) -- Size of the frame DermaPanel:SetTitle( "Testing Derma Stuff" ) -- Title of the frame DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) -- Draggable by mouse? DermaPanel:ShowCloseButton( true ) -- Show the close button? DermaPanel:MakePopup() -- Show the frame end) [/lua] No error in the console! [editline]09:56AM[/editline] I think I solved it, wait a min, [editline]10:04AM[/editline] Yes, I solved it. I forgott an "end"...
Sorry, you need to Log In to post a reply to this thread.