Garry's Mod Wiki

GM:PlayerSwitchFlashlight

  boolean GM:PlayerSwitchFlashlight( Player ply, boolean enabled )

Description

Called whenever a player attempts to either turn on or off their flashlight, returning false will deny the change.

Also gets called when using Player:Flashlight.

Arguments

1 Player ply
The player who attempts to change their flashlight state.
2 boolean enabled
The new state the player requested, true for on, false for off.

Returns

1 boolean
Can toggle the flashlight or not

Example

Only allow the flashlight for admins, you can also use Player:AllowFlashlight for that.

hook.Add( "PlayerSwitchFlashlight", "BlockFlashLight", function( ply, enabled ) return ply:IsAdmin() -- Allow the player to use their flashlight if they are an admin end )