• Derma menu help
    21 replies, posted
Well heya! I was wondering if there had any ways to make This ([url]http://wiki.garrysmod.com/?title=File:DComboBox.png):[/url] [CODE]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[/CODE] In a thing like this: [url]http://img151.imageshack.us/img151/7730/31430701.png[/url] I'm really lost atm, I can make simple derma menu, but when it come to things like that I'm really lost.
[URL=http://wiki.garrysmod.com/?title=DImageButton]DImageButton[/URL] 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] [url]http://wiki.garrysmod.com/?title=DImage[/url] For an example of it's usage see here or the code below which I took from the wiki. [url]http://wiki.garrysmod.com/?title=Guide_to_Derma[/url] [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: [url]http://img528.imageshack.us/img528/6415/sanstitrevo.jpg[/url]
[QUOTE=WolvesSoulZ;21293992]I'm also totally out of idea about how to make an image appear, but I'll try again.[/QUOTE] 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 ;) Anyways, I'll edit this later or make a new post, with the result and code :)
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] [QUOTE=WolvesSoulZ;21305424]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.[/QUOTE] 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 :P 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. [QUOTE=Busymonkey][b]tried 3 times[/b][/QUOTE] I'm lazy.
[QUOTE]GmodAirsoft\gamemode\cl_weaponmenu.lua:59: attempt to index global 'CboxRIFLE' (a nil value)[/QUOTE] 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 :O
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. :)
[QUOTE=WolvesSoulZ][b]Whole Code[/b][/QUOTE] I'd get rid of that code, before someone steals it :) 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.
Ok, try it without ply though it should still work as the first serverside argument given by the console command is the player's entity that called the function.
It work now. With the code you gave to me. Thanks ^^ Edit: Now on how to put it so when you click the weapon you want, before picking it you get the info in the upper panel, hopefully I'll get that to work too xD Edit2: Now I can finish that damn Weapon selection menu :D Got the info box to work properly.
Sorry, you need to Log In to post a reply to this thread.