Garry's Mod Wiki

Revision Difference

spawnmenu.AddToolMenuOption#512863

<function name="AddToolMenuOption" parent="spawnmenu" type="libraryfunc"> <description>Adds an option to the right side of the spawnmenu</description> <realm>Client</realm> <args> <arg name="tab" type="string">The spawnmenu tab to add into (for example &quot;Utilities&quot;)</arg> <arg name="category" type="string">The category to add into (for example &quot;Admin&quot;)</arg> <arg name="class" type="string">Unique identifier of option to add</arg> <arg name="name" type="string">The nice name of item</arg> <arg name="cmd" type="string">Command to execute when the item is selected</arg> <arg name="config" type="string">Config name, used in older versions to load tool settings UI from a file. No longer works.&#xA;&#xA;&lt;deprecated&gt;Category=No&lt;/deprecated&gt;</arg> <arg name="cpanel" type="function">A function to build the context panel. The function has one argument:&#xA;* &lt;page&gt;Panel&lt;/page&gt; pnl - A &lt;page&gt;DForm that will be shown in the context menu&lt;/page&gt;</arg> <arg name="table" type="table" default="{}">Allows to override the table that will be added to the tool list. Some of the fields will be overwritten by this function.</arg> </args> </function> <example> <description>Adds a new option to the menu with a slider to change the gravity</description> <code> 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 ) </code> <output></output> </example>