Garry's Mod Wiki

spawnmenu.AddToolMenuOption

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

Description

Adds an option to the right side of the spawnmenu

Arguments

1 string tab
The spawnmenu tab to add into (for example "Utilities")
2 string category
The category to add into (for example "Admin")
3 string class
Unique identifier of option to add
4 string name
The nice name of item
5 string cmd
Command to execute when the item is selected
6 string config
Config name, used in older versions to load tool settings UI from a file. No longer works.
We advise against using this. It may be changed or removed in a future update.
7 function cpanel
A function to build the context panel. The function has one argument:
  • 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:ClearControls() panel:NumSlider( "Gravity", "sv_gravity", 0, 600 ) -- Add stuff here end ) end )
Output: