Garry's Mod Wiki

ENTITY:CanTool

  boolean ENTITY:CanTool( Player ply, table tr, string toolname, table tool, number button )

Description

Controls if a tool can be used on this entity or not.

This hook will only work in Sandbox derived gamemodes that do not have SANDBOX:CanTool overridden.

This hook will work on ALL entities, not just the scripted ones (SENTs)

Arguments

1 Player ply
Player, that tried to use the tool
2 table with TraceResult structure tr
The trace of the tool.

Returns only the world in the Entity key and returns false in the Hit key when the 5th argument returns 4.
3 string toolname
Class of the tool that is tried to use, for example - weld
4 table tool
The tool mode table the player currently has selected.
5 number button
The tool button pressed.

  • 1 - left click
  • 2 - right click
  • 3 - reload
  • 4 - spawn menu (No interaction with the toolgun). Client-side only

Returns

1 boolean
Return false to disallow using that tool on this entity, return true to allow.

Example

Prevents usage of the remover tool on this entity.

function ENT:CanTool( ply, trace, mode, tool, button ) if ( mode == "remover" ) then return false end return true end