Garry's Mod Wiki

GM:PlayerBindPress

  boolean GM:PlayerBindPress( Player ply, string bind, boolean pressed, number code )

Description

Runs when a bind has been pressed. Allows to block commands.

By using the "alias" console command, this hook can be effectively circumvented. To prevent this use input.TranslateAlias.

To stop the user from using +attack, +left and any other movement commands of the sort, please look into using GM:StartCommand instead.

The third argument will always be true.

Issue Tracker: 1176
This does not run for function keys binds (F1-F12).

Issue Tracker: 2888

Arguments

1 Player ply
The player who used the command; this will always be equal to LocalPlayer.
2 string bind
The bind command.
3 boolean pressed
If the bind was activated or deactivated.
4 number code
The button code. See BUTTON_CODE Enums.

Returns

1 boolean
Return true to prevent the bind.

Example

Prevents players from using flashlight.

hook.Add( "PlayerBindPress", "PlayerBindPressExample", function( ply, bind, pressed ) --To block more commands, you could add another line similar to --the one below, just replace the command if ( string.find( bind, "impulse 100" ) ) then return true end end )