ToolClass
A script class that is instanced for every active Tool in the game.
A tool is something that a Player can equip by selecting it in the hotbar, for example the Sledgehammer.
The class can receive events sent with sm.event.sendToTool.
The fields below are accessed using self.fieldName
in the ToolClass script:
Type | Name | Description |
---|---|---|
Tool | tool | The Tool game object belonging to this class instance. |
Network | network | A Network object that can be used to send data between client and server. |
Storage | storage | A server-side Storage object that can be used to save and load data to/from the world database. |
any | data | Data from the data entry in the tool's JSON file entry. |
Client-only
onEquip
function ToolClass.client_onEquip( self, animate )
end
Called when the a Player equips the Tool.
Arguments:self
[ table ]: The class instance.animate
[ bool ]: A boolean indicating whether the event should be animated or not.
onUnequip
function ToolClass.client_onUnequip( self, animate )
end
Called when the a Player unequips the Tool.
Arguments:self
[ table ]: The class instance.animate
[ bool ]: A boolean indicating whether the event should be animated or not.
onEquippedUpdate
function ToolClass.client_onEquippedUpdate( self, primaryState, secondaryState, forceBuild )
return true, true --first boolean blocks other primary actions, second boolean blocks other secondary actions
end
Called every frame for the currently equipped Tool.
Swinging the sledgehammer is a typical example where you want to block other primary input.
Force building is an example where the primary input action is not blocked.
Not blocking secondary input allows shape removal while the tool is equipped.
See sm.tool.interactState for details about the primary and secondary state.
Arguments:self
[ table ]: The class instance.primaryState
[ int ]: The interact state of the primary (left) mouse button.secondaryState
[ int ]: The interact state of the secondary (right) mouse button.forceBuild
[ bool ]: The interact state of theForce Build
key (defaultF
).
- [ bool ]: A boolean indicating whether other primary actions should be blocked (defaults to false).
- [ bool ]: A boolean indicating whether other secondary actions should be blocked (defaults to false).
onToggle
function ToolClass.client_onToggle( self )
return true --true or false, default false
end
Called when the Player presses a toggle key with the Tool equipped (default Q
and Shift + Q
).
self
[ table ]: The class instance.
- [ bool ]: A boolean that indicates if other toggle actions should be blocked (rotating shapes). Defaults to false.
onReload
function ToolClass.client_onReload( self )
return true --true or false, default false
end
Called when the Player presses the Reload
key with the Tool equipped (default R
).
self
[ table ]: The class instance.
- [ bool ]: A boolean that indicates if other reload actions should be blocked (
PlayerClass.client_onReload
). Defaults to false.
canEquip
function ToolClass.client_canEquip( self )
return true --true or false, default false
end
This event is called to check whether the Tool can be equipped.
Arguments:self
[ table ]: The class instance.
- [ bool ]: A boolean that indicates if the Tool can be equipped. Defaults to true.