• How to USE an entity?
    11 replies, posted
Hey, I made a scripted entity, it just stands there and looks pretty. But, how can I make it so when I press e on it, it will open up a derma panel? Since derma panels are Clientside and the entity stuff is serverside.. How can this be done? Also, how can you make it so the npc can't be killed?
[url=http://wiki.garrysmod.com/?title=User_Messages][b]User Messages [img]http://wiki.garrysmod.com/favicon.ico[/img][/b][/url] [editline]09:47PM[/editline] [b][url=wiki.garrysmod.com/?title=ENT.Use]ENT.Use [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Yes, I know that, but how can I make the derma panel actually open up?
In your cl_init.lua, which I beleive is where your derma is placed, do a [b]concommand.Add()[/b] and then under [b]ENT.Use()[/b] do [b]RunConsoleCommand()[/b]
[QUOTE=Sylph;19786557]In your cl_init.lua, which I beleive is where your derma is placed, do a [B]concommand.Add()[/B] and then under [B]ENT.Use()[/B] do [B]RunConsoleCommand()[/B][/QUOTE] ENT.Use is serverside only. And while executing the concommand on the using player would work, players would be able to open the panel erroneously by executing the command manually. Sending a usermessage instead would be better suited to this.
Edit: MegaJohnny, can you show me how that would work?
[lua]function ENT:Use( activator, caller ) self.Entity:Remove() if ( activator:IsPlayer() ) then RunConsoleCommand("Derma1") end end [/lua] Forgot the quotes around Derma1 :v:
[lua]-- Server function ENT:Use(activator, caller) umsg.Start("OpenMenu", activator) umsg.End() end -- Client usermessage.Hook("OpenMenu", function(um) --open menu end)[/lua]
Okay, so when I use it, nothing happens.. init : [lua] function my_message_hook( um ) DermaPanel = vgui.Create( "DFrame" ) -- Creates the frame itself DermaPanel:SetPos( 50,50 ) -- Position on the players screen DermaPanel:SetSize( 500, 400 ) -- Size of the frame DermaPanel:SetTitle( "Testing Derma Stuff" ) -- Title of the frame DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( false ) -- Draggable by mouse? DermaPanel:ShowCloseButton( true ) -- Show the close button? DermaPanel:MakePopup( true ) //DermaPanel.MakePopup( true ) Msg( "The message has been received!" ) end usermessage.Hook("my_message", my_message_hook) [/lua] Init: [lua] function ENT:Use( activator, caller ) umsg.Start("my_message", activator) umsg.End() end [/lua] The problem is something to do with ent:use because I tested it with Ent:Starttouch and it worked. But I want it to be used. Do you want the full script for it, so maybe somewhere else is wrong?
Try putting this in the serverside Initialize function: self:SetUseType(SIMPLE_USE)
[QUOTE=iRzilla;19799514Then it's because you've attempted to make the hook serverside. If there is no error at all. It's because you've tried to use ENT:Use() on the client.[/QUOTE] He tried StartTouch too, which worked and is only available serverside.
Sorry, you need to Log In to post a reply to this thread.