Garry's Mod Wiki

Tool

A list of functions available inside a Sandbox Toolgun tool.

You can find the hooks here, and members here.

Methods

Returns whether the tool is allowed to be used or not. This function ignores the SANDBOX:CanTool hook. By default this will always return true clientside and uses TOOL. AllowedCVarwhich is a ConVar object pointing to toolmode_allow_*toolname* convar on the server.
Builds a list of all ConVars set via the ClientConVar variable on the TOOL structure and their default values. This is used for the preset system.
Tool:CheckObjects()
This is used internally - although you're able to use it you probably shouldn't. This is called automatically for most toolgun actions so you shouldn't need to use it. Checks all added objects to see if they're still valid, if not, clears the list of objects.
Tool:ClearObjects()
Clears all objects previously set with Tool:SetObject.
Tool Tool:Create()
This is used internally - although you're able to use it you probably shouldn't. This is called automatically for all tools. Initializes the tool object
This is used internally - although you're able to use it you probably shouldn't. This is called automatically for all tools. Creates clientside ConVars based on the ClientConVar table specified in the tool structure. Also creates the 'toolmode_allow_X' ConVar.
number Tool:GetBone( number id )
Retrieves a physics bone number previously stored using Tool:SetObject.
number Tool:GetClientBool( string name, boolean default = false )
Attempts to grab a clientside tool ConVar value as a boolean.
Attempts to grab a clientside tool ConVar as a string.
number Tool:GetClientNumber( string name, number default = 0 )
Attempts to grab a clientside tool ConVar's value as a number.
Entity Tool:GetEnt( number id )
Retrieves an Entity previously stored using Tool:SetObject.
Returns a language key based on this tool's name and the current stage it is on.
Retrieves an local vector previously stored using Tool:SetObject. See also Tool:GetPos.
Returns the name of the current tool mode.
Retrieves an normal vector previously stored using Tool:SetObject.
Returns the current operation of the tool set by Tool:SetOperation.
Returns the owner of this tool.
Retrieves an PhysObj previously stored using Tool:SetObject. See also Tool:GetEnt.
Vector Tool:GetPos( number id )
Retrieves an vector previously stored using Tool:SetObject. See also Tool:GetLocalPos.
Attempts to grab a serverside tool ConVar. This will not do anything on client, despite the function being defined shared.
Returns the current stage of the tool set by Tool:SetStage.
We advise against using this. It may be changed or removed in a future update. Use Tool:GetWeapon instead. Returns the Tool Gun (gmod_tool) Scripted Weapon.
Returns the Tool Gun (gmod_tool) Scripted Weapon.
Tool:MakeGhostEntity( string model, Vector pos, Angle angle )
Initializes the ghost entity with the given model. Removes any old ghost entity if called multiple times. The ghost is a regular prop_physics entity in singleplayer games, and a clientside prop in multiplayer games.
Returns the amount of stored objects ( Entitys ) the tool has. Are TOOLs limited to 4 entities?
Tool:RebuildControlPanel( vararg extra_args )
Automatically forces the tool's control panel to be rebuilt.
Removes any ghost entity created for this tool. This is called automatically at various points, including when changing tools, holstering the toolgun, therefore it is a very good idea to implement this callback in your custom tool to cleanup any custom ghost entities.
Tool:SetObject( number id, Entity ent, Vector pos, PhysObj phys, number bone, Vector normal )
Stores an Entity for later use in the tool. The stored values can be retrieved by Tool:GetEnt, Tool:GetPos, Tool:GetLocalPos, Tool:GetPhys, Tool:GetBone and Tool:GetNormal
Tool:SetOperation( number operation )
Sets the current operation of the tool. Does nothing clientside. See also Tool:SetStage. Operations and stages work as follows: Operation 1 Stage 1 Stage 2 Stage 3 Operation 2 Stage 1 Stage 2 Stage . . .
Tool:SetStage( number stage )
Sets the current stage of the tool. Does nothing clientside. See also Tool:SetOperation.
Initializes the ghost entity based on the supplied entity.
Tool:UpdateData()
This is used internally - although you're able to use it you probably shouldn't. Called on deploy automatically Sets the tool's stage to how many stored objects the tool has.
Updates the position and orientation of the ghost entity based on where the toolgun owner is looking along with data from object with id 1 set by Tool:SetObject. This should be called in the tool's TOOL:Think hook. This command is only used for tools that move props, such as easy weld, axis and motor. If you want to update a ghost like the thruster tool does it for example, check its source code.