Revision Difference
SANDBOX:CanTool#529764
<function name="CanTool" parent="SANDBOX" type="hook">
<ishook>yes</ishook>
<description>Called when a player attempts to fire their tool gun. Return true to specifically allow the attempt, false to block it.</description>
<realm>Shared</realm>
<predicted>Yes</predicted>
<args>
<arg name="ply" type="Player">The player who attempted to use their toolgun.</arg>
<arg name="tr" type="table">A trace from the players eye to where in the world their crosshair/cursor is pointing. See <page>Structures/TraceResult</page></arg>
<arg name="tool" type="string">The tool mode the player currently has selected.</arg>
<arg name="toolname" type="string">The tool mode the player currently has selected.</arg>
<arg name="tool" type="table">The tool mode table the player currently has selected.</arg>⤶
<arg name="button" type="number">The tool button pressed.</arg>⤶
</args>
<rets>
<ret name="" type="boolean">Can use toolgun or not.</ret>
</rets>
</function>
<example>
<description>Stops players from removing doors.</description>
<code>
hook.Add( "CanTool", "CanToolExample", function( ply, tr, toolname, tool, button )
if tool == "remover" and IsValid( tr.Entity ) and tr.Entity:GetClass() == "prop_door_rotating" then
if toolname == "remover" and IsValid( tr.Entity ) and tr.Entity:GetClass() == "prop_door_rotating" then
return false
end
end )
</code>
</example>