wondering how i could close a button after its use, ive tried doing the following
[CODE]local HeyThatsPrettyGood = vgui.Create( "DButton", "DFrame" )
HeyThatsPrettyGood:SetText( "X" )
HeyThatsPrettyGood:SetSize( 150, 65 )
HeyThatsPrettyGood:SetTextColor( Color( 255, 255, 255 ) )
HeyThatsPrettyGood:SetPos( 10, 100 )
HeyThatsPrettyGood.Paint = function( self, w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color( 41, 128, 185, 250 ) )
end
HeyThatsPrettyGood.DoClick = function()
DButton:Close()
end [/CODE]
[code]HeyThatsPrettyGood.DoClick = function(self)
self:Remove()
end[/code]
That should fix your problem.
thank you that helped me alot, one last question hopefully, how do i make it remove the derma panel on click whilst itself?
-snip-
Nevermind i cant read.
[QUOTE=Felex;49452421]thank you that helped me alot, one last question hopefully, how do i make it remove the derma panel on click whilst itself?[/QUOTE]
Not tested, probably looks horrible.
[CODE]local DFrame = vgui.Create( "DFrame" )
DFrame:SetPos( 100, 100 )
DFrame:SetSize( 300, 150 )
DFrame:ShowCloseButton( true )
local CloseButton = vgui.Create( "DButton", DFrame )
CloseButton:SetPos( 350, 100 )
CloseButton:SetSize( 50, 20 )
CloseButton.DoClick = function()
DFrame:Remove()
end[/CODE]
You only have to remove the frame, it'll delete the children too
worked it out, i was getting errors because my code wasnt in the correct order. thanks for your help again!!!!!!
[editline]5th January 2016[/editline]
another question ( sorry )
i have done the following
[CODE]HeyThatsPrettyGood.DoClick = function(self)
local ply = LocalPlayer()
self:Remove()
ply:Kick( "Didn't Accept Rules." )
end [/CODE]
hoping that it would kick the player on the buttons click but all it is giving me is the error
[ERROR] lua/niggerfaggot.lua:62: attempt to call method 'Kick' (a nil value)
1. DoClick - lua/niggerfaggot.lua:62
2. unknown - lua/vgui/dlabel.lua:218
once again sorry for asking so many questions.
Lua / niggerfaggot.lua
Nice file name.
Use wiki.garrysmod.com it will help you
You're getting the error because 'Kick' is a serverside command, and your VGUI code has to be clientside to work. You need to [URL="https://wiki.garrysmod.com/page/Net_Library_Usage"]network[/URL] the Kick command to the server. E.G.
[CODE]
--SERVERSIDE
util.AddNetworkString( 'KickAPlayer' )
net.Receive( "KickAPlayer", function( len, ply )
ply:Kick( "Didn't Accept Rules" ) -- since the net library automatically sends the player who is trying to close the panel, you just need to use the 'ply' argument this function receives.
end )
--CLIENTSIDE
HeyThatsPrettyGood.DoClick = function(self)
net.Start('KickAPlayer')
net.SendToServer()
self:Remove()
end
[/CODE]
Sorry, you need to Log In to post a reply to this thread.