• Derma question
    6 replies, posted
How would I make a DFrame popup when I press down a key and close when I release the key? Ive tried looking at the scoreboards lua for an example but can't get anything to work. Help mah!
Have a function that makes the derma frame and a function that closes it. Then do concommand.Add("+command", nameOfFunctionToOpenMenu) concommand.Add("-command", nameOfFunctionToCloseMenu) Then someone can bind a key to +command and it will run nameOfFunctionToOpenMenu when the press it, and nameOfFunctionToCloseMenu when they release it.
[lua]function InventoryShow() local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos(240, (ScrH() - 86) - 1, 200 + 2 ) DermaPanel:SetSize( 1200, 70 ) DermaPanel:SetTitle( "Testing Derma Stuff" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:MakePopup() local InventoryPanel = vgui.Create( "DPanel", DermaPanel ) InventoryPanel:SetPos( 0, 0 ) InventoryPanel:SetSize(1002, 66 ) InventoryPanel:SetVisible( true ) InventoryPanel.Paint = function() surface.SetDrawColor( 255, 255, 255, 75 ) surface.DrawRect( 0, 0, InventoryPanel:GetWide(), InventoryPanel:GetTall() ) end local InventoryPanel2 = vgui.Create( "DPanelList", InventoryPanel ) InventoryPanel2:SetPos( 1, 1 ) InventoryPanel2:SetSize( 1000, 64 ) InventoryPanel2:SetVisible( true ) InventoryPanel2:EnableHorizontal( true ) InventoryPanel2:EnableVerticalScrollbar( false ) InventoryPanel2.Paint = function() surface.SetDrawColor( 0, 0, 0, 75 ) surface.DrawRect( 0, 0, InventoryPanel2:GetWide(), InventoryPanel2:GetTall() ) end end concommand.Add( '+pgrp_inventory', InventoryShow ) function InventoryHide() DermaPanel:Close() end concommand.Add( '-pgrp_inventory', InventoryHide ) [/lua] DermaPanel returns nil when I run -pgrp_inventory
DermaPanel is local to the function InventoryShow(). At the top, do local DermaPanel function InventoryShow() DermaPanel = vgui.Create( "DFrame" ) instead of function InventoryShow() local DermaPanel = vgui.Create( "DFrame" )
[lua]local DermaPanel function InventoryShow() local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos(240, (ScrH() - 86) - 1, 200 + 2 ) DermaPanel:SetSize( 1200, 70 ) DermaPanel:SetTitle( "Testing Derma Stuff" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:MakePopup() local InventoryPanel = vgui.Create( "DPanel", DermaPanel ) InventoryPanel:SetPos( 0, 0 ) InventoryPanel:SetSize(1002, 66 ) InventoryPanel:SetVisible( true ) InventoryPanel.Paint = function() surface.SetDrawColor( 255, 255, 255, 75 ) surface.DrawRect( 0, 0, InventoryPanel:GetWide(), InventoryPanel:GetTall() ) end local InventoryPanel2 = vgui.Create( "DPanelList", InventoryPanel ) InventoryPanel2:SetPos( 1, 1 ) InventoryPanel2:SetSize( 1000, 64 ) InventoryPanel2:SetVisible( true ) InventoryPanel2:EnableHorizontal( true ) InventoryPanel2:EnableVerticalScrollbar( false ) InventoryPanel2.Paint = function() surface.SetDrawColor( 0, 0, 0, 75 ) surface.DrawRect( 0, 0, InventoryPanel2:GetWide(), InventoryPanel2:GetTall() ) end for k, v in pairs(LocalPlayer():GetTable().RoleplayData.Items) do if !GAMEMODE.ItemDatabase[k] then LocalPlayer():GetTable().RoleplayData.Items[k] = nil; end local ItemPanel = vgui.Create('pgrp_item', InventoryPanel2); ItemPanel:SetItem(k, TYPE_LOCAL); InventoryPanel2:AddItem(ItemPanel); end GAMEMODE.InventoryPanel_ItemList = InventoryPanel2; GAMEMODE.InventoryPanel = InventoryPanel2; end concommand.Add( '+pgrp_inventory', InventoryShow ) function InventoryHide() DermaPanel:Close() end concommand.Add( '-pgrp_inventory', InventoryHide )[/lua] This didn't work. New to lua, Please explain more. Appreciate your help. Sorry. Cant read :\. Working now, thanks man.
[lua] function InventoryShow() DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos(240, (ScrH() - 86) - 1, 200 + 2 ) DermaPanel:SetSize( 1200, 70 ) DermaPanel:SetTitle( "Testing Derma Stuff" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:MakePopup() InventoryPanel = vgui.Create( "DPanel", DermaPanel ) InventoryPanel:SetPos( 0, 0 ) InventoryPanel:SetSize(1002, 66 ) InventoryPanel:SetVisible( true ) InventoryPanel.Paint = function() surface.SetDrawColor( 255, 255, 255, 75 ) surface.DrawRect( 0, 0, InventoryPanel:GetWide(), InventoryPanel:GetTall() ) end InventoryPanel2 = vgui.Create( "DPanelList", InventoryPanel ) InventoryPanel2:SetPos( 1, 1 ) InventoryPanel2:SetSize( 1000, 64 ) InventoryPanel2:SetVisible( true ) InventoryPanel2:EnableHorizontal( true ) InventoryPanel2:EnableVerticalScrollbar( false ) InventoryPanel2.Paint = function() surface.SetDrawColor( 0, 0, 0, 75 ) surface.DrawRect( 0, 0, InventoryPanel2:GetWide(), InventoryPanel2:GetTall() ) end for k, v in pairs(LocalPlayer():GetTable().RoleplayData.Items) do if !GAMEMODE.ItemDatabase[k] then LocalPlayer():GetTable().RoleplayData.Items[k] = nil; end local ItemPanel = vgui.Create('pgrp_item', InventoryPanel2); ItemPanel:SetItem(k, TYPE_LOCAL); InventoryPanel2:AddItem(ItemPanel); end GAMEMODE.InventoryPanel_ItemList = InventoryPanel2; GAMEMODE.InventoryPanel = InventoryPanel2; end concommand.Add( '+pgrp_inventory', InventoryShow ) function InventoryHide() DermaPanel:Close() DermaPanel = nil end concommand.Add( '-pgrp_inventory', InventoryHide )[/lua] The panel's are now defined globally, so all functions can use it instead of just the function it's in.
[QUOTE=Horsey;17931564] The panel's are now defined globally, so all functions can use it instead of just the function it's in.[/QUOTE] Which is stupid because it can interfere with other scripts. And he already said it was fixed.
Sorry, you need to Log In to post a reply to this thread.