Ent use to open derma

How would I make it so when I click on my entity it pops up with a derma.

I understand how derma works and entitys but I can’t connect the two.
Been trying for a few days.

(Newbie Coder)

I tried this from old post:


function ENT:Use( ply, caller ) -- the use function for the entity
    umsg.Start( "DrawTheMenu", ply ) -- starts the creation of the usermessage, names the usermessage "DrawTheMenu" and sets the player to send it to as the player who used the entity.
        umsg.Short( "1" ) -- adds a pointless interger to the usermessage, simply because the last time I tried it wouldn't work with an empty one. ignore this.
    umsg.End() -- finishes the creation of the usermessage and sends it to the client

First you need to identify the code that runs when you “click” on an entity. Do you mean “press use (e)”?

wiki.garrysmod.com has information about what code will run when you do that.

From there, you need to send a message from the server to the client in order to open the window. You then need code on the client configured to run some code when it receives a message of that type so that it can then open the window using derma.

Alternatively, you can show the menu on the client without the server sending a message first, but sometimes you want the server to have some code that decides whether the derma should even be opening for that player in the first place. Those kinds of decisions might need to be done on the server if there is any way a player could “cheat” by opening the menu on something they’re not supposed to.

Also, when the things in the menu send messages to the server, the server needs to check that it is valid that the player should be doing that before carrying out the change requested. If no changes are valid at that moment in time, for that entity and for that player, maybe you didn’t even want to open it in the first place (hence the last part).

Yes so by pressing E.

And I didn’t understand much of that to be honest.

[editline]3rd March 2017[/editline]

I found this from the same post.

local function DrawTheMenu() -- the function to call when the usermessage is received
    -- your derma stuff goes in this function..
    local DFrame1 = vgui.Create('DFrame')
    DermaPanel:SetSize(100, 79)

usermessage.Hook( "DrawTheMenu", DrawTheMenu )

“Warning: Unhandled usermessage ‘DrawTheMenu’”

Try to use the net. library.

Read it :
Click me!

Use net.
Take a look at this:


This did not work…

In the ENT init.lua:

util.AddNetworkString( "whatever" )
function ENT:AcceptInput( name, activator, caller )
	if name == "Use" && caller:IsPlayer() then

I’m not sure if it’s ok to add the networkstring in the entity file maybe someone can correct me on that.

In the gamemode cl_init.lua or any clientside file:

net.Receive( "whatever", function()
	"Open the menu"


net.Receive( "whatever", functiontoopenthemenu)

Why not ENT:Use(…) ?

It’s been a while since I wrote this but I remember that I had troubles with ENT:Use

Probs because you didnt use


Yeah if I remember correctly, my problem was that ENT:Use fired like 10 times when you pressed E. If only I had known about that.