use to open derma menu

I have an entity that once you press use(E) i want it to open a derma menu:

local DFrame1 = vgui.Create(‘DFrame’)
DermaPanel:SetSize(100, 79)
DermaPanel:Center()
DermaPanel:SetTitle(‘Options’)
DermaPanel:ShowCloseButton(true)
DermaPanel:SetSizable(false)
DermaPanel:SetDeleteOnClose(true)
DermaPanel:MakePopup()

I need help making the use function. etc… and in which of the cl_init,init,shared lua files it needs to be added.

Okay, you need to create the use function in init.lua then send a usermessage to the client telling them to open your derma menu.

init.lua:
[lua]

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
end
[/lua]

cl_init.lua:

[lua]
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)
DermaPanel:Center()
DermaPanel:SetTitle(‘Options’)
DermaPanel:ShowCloseButton(true)
DermaPanel:SetSizable(false)
DermaPanel:SetDeleteOnClose(true)
DermaPanel:MakePopup()

end
usermessage.Hook( “DrawTheMenu”, DrawTheMenu ) – hooks the usermessage so when the “DrawTheMenu” usermessage is received by the client, it runs the function DrawTheMenu, which will open your menu.[/lua]

is this possible? (sorry im not sure how to post in the code window)

init.lua

function ENT:Use( ply, caller ) – the use function for the entity
if self.Entity:GetNWBool(“Usable”) == true then
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
if self.Entity:GetNWBool(“Usable”) == false then
return end
end
end

cl_init.lua

function ENT:Draw()
if self.Entity:GetNWBool(“Usable”) == true then
self:DrawEntityOutline( 1.0 )
else
self:DrawEntityOutline( 0.0 )
end
self.Entity:DrawModel()
(derma will be added aswell in here)

Use [noparse][lua][/lua][/noparse] tags.

[lua]
function ENT:Use( ply, caller ) – the use function for the entity
if self.Entity:GetNWBool(“Usable”) == true then
umsg.Start( “DrawTheMenu”, ply ) – Empty works fine.
umsg.End() – finishes the creation of the usermessage and sends it to the client
end
end[/lua]

Don’t add the derma in ENT:Draw(), just add this in the cl_init.lua file of the ent, it’ll work fine
[lua]
local function Derma()
(derma code goes here)
end
usermessage.Hook(“DrawTheMenu”, Derma)
[/lua]

Ok Thanks

And what if I wanted to make a menu for a toybox entity, which means that there can only be one lua file?