From GMod Wiki
Event Hook
|
Hook Name | CanTool
|
Syntax | GM:CanTool( Player ply, TraceRes tr, String toolmode )
|
Description | Determines whether or not a player is allowed to use a tool.
|
Returns | Boolean
|
Lua State |
|
BBCode | [b][url=wiki.garrysmod.com/?title=Gamemode.CanTool]Gamemode.CanTool [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
|
Examples
Description | Stops non-admins from using the Remover, Ignite, and RT Camera tools. |
Used on | |
Code | function UseTool(pl, _, toolmode)
//NOTE: The _ (underscore) can be used to ignore certain arguments passed to a function
//If the current tool is the remover, ignite, or rt camera
if toolmode == "remover" or toolmode == "ignite" or toolmode == "rtcamera" then
if pl:IsAdmin() then -- If the player is an admin/superadmin
return true -- Allow usage of the tools
else
return false -- Otherwise, disallow usage
end
end
end
hook.Add("CanTool", "UseTool", UseTool) |
Output | N/A |
Description | Prevents players from removing physics props. |
Used on | |
Code | function StopRemovalOfProps(_, trace, tool)
local ent = trace.Entity
//If the current tool is the remover, and the entity is a physics prop
if tool == "remover" and ent:GetClass() == "prop_physics" then
//Disallow Tool Usage
return false
end
end
hook.Add("CanTool", "Stop Prop Removal", StopRemovalOfProps) |
Output | N/A |
Toolgun Modes
The toolmode parameter is the filename of the tool (e.g. ignite.lua) without the .lua extenstion. The built in Garry's Mod toolgun modes are listed below:
- axis
- balloon
- ballsocket
- ballsocket_adv
- ballsocket_ez
- button
- camera
- colour
- duplicator
- dynamite
- elastic
- emitter
- example
- eyeposer
- faceposer
- paint
|
- physprop
- pulley
- remover
- rope
- rtcamera
- slider
- spawner
- statue
- thruster
- trails
- turret
- weld
- weld_ez
- wheel
- winch
- finger
|
- hoverball
- hydraulic
- ignite
- inflator
- keepupright
- lamp
- leafblower
- light
- magnetise
- material
- motor
- muscle
- nail
- nocollide
|
Here are the wire tools:
- wire_addressbus
- wire_adv
- wire_cam
- wire_colorer
- wire_cpu
- wire_dataplug
- wire_dataport
- wire_datarate
- wire_data_satellitedish
- wire_data_store
- wire_data_transferer
- wire_debugger
- wire_detonator
- wire_emarker
- wire_explosive
- wire_expression
- wire_forcer
- wire_fx_emitter
- wire_gate_expression
- wire_gps
|
- wire_gpu
- wire_grabber
- wire_graphics_tablet
- wire_gyroscope
- wire_hdd
- wire_hoverball
- wire_hudindicator
- wire_hydraulic
- wire_igniter
- wire_keyboard
- wire_las_reciever
- wire_latch
- wire_locator
- wire_nailer
- wire_namer
- wire_numpad
- wire_output
- wire_plug
- wire_pod
|
- wire_radio
- wire_ranger
- wire_relay
- wire_sensor
- wire_spawner
- wire_target_finder
- wire_textreceiver
- wire_thruster
- wire_trail
- wire_turret
- wire_twoway_radio
- wire_user
- wire_value
- wire_vehicle
- wire_vthruster
- wire_watersensor
- wire_waypoint
- wire_wheel
- wire_winch
- wire_wirelink
|
Additional Notes
- Return true to allow usage of the toolmode, false for not allowing it.
- toolmode is derived from the STool's filename, with the .lua extension removed.
See Also