Structures/TOOL

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Remove items that are deprecated and don't work anymore)
(Add more info to BuildCPanel)
 
Line 9: Line 9:
  
 
Ensure that all tool file names are entirely lowercase.  Including capital letters can lead to unintended behavior.
 
Ensure that all tool file names are entirely lowercase.  Including capital letters can lead to unintended behavior.
|Fields={{StructureField|boolean|AddToMenu|If set to false, the tool won't be added to the tool menu and players will have to access it by other means.|true}}
+
|Fields={{StructureField|boolean|AddToMenu|If set to false, the tool won't be added to the tool menu and players will have to access it by other means.|true}}{{StructureField|string|Category|The tool menu category under which the tool should be listed.|"New Category"}}{{StructureField|string|Command|The console command to execute upon being selected in the Q menu.|"gmod_toolmode [tool]"}}{{StructureField|string|Name|The name of the tool in the Q menu.
{{StructureField|string|Category|The tool menu category under which the tool should be listed.|"New Category"}}
+
{{StructureField|string|Command|The console command to execute upon being selected in the Q menu.|"gmod_toolmode [tool]"}}{{StructureField|string|Name|The name of the tool in the Q menu.
+
 
Common practice is to set this to "#tool.[lua filename].name" to match the name displayed in the tool information box.|"#[tool mode]"
 
Common practice is to set this to "#tool.[lua filename].name" to match the name displayed in the tool information box.|"#[tool mode]"
}}
+
}}{{StructureField|table|ClientConVar|A key-value ( convar name-default value ) table containing the client-side convars to create. All convars will be prefixed with the filename of the tool.
{{StructureField|table|ClientConVar|A key-value ( convar name-default value ) table containing the client-side convars to create. All convars will be prefixed with the filename of the tool.
+
 
You can later use {{ClassFunction|Tool|GetClientNumber}} or {{ClassFunction|Tool|GetClientInfo}} to retrieve these values.
 
You can later use {{ClassFunction|Tool|GetClientNumber}} or {{ClassFunction|Tool|GetClientInfo}} to retrieve these values.
}}
+
}}{{StructureField|table|ServerConVar|Same as above, but created server-side instead.}}{{StructureField|function|BuildCPanel|The function that is called to build the context menu for your tool. It has one argument, namely the context menu's base panel to which all of your custom panels are going to be parented to.
{{StructureField|table|ServerConVar|Same as above, but created server-side instead.}}
+
{{StructureField|function|BuildCPanel|The function that is called to build the context menu for your tool. It has one argument, namely the context menu's base panel to which all of your custom panels are going to be parented to.
+
  
While it might sound like a hook, it isn't - you won't receive a self argument inside the function.
+
While it might sound like a hook, it isn't - you won't receive a self argument inside the function. The only argument you will receive is a {{Type|DForm}} that represents the CPanel.
}}
+
 
{{StructureField|table|Information|Allows you to override the tool usage information shown when the tool is equipped.
+
{{Note|You can use the <pre class="inline">spawnmenu_reload</pre> console command to rebuild tool CPanels.}}
 +
}}{{StructureField|table|Information|Allows you to override the tool usage information shown when the tool is equipped.
 
See [[Tool Information Display]] for more information.
 
See [[Tool Information Display]] for more information.
}}
+
}}{{StructureField|string|Mode|Class name of the tool. (name of the .lua file)
{{StructureField|string|Mode|Class name of the tool. (name of the .lua file)
+
  
 
This is set automatically.
 
This is set automatically.
 
}}
 
}}
 
}}
 
}}

Latest revision as of 14:57, 23 January 2020

This function or feature is only available in the Sandbox gamemode and its derivatives.

The TOOL table is used in Sandbox tool creation. You can find a list of callbacks on the TOOL Hooks page and a list of methods on the Tool Functions page. Do note that some of the fields below have no effect on server-side operations.

The tool information box drawn on the HUD while your tool is selected has 2 values that are set by language.Add.
"tool.[tool mode].name" - The tool name (Note this is NOT the same as TOOL.Name)
"tool.[tool mode].desc" - The tool description

Ensure that all tool file names are entirely lowercase. Including capital letters can lead to unintended behavior.

Type Name Description
boolean AddToMenu

If set to false, the tool won't be added to the tool menu and players will have to access it by other means.

Default: true

string Category

The tool menu category under which the tool should be listed.

Default: "New Category"

string Command

The console command to execute upon being selected in the Q menu.

Default: "gmod_toolmode [tool]"

string Name

The name of the tool in the Q menu. Common practice is to set this to "#tool.[lua filename].name" to match the name displayed in the tool information box.

Default: "#[tool mode]"

table ClientConVar

A key-value ( convar name-default value ) table containing the client-side convars to create. All convars will be prefixed with the filename of the tool. You can later use Tool:GetClientNumber or Tool:GetClientInfo to retrieve these values.

table ServerConVar

Same as above, but created server-side instead.

function BuildCPanel

The function that is called to build the context menu for your tool. It has one argument, namely the context menu's base panel to which all of your custom panels are going to be parented to.

While it might sound like a hook, it isn't - you won't receive a self argument inside the function. The only argument you will receive is a DForm that represents the CPanel.

NOTE You can use the
spawnmenu_reload
console command to rebuild tool CPanels.
table Information

Allows you to override the tool usage information shown when the tool is equipped. See Tool Information Display for more information.

string Mode

Class name of the tool. (name of the .lua file)

This is set automatically.

Personal tools
Navigation