Tool class
Part of Flow
Base class of the tool gun tools that Flux loads. It reimplements the tool object of
Sandbox, so that a tool file written for Sandbox works as it is: the same fields (Mode,
ClientConVar, Objects and so on), the same callbacks to override (LeftClick,
RightClick, Reload, Think, Deploy, Holster, DrawHUD) and the same helpers for
console variables, selected objects and ghost entities. What Flux adds is that the name and
the description of a tool come from the tool.<id>.name and tool.<id>.desc language
phrases. Tool files are loaded from the tools folders by the Flux.Tool library, which
creates the object and passes it to the file as TOOL.
Summary
Methods
Methods
Converts the tool to a string for printing.
Returns
- String
Checks whether the tool is allowed to be used on the server. Always true on the client.
Returns
- Boolean
Builds a list of the client console variables of the tool with their defaults.
Returns
- Map default values by full variable name
Clears the selected objects if any of their entities has been removed.
Clears the selected objects, removes the ghost entity and resets the stage and operation.
Creates the console variables of the tool: the ones listed in ClientConVar on the client, and 'toolmode_allow_<mode>' on the server.
Called when the tool gun is deployed. Removes the ghost entity by default.
Gives the tool an opportunity to draw to the HUD. Does nothing by default.
Draws the scrolling name of the tool on the screen of the tool gun.
Parameters
- _w Number width of the screen
- _h Number height of the screen
Determines whether the view angles of the owner should be frozen while using the tool. Returns false by default.
Returns
- Boolean
Returns the physics bone number of the numbered hit (for ragdolls).
Parameters
- i Number index of the selected object
Returns
- Number
Returns the value of a client console variable of the tool for its owner.
Parameters
- property String name of the variable without the tool mode prefix
Returns
- String
Returns the value of a client console variable of the tool for its owner as a number.
Parameters
- property String name of the variable without the tool mode prefix
- default Number optional, defaults to
0returned if the variable is not a number
Returns
- Number
Returns the entity of the numbered hit.
Parameters
- i Number index of the selected object
Returns
- Entity the entity
- NULL if there is no object with this index
Returns the translated description of the tool.
Returns
- String
Returns the position of the numbered hit local to the entity that was hit.
Parameters
- i Number index of the selected object
Returns
- Vector
Returns the mode (ID) of the tool.
Returns
- String
Returns the surface normal of the numbered hit in world space.
Parameters
- i Number index of the selected object
Returns
- Vector
Returns the current operation of the tool.
Returns
- Number
Returns the player who holds the tool gun.
Returns
- Player
Returns the physics object of the numbered hit.
Parameters
- i Number index of the selected object
Returns
- PhysObj
Returns the world position of the numbered hit.
Parameters
- i Number index of the selected object
Returns
- Vector
Returns the value of a console variable of the tool.
Parameters
- property String name of the variable without the tool mode prefix
Returns
- String
Returns the current stage of the tool.
Returns
- Number
Returns the tool gun that this tool belongs to.
Returns
- Weapon
Returns the weapon entity of the tool gun.
Returns
- Weapon
Called when the tool gun is holstered. Removes the ghost entity by default.
Creates a new tool with the default values of its fields.
Called when the tool gun initializes the tool. Does nothing by default.
Called when the owner presses primary attack. Returns false by default.
Returns
- Boolean false, overrides should return true if the tool has done something
Creates a translucent ghost prop that previews the result of the tool, replacing the previous one. Ragdolls and effects cannot be ghosts.
Parameters
- model String path to the model
- pos Vector
- angle Angle
Returns the number of selected objects. On the client this is the stage of the tool.
Returns
- Number
Removes the ghost entity of the tool.
Called when the owner presses reload. Clears the selected objects by default.
Called when the owner presses secondary attack. Returns false by default.
Returns
- Boolean false, overrides should return true if the tool has done something
Stores a selected object. The position and the normal are converted to be local to the physics object (or the entity), so that they stay valid when it moves.
Parameters
- i Number index to store the object under
- ent Entity the entity that was hit
- pos Vector world position of the hit
- phys PhysObj physics object that was hit
- bone Number physics bone number
- norm Vector surface normal of the hit
Sets the operation of the tool and networks it to the clients. Does nothing on the client.
Parameters
- i Number
Sets the stage of the tool and networks it to the clients. Does nothing on the client.
Parameters
- i Number
Creates a ghost entity that copies the model, position and angles of the specified entity.
Parameters
- ent Entity
Called every tick while the tool is active. Removes the ghost entity by default.
Sets the stage of the tool to the number of selected objects.
Moves the ghost entity to where the first selected object would end up if the tool was applied to the spot the owner is aiming at.