Pivity

Gmod Derma Menu I need help.

Last read Never
#1

Hello, I have been trying to create this menu, and I added this folder inside of my garrysmod/addons folder:

MyNewDerma/lua/autorun/sh.lua

and inside of the sh.lua is:

if (SERVER) then

end


if (CLIENT) then

local midW, midH = ScrW() / 2, ScrH() / 2

local function OpenMyDerma()

local MyDerma = vgui.Create( "DFrame" )

MyDerma:SetSize( 250, 250 )

MyDerma:SetPos( midW - ( MyDerma:GetWide() / 2 ), midH - ( MyDerma:GetTall() / 2 ) ) --midW midH are the two variables. ScrW is screenwidth divided by 2 and ScrH screenhieght is divided by 2

MyDerma:SetTitle( "My Menu" )


local MyLabel = vgui.Create( "DLabel", MyDerma )

MyLabel:SetPos( 175, 30 )

MyLabel:SetText( "Insert label here" )


local MyButton = vgui.Create( "DButton", MyDerma )

MyButton:SetText( "Click To Die" )

MyButton:SetPos( 175, 60 )

MyButton.DoClick = function()

RunConsoleCommand( "explode" )

end

end

concommand.Add( "openderma", OpenMyDerma )

end

And I type openderma inside of my servers in-game console, and the menu does not pop up. Any ideas/flaws i had in my code?

#2

Change "MyNewDerma" to something that is lowercase and contains no spaces, e.g. "mynewderma"

Also I assume its in your server's addons folder?

#3

Yep, it's in my addons folder, and I'll change the code whenever I get home from school.

#4

I might be wrong, as I haven't touched Lua in years now, but IIRC you need to manually open the menu.

I think the function was sth like

DermaPanel:SetVisible(true)
and then
DermaPanel:MakePopup()


Hope this is somehow useful for you. Forgive me for any mistakes, just trying to help.

Agree x 2Friendly x 1
#5

I thought that the derma menu automatically had set visible to true...

#6

Put prints everywhere or just throw some garbage into your code that'll cause it to break. If it doesn't print or error your code isn't running.

#7

heya, I put this inside of my MyNewDerma folder:


if (SERVER) then

end


if (CLIENT) then
local midW, midH = ScrW() / 2, ScrH() / 2
local function OpenMyDerma()
local MyDerma = vgui.Create( "DFrame" )
MyDerma:SetSize( 250, 250 )
MyDerma:SetPos( midW - ( MyDerma:GetWide() / 2 ), midH - ( MyDerma:GetTall() / 2 ) ) --midW midH are the two variables. ScrW is screenwidth divided by 2 and ScrH screenhieght is divided by 2
MyDerma:SetTitle( "My Menu" )
MyDerma:SetVisible(true)
MyDerma:MakePopup()

local MyLabel = vgui.Create( "DLabel", MyDerma )
MyLabel:SetPos( 175, 30 )
MyLabel:SetText( "Insert label here" )

local MyButton = vgui.Create( "DButton", MyDerma )
MyButton:SetText( "Click To Die" )
MyButton:SetPos( 175, 60 )
MyButton.DoClick = function()
RunConsoleCommand( "explode" )
end
end
concommand.Add( "openderma", OpenMyDerma )
end

and whenever I put openderma inside of my in-game console, it says unknown command. plz help

#8

You should do as Dan says and make prints to figure out if your code is even loading...

This thread seems more you want someone to fix your code instead of actually learning yourself :/

Agree x 1Confused x 1
#9

As everyone has been saying you need to debug or in simple terms work out where the issue is within the code.

As Dan said you should use functions known as prints in your code, this function will output text to console. What you need to do is at the top of your lua file you should add a print('Debug | Is file loading') and if you load up gmod, go in game and check your console if you see 'Debug | Is file loading' then it is a issue with creating the menu, if not it is a issue with the file loading.

If you fail to understand this you need to learn some more basic lua before trying menus.

Agree x 1
Users viewing this thread
Nobody