• Adding VGUI into a timer
    2 replies, posted
Hi, I must sound like a pain posting 2 questions in 1 day but one last thing I need to know is how to add vgui into a timer, I know about creating a timer and everything it's just putting vgui into it and also at the end of the timer making the VGUI close, here is the code I have so far: [CODE]if (SERVER) then util.AddNetworkString("OpenVGUIElement") hook.Add("PlayerDeath", "ID", function(ply, inf, att) -- Would make a menu pop up when the player dies net.Start("OpenVGUIElement") net.Send( ply ) end ) elseif (CLIENT) then net.Receive("OpenVGUIElement", function(len) OpenVGUIElement() end ) function OpenVGUIElement() -- Container panel BGPanel = vgui.Create( "DPanel" ) BGPanel:SetSize( 400, 400 ) BGPanel:Center() BGPanel:SetDrawBackground( false ) -- Wood background local img_bg = vgui.Create( "DImage", BGPanel ) img_bg:SetSize( BGPanel:GetSize() ) img_bg:SetImage( "models/props_foliage/oak_tree01" ) -- Blurred out screenshot of Construct local img_construct = vgui.Create( "DImage", BGPanel ) img_construct:SetPos( 10, 10 ) img_construct:SetSize( 380, 380 ) img_construct:SetImage( "hlmv/background" ) -- Flatgrass sign local img_text = vgui.Create( "DImage", BGPanel ) img_text:SetPos( 10, 20 ) img_text:SetSize( 380, 130 ) img_text:SetImage( "gm_construct/flatsign" ) end end[/CODE]
Remove your base panel. In this case it's BGPanel:Remove() That will automatically remove all children as well. Method wise are you sure you want to use a timer? You can run a check on the panel's think/paint function to remove after a certain amount of time like so: [code] pan.RefTime = CurTime() + LengthBeforeDeletion pan.Think = function( self, w, h ) if pan.RefTime < CurTime() then self:Remove() end end [/code]
[QUOTE=solid_jake;51772675]Remove your base panel. In this case it's BGPanel:Remove() That will automatically remove all children as well. Method wise are you sure you want to use a timer? You can run a check on the panel's think/paint function to remove after a certain amount of time like so: [code] pan.RefTime = CurTime() + LengthBeforeDeletion pan.Think = function( self, w, h ) if pan.RefTime < CurTime() then self:Remove() end end [/code][/QUOTE] That could work too lol, thanks jake :) I'll go do those changes and report back [editline]3rd February 2017[/editline] It worked thanks to solid_jake, here is the code for anyone else wanting to know how to do this: [CODE]if (SERVER) then util.AddNetworkString("OpenVGUIElement") hook.Add("PlayerDeath", "ID", function(ply, inf, att) -- Would make a menu pop up when the player dies net.Start("OpenVGUIElement") net.Send( ply ) end ) elseif (CLIENT) then net.Receive("OpenVGUIElement", function(len) OpenVGUIElement() end ) function OpenVGUIElement() -- Container panel BGPanel = vgui.Create( "DPanel" ) BGPanel:SetSize( 400, 400 ) BGPanel:Center() BGPanel:SetDrawBackground( false ) -- Wood background local img_bg = vgui.Create( "DImage", BGPanel ) img_bg:SetSize( BGPanel:GetSize() ) img_bg:SetImage( "models/props_foliage/oak_tree01" ) -- Blurred out screenshot of Construct local img_construct = vgui.Create( "DImage", BGPanel ) img_construct:SetPos( 10, 10 ) img_construct:SetSize( 380, 380 ) img_construct:SetImage( "hlmv/background" ) -- Flatgrass sign local img_text = vgui.Create( "DImage", BGPanel ) img_text:SetPos( 10, 20 ) img_text:SetSize( 380, 130 ) img_text:SetImage( "gm_construct/flatsign" ) pan = BGPanel pan.RefTime = CurTime() + 10 pan.Think = function( self, w, h ) if pan.RefTime < CurTime() then self:Remove() end end end end[/CODE] I really appreciate all the help the developer discussion section has given me tonight :)
Sorry, you need to Log In to post a reply to this thread.