Garry's Mod Wiki

Revision Difference

GM:PlayerSwitchFlashlight#527343

<function name="PlayerSwitchFlashlight" parent="GM" type="hook"> <ishook>yes</ishook> <description>Called whenever a player attempts to either turn on or off their flashlight, returning false will deny the change.</description> <realm>Server</realm> <args> <arg name="ply" type="Player">The player who attempts to change their flashlight state.</arg> <arg name="enabled" type="boolean">The new state the player requested, true for on, false for off.</arg> </args> <rets> <ret name="" type="boolean">Can toggle the flashlight or not</ret> </rets> </function> <note>Also gets called when using <page>Player:Flashlight</page>.</note> <note>Also gets called when using <page>Player:Flashlight</page>.</note>⤶ ⤶ <example>⤶ <description>Only allow the flashlight for admins, you can also use <page>Player:AllowFlashlight</page> for that.</description>⤶ <code>⤶ hook.Add( "PlayerSwitchFlashlight", "BlockFlashLight", function( ply, enabled )⤶ return ply:IsAdmin() -- disallow the player to use his flashlight if he's not an admin⤶ end )⤶ </code>⤶ ⤶ </example>