• Derma opening 10 times instead of just once
    4 replies, posted
I'm using this code to open a derma panel on the player's screen when they press E on an npc: [code] hook.Add( "PlayerUse", "dermat", function( ply, ent ) if ( ent:GetClass() == "prof" ) then RunConsoleCommand("dermapop") end end ) concommand.Add("dermapop", function() local tFrame = vgui.Create( "DFrame" ) tFrame:SetPos( ScrW()/2 + 50,ScrH()/2 + 50 ) tFrame:SetSize( 300, 150 ) tFrame:SetTitle( "Name window" ) tFrame:SetVisible( true ) tFrame:SetDraggable( false ) tFrame:ShowCloseButton( true ) tFrame:MakePopup() end) [/code] I intended for it to open only 1 window, but it opens multiple in the same spot making the player have to spam the close button to get rid of all of them. How do I make it only create 1 window?
Thanks! I put this into the command: [code] concommand.Add("dermapop", function() if IsValid(tFrame) then print("the window exists") end if not IsValid(tFrame) then tFrame = vgui.Create( "DFrame" ) tFrame:SetPos( ScrW()/2 + 50,ScrH()/2 + 50 ) tFrame:SetSize( 700, 350 ) tFrame:SetTitle( "Professor" ) tFrame:SetVisible( true ) tFrame:SetDraggable( false ) tFrame:ShowCloseButton( true ) tFrame:MakePopup() end end) [/code]
You can also add [URL="https://wiki.garrysmod.com/page/Entity/SetUseType"]self:SetUseType(SIMPLE_USE)[/URL] in the ENT:Initialize function of your entity. [CODE] function ENT:Initialize() self:SetUseType(SIMPLE_USE) end [/CODE]
[QUOTE=Jompe...;51816674]You can also add [URL="https://wiki.garrysmod.com/page/Entity/SetUseType"]self:SetUseType(SIMPLE_USE)[/URL] in the ENT:Initialize function of your entity. [CODE] function ENT:Initialize() self:SetUseType(SIMPLE_USE) end [/CODE][/QUOTE] Thats for SENTS, what the user is doing is on a hook, but it would be simpler if only that prop needs it.
Sorry, you need to Log In to post a reply to this thread.