My derma menu keeps stacking whenever you press F4, so you have to close it twice if you pressed it twice.
Any way to fix this? I can paste my code if that is needed.
[QUOTE=Skere_;49095685] I can paste my code if that is needed.[/QUOTE]
Yes, that would be very helpful.
[B]In cl_init.lua[/B]
[QUOTE]
local Menu
local function MyMenu()
local Menu = vgui.Create("DFrame")
Menu:SetPos(ScrW() / 2 - 325, ScrH() / 2 - 250)
Menu:SetSize(750, 500)
Menu:SetTitle("Battlefront Arms - Menu")
Menu:SetDraggable(false)
Menu:ShowCloseButton(true)
gui.EnableScreenClicker(true)
Menu.Paint = function()
surface.SetDrawColor(60,60,60,255)
surface.DrawRect(0,0, 750, 500)
surface.SetDrawColor(40,40,40,255)
surface.DrawRect(0,24,Menu:GetWide(),1)
end
end
usermessage.Hook("MyMenu", MyMenu)
addButtons(Menu)
function addButtons(Menu)
local playerButton = vgui.Create("DButton")
playerButton:SetParent(Menu)
playerButton:SetText("")
playerButton:SetSize(100,50)
playerButton:SetPos(0,25)
playerButton.Paint = function()
surface.SetDrawColor(50,50,50,255)
surface.DrawRect(0,0,playerButton:GetWide(),playerButton:GetTall())
surface.SetDrawColor(40,40,40,255)
surface.DrawRect(0,49, playerButton:GetWide(), 1)
surface.DrawRect(99,0,1,playerButton:GetTall())
end
end
[/QUOTE]
[B]In init.lua[/B]
[QUOTE]
function GM:ShowSpare2( ply )
umsg.Start( "MyMenu", ply )
umsg.End()
end
[/QUOTE]
The problem is that you keep opening the menu without destroying it.
Do not localize your menu, make it a global variable. Upon calling the usermessage (pls use net).
Then you can make a function to toggle your menu.
[code]
function ToggleMenu()
if IsValid(Menu) then
Menu:SetVisible(!Menu:GetVisible())
else
--Code where you create the menu
end
end
[/code]
This code toggles the menu, if the menu doesn't exist, it creates it.
You can do a sort of toggle/switch thing, like have a variable set to false which is changed to true when the menu is open - then basically say 'if variable is false, open the menu and make it true'
Obviously you'll need to reverse it for closing
Well your CL_INIT code is a bit fucked here:
[code]local Menu
local function MyMenu()
local Menu = vgui.Create("DFrame")[/code]
Double locals.
Secondly, don't be afraid to use "returns". You have a lot of ways to handle this but I think this is best for a non-changing panel:
[code]
if IsValid( Menu ) then Menu:SetVisible( !Menu:IsVisible() ) return end
[/code]
At the top of your code will automatically make the menu toggle. Though you have to fix what I said above to make the "Menu" exist outside the function
[editline]11th November 2015[/editline]
[QUOTE=Darrell;49096071]The problem is that you keep opening the menu without destroying it.
Do not localize your menu, make it a global variable. Upon calling the usermessage (pls use net).
Then you can make a function to toggle your menu.
[code]
function ToggleMenu()
if IsValid(Menu) then
Menu:SetVisible(!Menu:GetVisible())
else
--Code where you create the menu
end
end
[/code]
This code toggles the menu, if the menu doesn't exist, it creates it.[/QUOTE]
Pretty much what was written here except a little more code efficient.
He can maintain the Menu as a localized variable within his CL_INIT file so long as he calls the function from the net.Receive. What he did was localize it both in CL_INIT and the function which doesn't do shit to the CL_INIT.
Also GetVisible() doesn't exist, the function is PANEL:IsVisible()
Changed it (not completely yet) to the network thingy but for some reason it doesn't want to include it
[B]f4menu.lua[/B]
[lua]
net.Receive("FMenu",function()
local Menu = vgui.Create("DFrame")
Menu:SetSize(500,500)
Menu:SetPos(ScrW()/2 - 250, ScrH()/2 -250)
Menu:SetTitle("BFA - Menu")
Menu:SetDraggable(false)
Menu:ShowCloseButton(true)
Menu:MakePopup()
end)
[/lua]
[B]init.lua[/B]
[lua]
util.AddNetworkString("FMenu")
function GM:ShowSpare2(ply)
net.Start("FMenu")
net.Broadcast()
end
[/lua]
Error:
[QUOTE]
Couldn't include file 'f4menu.lua' (File not found) (@gamemodes/skeretdm/gamemode/shared.lua (line 6))
[/QUOTE]
And that line 6 is just this
[lua]
include ("f4menu.lua")
[/lua]
I even tried putting it seperately in init & cl_init but the cl_init doesn't want to include it.
This is why I made it locally.
[editline]11th November 2015[/editline]
Nvm fixed
Sorry, you need to Log In to post a reply to this thread.