• Getting ENT inside Derma Menu
    6 replies, posted
So I have this Derma Menu that when I press a button, I want it to send the entity a variable, how would I go about targeting the entity inside of this? This is in my info.lua which is clientside local bread_button = vgui.Create( "DButton", recipeMenu ) bread_button:SetText("Bread") bread_button:SetPos( 25, 50 ) bread_button:SetSize(250, 30) bread_button.DoClick = function() entity:SetRecipe("Bread") end What would I need to define entity to in order for me to able to get the entity this is running
Well technically it's not running in an entity. What you could do (which might be bad practice, I don't know) is send the entity from the server to the client, then store the entity in a local variable in the net receive, then use it like that.
What would be the good practice way of doing it?
I don't know if it's necessarily bad practice, I just know a lot of things I do end up being the wrong way to go upon things.
First you need to appropriately define the "entity this is running on". What entity are you trying to work with? Did you open this menu by interacting with an entity, and you want to do something with that entity? Did you want to do something to a player? Did you want to do something to an entity that a player is looking at? Did you want the Lua gremlins to magically figure out what entity you wanted? Give us something to work with, as the code you posted doesn't really indicate any involvement with any entity at any point.
I am working with a scripted entity I spawned in the Q Menu. I opened the menu by interacting with said entity, I then want to do something with the entity from that menu. I need to be able to target the entity that I opened the menu from. The menu is being opened with ENT:Use(activator, ply), and is sent to the clientside where I have the net.Receive() opening up the derma. From the derma menu I have a button where I want to send a variable to that ENT that I pressed E on
Then yeah, do what SweptThrone said and send the entity in the net message. Storing it in a local would work, and probably be smidgen faster, but for organizational purposes, I would store it on the panel. This would also allow other scripts that know about your panel to access the entity easily. Whether or not this would ever be useful isn't clear, but someone at a later date may appreciate having it there.
Sorry, you need to Log In to post a reply to this thread.