• Entity Use Creates A Lot Of Derma Panels?
    4 replies, posted
So I am coding an entity that when you hit [B]e[/B] on it, it opens a menu that you can deposit money and withdraw and stuff. I just started so there is no coding for money or buttons yet. But, I have everything working except for the fact that the longer I hold [B]e[/B] on the entity, the more derma panels it opens. For example, if I hold it for 3 seconds, its opens 117 derma panels... My question is, how do I make it so even if you hold [B]e[/B], it only opens 1 derma panel? Here is all of my coding so far. [B][U]cl_init.lua[/U][/B] [CODE]include("shared.lua") function ENT:Draw() self:DrawModel() end local function DrawMenu() local Frame = vgui.Create( "DFrame" ) Frame:SetSize( 100, 100 ) Frame:Center() Frame:SetTitle("Options") Frame:ShowCloseButton(true) Frame:SetSizable(false) Frame:SetDeleteOnClose(true) Frame:MakePopup() end usermessage.Hook( "DrawMenu", DrawMenu )[/CODE] [B][U]init.lua[/U][/B] [CODE]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") function ENT:Initialize() self:SetModel("models/props_wasteland/controlroom_desk001b.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end end function ENT:Use( ply, caller ) umsg.Start( "DrawMenu", ply ) umsg.Short( "1" ) umsg.End() end[/CODE] [B][U]shared.lua[/U][/B] [CODE]ENT.Type = "anim" ENT.Base = "base_gmodentity" ENT.PrintName = "Test Entity" ENT.Spawnable = true[/CODE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetUseType]Entity:SetUseType[/url] And when you create your panel, store it somewhere you can actually access it. And get into the habit of using the net library instead of usermessages. [url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url]
In your ENT:Initialize() function, do this: [code]self:SetUseType(SIMPLE_USE)[/code] EDIT: ok ninja me
Ok so like you both said I added self:SetUseType(SIMPLE_USE) to my serverside. That didn't do anything though. Also, what do you mean by store it somewhere and if I were to use the net library, what would I change? [editline]27th November 2016[/editline] EDIT: Nvm I just reloaded by console and game and it worked my bad but again what do you mean by store it somewhere and if I were to use the net library, what would I change?
[QUOTE=Revenance;51438265]-snip-[/QUOTE] [CODE]--server util.AddNetworkString("sendDerma") --must add this to send net messages function ENT:Use(ply, caller) net.Start("sendDerma") net.Send(caller) end [/CODE] [CODE]--client net.Receive("sendDerma", function(len) --derma code end) [/CODE] And I'm assuming that sannys means is that you would wanna create a variable like [CODE]menu = false;[/CODE] Then check to see if it has a value, then assign it to a derma menu and then just use the function menu:SetVisible(boolean) to make it open/close. You'd just have to set the menu variable to true/false.
Sorry, you need to Log In to post a reply to this thread.