meta/sh_tool¶
Source: gamemode/framework/meta/sh_tool.lua
Creates and returns a new tool object instance from this metatable.
Documented functions: 19
Functions¶
TOOL:Allowed()TOOL:BuildConVarList()TOOL:CheckObjects()TOOL:Create()TOOL:CreateConVars()TOOL:Deploy()TOOL:GetClientInfo(property)TOOL:GetClientNumber(property, default)TOOL:GetMode()TOOL:GetOwner()TOOL:GetServerInfo(property)TOOL:GetSWEP()TOOL:GetWeapon()TOOL:Holster()TOOL:Init()TOOL:LeftClick()TOOL:Reload()TOOL:RightClick()TOOL:Think()
TOOL:Allowed()¶
Returns whether this tool mode is allowed to be used on the server.
On the client, always returns true (enforcement happens server-side).
On the server, reads the "toolmode_allow_<mode>" convar created by CreateConVars; returns its boolean value.
Realm: shared
Returns
boolean: True if the tool is allowed, false if disabled by the server.
TOOL:BuildConVarList()¶
Returns the full client convar table for this tool, with prefixed keys.
Iterates self.ClientConVar and builds a new table keyed by "<mode>_<k>" with the corresponding default values.
Useful for syncing all tool convars at once.
Realm: shared
Returns
table: A table of{ ["<mode>_<cvar>"] = defaultValue }entries.
TOOL:CheckObjects()¶
Validates that all stored tool objects are still valid entities.
Iterates self.Objects and calls ClearObjects if any entry's Ent field is neither a valid entity nor the world.
This prevents operations on stale entity references (e.g. when a prop is deleted mid-interaction).
Checks the objects before any action is taken
This is to make sure that the entities haven't been removed
Realm: shared
TOOL:Create()¶
Creates and returns a new tool object instance from this metatable.
Replicated from the Sandbox tool base (stool.lua).
Initialises all standard fields with their defaults: Mode, SWEP, Owner, ClientConVar, ServerConVar, Objects, Stage, Message, LastMessage, and AllowedCVar.
Callers should override fields on the returned object as needed before use.
Realm: shared
Returns
table: A new tool instance with default field values. code replicated from gamemodes/sandbox/entities/weapons/gmod_tool/stool.lua
TOOL:CreateConVars()¶
Creates the console variables required by this tool.
On the client, iterates self.ClientConVar and calls CreateClientConVar for each entry prefixed with "<mode>_".
On the server, creates the "toolmode_allow_<mode>" convar (with FCVAR_NOTIFY) which controls whether this tool mode is permitted on the server.
This is called automatically during tool registration.
Realm: shared
TOOL:Deploy()¶
Called when the tool is deployed (the player selects it).
Releases any ghost entity via ReleaseGhostEntity.
Override to show a preview ghost or run setup logic when the player switches to this tool.
Realm: shared
TOOL:GetClientInfo(property)¶
Returns the string value of a client-side convar for this tool.
Reads the convar named "<mode>_<property>" from the owning player via Player:GetInfo.
This reflects the client's locally set value.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
property |
string |
The convar suffix (the part after "<mode>_"). |
Returns
string: The string value of the client convar.
TOOL:GetClientNumber(property, default)¶
Returns the numeric value of a client-side convar for this tool.
Reads the convar named "<mode>_<property>" from the owning player via Player:GetInfoNum.
Falls back to default (converted to number, or 0) when the convar is unset or non-numeric.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
property |
string |
The convar suffix (the part after "<mode>_"). |
default |
number\|nil |
The fallback value when the convar is unset. Defaults to 0. |
Returns
number: The numeric value of the client convar.
TOOL:GetMode()¶
Returns the mode string identifying this tool.
The mode string is the tool's registered name (e.g. "axis", "weld").
It is used as the prefix for all convar names associated with this tool.
Realm: shared
Returns
string: The tool mode identifier string.
TOOL:GetOwner()¶
Returns the player entity that owns this tool.
Reads SWEP.Owner first, falling back to self.Owner when the SWEP reference is unavailable.
This is the player who has the gmod_tool weapon equipped.
Realm: shared
Returns
Player: The owning player entity.
TOOL:GetServerInfo(property)¶
Returns the string value of a server-side convar for this tool.
Reads the convar named "<mode>_<property>" via GetConVarString.
Useful for reading server-authoritative settings from within shared or client code.
Realm: shared
Parameters
| Name | Type | Description |
|---|---|---|
property |
string |
The convar suffix (the part after "<mode>_"). |
Returns
string: The string value of the convar.
TOOL:GetSWEP()¶
Returns the SWEP (scripted weapon) that this tool is attached to.
The SWEP is the gmod_tool weapon entity in the player's hand.
Access the owning player via GetOwner() rather than reading SWEP.Owner directly.
Realm: shared
Returns
table: The SWEP entity table.
TOOL:GetWeapon()¶
Returns the weapon entity that holds this tool.
Reads SWEP.Weapon first, falling back to self.Weapon.
Equivalent to the gmod_tool weapon entity rather than the owning player.
Realm: shared
Returns
Entity: The weapon entity.
TOOL:Holster()¶
Called when the tool is holstered (the player switches away from it).
Releases any ghost entity via ReleaseGhostEntity.
Override to clean up any visual state or timers created during Deploy.
Realm: shared
TOOL:Init()¶
Called when the tool is first initialised.
Empty by default; override this in a tool definition to run setup logic when the tool object is created.
Equivalent to the Init stub in the Sandbox tool base.
Realm: shared
TOOL:LeftClick()¶
Called when the player left-clicks while this tool is active.
Returns false by default (no action taken).
Override in a tool definition to implement the primary tool interaction (e.g. placing, welding, constraining).
Realm: shared
Returns
boolean: True if the click was handled, false otherwise.
TOOL:Reload()¶
Called when the player presses the reload key while this tool is active.
Clears all stored objects via ClearObjects.
Override to add additional reset behaviour, but ensure ClearObjects is still called to maintain consistent state.
Realm: shared
TOOL:RightClick()¶
Called when the player right-clicks while this tool is active.
Returns false by default (no action taken).
Override in a tool definition to implement the secondary tool interaction.
Realm: shared
Returns
boolean: True if the click was handled, false otherwise.
TOOL:Think()¶
Called every frame while this tool is active.
Releases any ghost entity by default.
Override to implement per-frame ghost preview updates; call ReleaseGhostEntity only when no ghost should be shown.
Realm: shared