Revision Difference
spawnmenu.AddToolMenuOption#561468
<function name="AddToolMenuOption" parent="spawnmenu" type="libraryfunc">
<description>Adds an option to the right side of the spawnmenu</description>
<realm>Client</realm>
<file line="147-L175">lua/includes/modules/spawnmenu.lua</file>
<args>
<arg name="tab" type="string">The spawnmenu tab to add into (for example "Utilities")</arg>
<arg name="category" type="string">The category to add into (for example "Admin")</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.
<warning>We advise against using this. It may be changed or removed in a future update.</warning></arg>
<arg name="cpanel" type="function">A function to build the context panel. The function has one argument:⤶
* <page>Panel</page> pnl - A <page>DForm</page> that will be shown in the context menu</arg>⤶
<arg name="cpanel" type="function">A function to build the context panel.⤶
⤶
<callback>⤶
<arg type="Panel" name="pnl">A <page>DForm</page> that will be shown in the context menu</arg>⤶
</callback></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><image src="addtoolmenuoption.png" alt="400px"/></output>
</example>