• How do you create ConVars and Tool tab options in Gmod?
    2 replies, posted
Hi, I'm a complete noob and have no idea what I'm doing... Please help :s: Anyway, so I want to create some settings for a little project I'm making for myself. Long story in short, I have no idea how to. I've scoured the Gmod wiki for help, no luck. What I want to do, is put some settings in the options tab (sliders, checkboxes etc.). Now I have some configs that maybe I could use to create some ConVars that I can use for the settings tab. (Excuse me if anything I say is rubbish, I honestly have no idea what I'm talking about). Here's the config stuff [CODE]TerminalR.Config = {} TerminalR.Config.CleanUpSave = true TerminalR.Config.PermaSave = true TerminalR.Config.HackTime = 25 TerminalR.Config.HackProtectionTime = 60 TerminalR.Config.HackErrorLimit = 5 TerminalR.Config.HackScoreNeed = 35[/CODE] This is as far as I could get (It doesn't work) [CODE]TerminalR.Config.CleanUpSave = CreateClientConvar("terminalr_cleanupsave", "1", true, false) TerminalR.Config.PermaSave = CreateClientConvar("terminalr_permasave", "1", true, false) TerminalR.Config.HackTime = CreateClientConvar("terminalr_hacktime", "25", true, false) TerminalR.Config.HackProtectionTime = CreateClientConvar("terminalr_hackprotectiontime", "60", true, false) TerminalR.Config.HackErrorLimit = CreateClientConvar("terminalr_hackerrorlimit", "5", true, false) TerminalR.Config.HackScoreNeed = CreateClientConvar("terminalr_hackscoreneed", "35", true, false)[/CODE] That's it! If someone could point me in the right direction, that'd be appreciated. Duck
The convars would work if you had a capital V on [B][U]V[/U][/B]ar (CreateClientCon[B][U]V[/U][/B]ar). [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/CreateClientConVar]CreateClientConVar[/url] If you want to add some options to the menu, I usually do this in a clientside autorun file: [CODE] hook.Add( "PopulateToolMenu", "ADDON NAME Settings", function() spawnmenu.AddToolMenuOption( "Options", "SOME CATEGORY", "INTERNAL CLASS NAME", "DISPLAYED CLASS NAME", "", "", function( panel ) panel:ClearControls() -- Add stuff here end ) end ) [/CODE] To add more stuff to the menu, it uses the same structure as the DForm, so all these work: [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DForm/AddItem]DForm:AddItem[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DForm/Button]DForm:Button[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DForm/CheckBox]DForm:CheckBox[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DForm/ComboBox]DForm:ComboBox[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DForm/ControlHelp]DForm:ControlHelp[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DForm/Help]DForm:Help[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DForm/ListBox]DForm:ListBox[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DForm/NumberWang]DForm:NumberWang[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DForm/NumSlider]DForm:NumSlider[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DForm/PanelSelect]DForm:PanelSelect[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DForm/TextEntry]DForm:TextEntry[/url] Just for fun, here's an example: [CODE] CreateClientConVar( "cool_convar", "0", true, false ) CreateClientConVar( "sick_convar", "123", true, false ) CreateClientConVar( "epic_convar", "sample text", true, false ) hook.Add( "PopulateToolMenu", "AddonSettings", function() spawnmenu.AddToolMenuOption( "Options", "Quality Addons", "Sick_Addon_Options", "SICK ADDON OPTIONS", "", "", function( panel ) panel:ClearControls() panel:CheckBox( "Look at this sexy check box", "cool_convar" ) panel:NumSlider( "Check out this hot slider", "sick_convar", 0, 1000 ) panel:TextEntry( "You get the idea", "epic_convar" ) end ) end ) [/CODE] In the menu: [t]https://i.imgur.com/dvR4jWl.png[/t] Pressing C: [t]https://i.imgur.com/7Pc0LOJ.png[/t]
Thanks for the reply mate! EDIT: Just tried it out, isn't working. So I chucked this at the end of the autorun lua file: [CODE]TerminalR.Config.CleanUpSave = CreateClientConVar("terminalr_cleanupsave", "1", true, false) TerminalR.Config.PermaSave = CreateClientConVar("terminalr_permasave", "1", true, false) TerminalR.Config.HackTime = CreateClientConVar("terminalr_hacktime", "25", true, false) TerminalR.Config.HackProtectionTime = CreateClientConVar("terminalr_hackprotectiontime", "60", true, false) TerminalR.Config.HackErrorLimit = CreateClientConVar("terminalr_hackerrorlimit", "5", true, false) TerminalR.Config.HackScoreNeed = CreateClientConVar("terminalr_hackscoreneed", "35", true, false) hook.Add( "PopulateToolMenu", "TerminalRSettings", function() spawnmenu.AddToolMenuOption( "Options", "Terminal Mod Rebooted", "trm_settings", "Settings", "", "", function( panel ) panel:ClearControls() panel:CheckBox( "Clean-Up Save", "terminalr_cleanupsave" ) panel:CheckBox( "Perma-Save", "terminalr_permasave" ) panel:NumSlider( "Hacking Time Restraint" "terminalr_hacktime", 20, 100 ) panel:NumSlider( "Firewall Activation Time", "terminalr_hackprotectiontime", 30, 100 ) panel:NumSlider( "Hacking Error Limit", "terminalr_hackerrorlimit", 5, 100 ) panel:NumSlider( "Hacking Score Desideratum", "terminalr_hackscoreneed", 5, 100 ) end ) end )[/CODE] The category isn't showing up in the spawnmenu, and it still hasn't created any convars. I'm not getting any script errors either. Have I done something wrong? Little help please :s: Thanks, Duck
Sorry, you need to Log In to post a reply to this thread.