Derma menu help

Well heya! I was wondering if there had any ways to make

This (http://wiki.garrysmod.com/?title=File:DComboBox.png):


local TestingComboBox = vgui.Create( "DComboBox", DermaFrame )
TestingComboBox:SetPos( 10, 35 )
TestingComboBox:SetSize( 100, 185 )
TestingComboBox:SetMultiple( false ) -- Don't use this unless you know extensive knowledge about tables
TestingComboBox:AddItem( "Add" ) -- Add our options
TestingComboBox:AddItem( "Some" )
TestingComboBox:AddItem( "Options" )
TestingComboBox:AddItem( "Here" )
 
local MainMenuSheet = vgui.Create( "DPanel", DermaFrame ) -- We create a panel so we can draw shit on; if we use the frame, it comes up transparent for some reason
MainMenuSheet:SetPos( 125, 50 )
MainMenuSheet:SetSize( DermaFrame:GetWide() - 25, DermaFrame:GetTall() - 25 )
MainMenuSheet.Paint = function()
    if TestingComboBox:GetSelectedItems() and TestingComboBox:GetSelectedItems()[1] then -- make sure something is selected if not we get uber spam of errors
        local OurStringThing = "Your selection is: "..TestingComboBox:GetSelectedItems()[1]:GetValue().."!" -- This was a pain in the ass to figure out; this gets the name of the option chosen
        surface.SetFont( "default" )
        surface.SetTextColor( 255, 255, 255, 255 )
        surface.SetTextPos( 50, 50 )
        surface.DrawText( OurStringThing ) -- Draws the text
    end
end

In a thing like this:
http://img151.imageshack.us/img151/7730/31430701.png

I’m really lost atm, I can make simple derma menu, but when it come to things like that I’m really lost.

DImageButton I suppose?

Not quite what I want, look at the image I posted.

Dimagebutton is something I already knows of, I will use it inside the grey box, but what I want to know is on how to make it so when you click on the “Some” for exemple, inside the gray box, An image appear and bellow the buttons “I want this!” give you what you want.

Ah, I see, but couldn’t you just, uhm… instead of “Your selection is: Some!”, then set a DImageButton with your material on it, that doesent do anything when clicked, and then add a button under it?

You would create a DImage and then use a think hook and check what is selected from the DComboBox and then depending on the result you would have a different image shown.

To find the selected item you would use

[lua]
DComboBox:GetSelectedItems()
[/lua]

For an example of it’s usage see here or the code below which I took from the wiki.

[lua]
local TestingComboBox = vgui.Create( “DComboBox”, DermaFrame )
TestingComboBox:SetPos( 10, 35 )
TestingComboBox:SetSize( 100, 185 )
TestingComboBox:SetMultiple( false ) – Don’t use this unless you know extensive knowledge about tables
TestingComboBox:AddItem( “Add” ) – Add our options
TestingComboBox:AddItem( “Some” )
TestingComboBox:AddItem( “Options” )
TestingComboBox:AddItem( “Here” )

local MainMenuSheet = vgui.Create( “DPanel”, DermaFrame ) – We create a panel so we can draw shit on; if we use the frame, it comes up transparent for some reason
MainMenuSheet:SetPos( 125, 50 )
MainMenuSheet:SetSize( DermaFrame:GetWide() - 25, DermaFrame:GetTall() - 25 )
MainMenuSheet.Paint = function()
if TestingComboBox:GetSelectedItems() and TestingComboBox:GetSelectedItems()[1] then – make sure something is selected if not we get uber spam of errors
local OurStringThing = “Your selection is: “…TestingComboBox:GetSelectedItems()[1]:GetValue()…”!” – This was a pain in the ass to figure out; this gets the name of the option chosen
surface.SetFont( “default” )
surface.SetTextColor( 255, 255, 255, 255 )
surface.SetTextPos( 50, 50 )
surface.DrawText( OurStringThing ) – Draws the text
end
end
[/lua]

Well, I tried random things, I got the menu layout and all.

But, when I click my buttons it doesn’t do anythings (I didn’t try the image but I will, I’ll edit this after)

As for some code
Buttons =
[Lua]//Code button

local DermaButton = vgui.Create( “DButton” )
DermaButton:SetParent( DermaPanel ) – Set parent to our “DermaPanel”
DermaButton:SetText( “Click to redeem this gun” )
DermaButton:SetPos( 100, 290 )
DermaButton:SetSize( 230, 30 )
DermaButton.DoClick = function ()
if DComboBox:GetSelectedItems() == “Ak47” then
RunConsoleCommand( “kill” )
end
end[/lua]
And a bit of the main rifle code
[Lua]//Code panel Rifle

local riflePanel = vgui.Create( “DPanel”, SheetItemRIFLE )
riflePanel:SetPos( 85, 35 )
riflePanel:SetSize( 240, 190 )
riflePanel.Paint = function() – Paint function
surface.SetDrawColor( 50, 50, 50, 255 ) – Set our rect color below us; we do this so you can see items added to this panel
surface.DrawRect( 0, 0, riflePanel:GetWide(), riflePanel:GetTall() ) – Draw the rect
end

local CboxRIFLE = vgui.Create( “DComboBox”, SheetItemRIFLE )
CboxRIFLE:SetPos( 10, 35 )
CboxRIFLE:SetSize( 70, 230 )
CboxRIFLE:SetMultiple( false ) – Don’t use this unless you know extensive knowledge about tables
CboxRIFLE:AddItem( “M4a1” ) – Add our options
CboxRIFLE:AddItem( “Ak47” )
CboxRIFLE:AddItem( “Famas” )
CboxRIFLE:AddItem( “Galil” )
CboxRIFLE:AddItem( “Sig552” )
CboxRIFLE:AddItem( “SteyrAUG” )

local MainMenuSheet2 = vgui.Create( “DPanel”, SheetItemRIFLE ) – We create a panel so we can draw shit on; if we use the frame, it comes up transparent for some reason
MainMenuSheet2:SetPos( 125, 50 )
MainMenuSheet2:SetSize( DermaPanel:GetWide() - 25, DermaPanel:GetTall() - 25 )
MainMenuSheet2.Paint = function()
if CboxRIFLE:GetSelectedItems() and CboxRIFLE:GetSelectedItems()[1] then – make sure something is selected if not we get uber spam of errors
local OurStringThing = “Your selection is: “…CboxRIFLE:GetSelectedItems()[1]:GetValue()…”!” – This was a pain in the ass to figure out; this gets the name of the option chosen
surface.SetFont( “default” )
surface.SetTextColor( 255, 255, 255, 255 )
surface.SetTextPos( 50, 50 )
surface.DrawText( OurStringThing ) – Draws the text
end
end[/lua]

Edit: Well I’m also totally out of idea about how to make an image appear, but I’ll try again.
Here’s my layout:
http://img528.imageshack.us/img528/6415/sanstitrevo.jpg

Im’a try making a derma panel with a picture, just to test it out, get some experience about Derma.

I’m not a very good Lua coder, but I try to give my contribution :wink: Anyways, I’ll edit this later or make a new post, with the result and code :slight_smile:

Alright
I know how to use image, just that, with the DComboBox, I’m not sure and don’t know how to call in a function and make the buttons only give you the weapon you clicked on, with an image showing the stats of the weapon in the dark box above it.

Well DComboBox is nil. You called it CboxRIFLE. So it would be this
[lua]
//Code button

local DermaButton = vgui.Create( “DButton” )
DermaButton:SetParent( DermaPanel ) – Set parent to our “DermaPanel”
DermaButton:SetText( “Click to redeem this gun” )
DermaButton:SetPos( 100, 290 )
DermaButton:SetSize( 230, 30 )
DermaButton.DoClick = function ()
if CboxRIFLE:GetSelectedItems() == “Ak47” then
RunConsoleCommand( “kill” )

end
end
[/lua]

Well you would attatch it into the .DoClick function, like so.
[lua]
DermaButton.DoClick = function ()
local gunimage =vgui.Create(“DImage”, DermaPanel)
gunimage:SetPos(125,50)
gunimage:SetSize(100,100)
gunimage:SetImage(CboxRIFLE:GetSelectedItems() … “.vtf”)
end
[/lua]

This would assume that the weapon’s name in the DComboBox is the same as the file name for the texture and that the texture is in the root of the folder. To convert images into VTF files for use with DImage I have heard that VTFEdit is a good program to use.

sigh, Sorry it took me so long to respond, but I went watching some YouTube videos, lol :stuck_out_tongue:

Also, I tried 3 times now, and the only thing I can pull off is the DermaMenu, the Panel and the selection, menu-ish thingi, but no picture nor button. Sorry mate.

But sintwins seems to be a rather advanced coder, so he’ll probably help you through it.

I’m lazy.

That’s what I get with >
[lua]
local DermaButton = vgui.Create( “DButton” )
DermaButton:SetParent( DermaPanel ) – Set parent to our “DermaPanel”
DermaButton:SetText( “Click to redeem this gun” )
DermaButton:SetPos( 100, 290 )
DermaButton:SetSize( 230, 30 )
DermaButton.DoClick = function ()
if CboxRIFLE:GetSelectedItems() == “Ak47” then
RunConsoleCommand( “kill” )

end
end[/lua]

Get rid of the “local” infron of “CboxRIFLE”.

Did it, no error, but the button doesn’t do anything now.

Ok, so you highlighted “ak47” and pressed the button? Can you post your complete code here please so I can se what you have up to now please :D?

Edit: Erased incase of stealers :open_mouth:

Replace your button code with this.

[lua]
local DermaButton = vgui.Create( “DButton” )
DermaButton:SetParent( DermaPanel ) – Set parent to our “DermaPanel”
DermaButton:SetText( “Click to redeem this gun” )
DermaButton:SetPos( 100, 290 )
DermaButton:SetSize( 230, 30 )
DermaButton.DoClick = function ()
if CboxRIFLE:GetSelectedItems() and CboxRIFLE:GetSelectedItems()[1] then
if CboxRIFLE:GetSelectedItems()[1] == “Ak47” then
RunConsoleCommand( “airsoft_weapons”, “tmp”, ply )
DermaPanel:Close()

end
end
end
[/lua]

Your problem was here.
[lua]
if CboxRIFLE:GetSelectedItems() == “Ak47”
[/lua]
That doesn’t equal “Ak47”, it is a table that contains the selected items. Which does contain “Ak47”, but a table containing “Ak47” isn’t the same as “Ak47”. Ok that isn’t a good way of describing it but hopefully you get what I mean. :slight_smile:

I’d get rid of that code, before someone steals it :slight_smile:

Glad sintwins could help you out with this problem :]

Damn doesn’t work… The button still doesn’t do anything.

Try this.

[lua]
local DermaButton = vgui.Create( “DButton” )
DermaButton:SetParent( DermaPanel ) – Set parent to our “DermaPanel”
DermaButton:SetText( “Click to redeem this gun” )
DermaButton:SetPos( 100, 290 )
DermaButton:SetSize( 230, 30 )
DermaButton.DoClick = function ()
if CboxRIFLE:GetSelectedItems() and CboxRIFLE:GetSelectedItems()[1] then
if CboxRIFLE:GetSelectedItems()[1]:GetValue() == “Ak47” then
RunConsoleCommand( “airsoft_weapons”, “tmp”)
DermaPanel:Close()

end
end
end
[/lua]

Edit: Wait, what is that console command supposed to do? You can’t send an entity via a console command, you can only send string arguments. When running a console command the server knows who has ran it anyway so you don’t need the ply.

The console command it send is a script loaded from weapon.lua, it give the gun and prevent it to be given during the lifetime of a guy, it work. was used in my previous menu.