• Function for when a panel is closed?
    17 replies, posted
Is there a way to apply a function when the 'X' on a panel is clicked?
[lua]Menu.OnClose = function() --do stuff here end [/lua]
[code]frame = vgui.Create( "DFrame" ) frame:SetPos( 0, 0 ) frame:SetSize( 295, 295 ) frame:SetTitle( "" ) frame:SetVisible( true ) frame:SetDraggable( false ) frame:ShowCloseButton( true ) frame:MakePopup() frame.OnClose = function() --Stuff goes here end[/code] So, in theory, this is how it should look?
Should work yes. Or: [lua] function frame:OnClose() --stuff end [/lua]
Hrm... Neither of those seem to do anything. Like if I put a self.Weapon:EmitSound the sound will not be played. Is there some kind of different thing that needs to be done for sweps?
Where are you defining self.Weapon?
Swep? How're you using it?
[QUOTE=Freze;34762700]Swep? How're you using it?[/QUOTE] I'm using it as an attachments menu, when the use and primary keys are pressed, the panel is drawn.
Show us the entire code.
[QUOTE=Chessnut;34762772]Show us the entire code.[/QUOTE] [code] function SWEP:Think() if self.owner:KeyDown(IN_USE) and self.owner:KeyPressed(IN_ATTACK) then self:SetIronsights(true, self.Owner) self:Att() end end function SWEP:Att() self.IronSightsPos = self.AttSightsPos self.IronSightsAng = self.AttSightsAng self.Weapon:EmitSound( Sound("weapons/scar-l/SCARL_ClothMovement3.wav" ) ) if CLIENT then frame = vgui.Create( "DFrame" ) frame:SetPos( 0, 0 ) frame:SetSize( 295, 295 ) frame:SetTitle( "Weapon Mods" ) frame:SetVisible( true ) frame:SetDraggable( false ) frame:ShowCloseButton( true ) frame:MakePopup() frame.OnClose = function() self:SetIronsights(false, self.Owner) self.Weapon:EmitSound( Sound("weapons/scar-l/SCARL_ClothMovement3.wav" ) ) end PropertySheet = vgui.Create( "DPropertySheet", frame ) PropertySheet:SetPos( 1, 30 ) PropertySheet:SetSize( 295, 295 ) ItemSheetOne = vgui.Create("DCollapsibleCategory", DermaPanel) ItemSheetOne:SetPos( 25,50 ) ItemSheetOne:SetSize( 200, 50 ) ItemSheetOne:SetExpanded( 1 ) ItemSheetOne:SetLabel( "Top Rail" ) Category = vgui.Create( "DPanelList" ) Category:SetAutoSize( true ) Category:SetSpacing( 2 ) Category:EnableHorizontal( false ) Category:EnableVerticalScrollbar( true ) ItemSheetOne:SetContents( Category ) ContentOne = vgui.Create( "DButton" ) ContentOne:SetText( "Doctor" ) ContentOne.DoClick = function () self.Weapon:EmitSound( Sound("weapons/scar-l/SCARL_BoltRelease.wav" ) ) self.Owner:GetViewModel():SetBodygroup( 1, 0 ) end Category:AddItem( ContentOne ) ContentTwo = vgui.Create( "DButton" ) ContentTwo:SetText( "Scope" ) ContentTwo.DoClick = function () self.Weapon:EmitSound( Sound("weapons/scar-l/SCARL_BoltRelease.wav" ) ) self.Owner:GetViewModel():SetBodygroup( 1, 1 ) end Category:AddItem( ContentTwo ) PropertySheet:AddSheet("Available Attachments:", ItemSheetOne, "gui/silkicons/wrench", false, false, "Commands") end end [/code] I have the weapon going into a twisted irons position, as to imitate the way Crysis does weapon attachments. DoClick works just fine if anyone would like to know.
Instead of using the think hook to check, why not just do: [lua] function SWEP:PrimaryAttack() if ( self.Owner:KeyDown(IN_USE) ) then -- Your stuff here. end; end; [/lua]
[QUOTE=Chessnut;34772865]Instead of using the think hook to check, why not just do: [lua] function SWEP:PrimaryAttack() if ( self.Owner:KeyDown(IN_USE) ) then -- Your stuff here. end; end; [/lua][/QUOTE] I think that would just do the exact same thing as using think.
[QUOTE=Supah_Sonic;34779362]I think that would just do the exact same thing as using think.[/QUOTE] But it's better to not use Think hook if you don't need to.
[QUOTE=Kidd;34779647]But it's better to not use Think hook if you don't need to.[/QUOTE] I can sort out which one is more efficient once closing the panel actually does anything.
[lua]MsgN("THIS WORKS!")[/lua] Put this besides your sound code in the [i]frame:OnClose[/i] function and tell us whether you see the message in the console or not. :pwn:
[QUOTE=vercas;34789952][lua]MsgN("THIS WORKS!")[/lua] Put this besides your sound code in the [i]frame:OnClose[/i] function and tell us whether you see the message in the console or not. :pwn:[/QUOTE] Nothing.
[QUOTE=Supah_Sonic;34790630]Nothing.[/QUOTE] That's weird. Um, do what I did: Place an (almost) invisible [i]DButton[/i] over the frame's closing button. I admit, I've had trouble with this before. I just wanted to see if I'm the only one.
[QUOTE=vercas;34790729]That's weird. Um, do what I did: Place an (almost) invisible [i]DButton[/i] over the frame's closing button. I admit, I've had trouble with this before. I just wanted to see if I'm the only one.[/QUOTE] Alright, I'll see what I can do.
Sorry, you need to Log In to post a reply to this thread.