Garry's Mod Wiki

spawnmenu.AddToolMenuOption

  spawnmenu.AddToolMenuOption( string tab, string category, string class, string name, string cmd = nil, string config = nil, function cpanel, table table = {} )

Description

Adds an option to the right side of the spawnmenu.

See spawnmenu.AddToolTab to add new right-side tabs. See spawnmenu.AddToolCategory to add new categories.

Arguments

1 string tab
The internal name of the spawnmenu tab to add into (for example "Utilities")
2 string category
The internal name of the category within the tab to add into (for example "Admin")
3 string class
Unique internal identifier of the new option. This is used to reference this option by other code.
4 string name
The nice name of item to show to the player. See Addon Localization.
5 string cmd = nil
Console command to execute when the item is selected.
6 string config = nil
Config name, used in older versions to load tool settings UI from a file.
We advise against using this. It may be changed or removed in a future update. Legacy argument, no longer works.
7 function cpanel
A function to build the context panel.
Function argument(s):
1 Panel pnl - A DForm that will be shown in the context menu
8 table table = {}
Allows to override the table that will be added to the tool list. Some of the fields will be overwritten by this function.

Example

Adds a new option to the menu with a slider to change the gravity

hook.Add( "AddToolMenuCategories", "CustomCategory", function() spawnmenu.AddToolCategory( "Utilities", "Stuff", "#Stuff" ) end ) hook.Add( "PopulateToolMenu", "CustomMenuSettings", function() spawnmenu.AddToolMenuOption( "Utilities", "Stuff", "Custom_Menu", "#My Custom Menu", "", "", function( panel ) panel:NumSlider( "Gravity", "sv_gravity", 0, 600 ) -- Add stuff here end ) end )
Output:

Example

Example on how to add a custom tool tab with a custom tool category and a tool option.

language.Add( "MyCoolTab.Title", "My Cool Tab" ) language.Add( "MyCoolTab.Category", "My Cool Category" ) language.Add( "MyCoolTab.ToolOption", "My Cool Menu Option" ) hook.Add( "AddToolMenuTabs", "myHookClass", function() spawnmenu.AddToolTab( "Internal_MyCoolTab", "#MyCoolTab.Title", "icon16/monkey.png" ) spawnmenu.AddToolCategory( "Internal_MyCoolTab", "Internal_MyCoolCategory", "#MyCoolTab.Category" ) end ) hook.Add( "PopulateToolMenu", "CustomMenuSettings", function() spawnmenu.AddToolMenuOption( "Internal_MyCoolTab", "Internal_MyCoolCategory", "Internal_MyCustomMenu", "#MyCoolTab.ToolOption", "", "", function( panel ) panel:NumSlider( "Gravity", "sv_gravity", 0, 600 ) end ) end )
Output:
image.png