GM/PlayerBindPress
From Garry's Mod
(Difference between revisions)
Robotboy655 (Talk | contribs) (Change the example to use hook system) |
|||
(8 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{Hook | {{Hook | ||
− | |||
− | |||
|Description=Runs when a bind has been pressed. Allows to block commands. | |Description=Runs when a bind has been pressed. Allows to block commands. | ||
+ | |||
+ | {{Note|By using the "alias" console command, this hook can be effectively circumvented}} | ||
+ | |||
+ | {{Note|To stop the user from using +attack, +left and any other movement commands of the sort, please look into using {{HookFunction|GM|StartCommand}} instead}} | ||
+ | |||
+ | {{Bug|Issue=1176|The third argument will always be true.}} | ||
+ | |||
+ | {{Bug|Issue=2888|This does not run for function keys binds (F1-F12).}} | ||
|Realm=Client | |Realm=Client | ||
|Predicted=No | |Predicted=No | ||
Line 9: | Line 15: | ||
|type=Player | |type=Player | ||
|name=ply | |name=ply | ||
− | |desc=The player who used the command | + | |desc=The player who used the command; this will always be equal to {{GlobalFunction|LocalPlayer}} |
}} | }} | ||
{{Arg | {{Arg | ||
Line 27: | Line 33: | ||
{{Example | {{Example | ||
|Description=Prevents players from using flashlight. | |Description=Prevents players from using flashlight. | ||
− | |Code= | + | |Code=hook.Add( "PlayerBindPress", "PlayerBindPressExample", function( ply, bind, pressed ) |
--To block more commands, you could add another line similar to | --To block more commands, you could add another line similar to | ||
--the one below, just replace the command | --the one below, just replace the command | ||
if ( string.find( bind, "impulse 100" ) ) then return true end | if ( string.find( bind, "impulse 100" ) ) then return true end | ||
− | end | + | end ) |
}} | }} |
Latest revision as of 14:35, 31 May 2019
GM:PlayerBindPress( )
Contents |
Description
Runs when a bind has been pressed. Allows to block commands.
NOTE |
By using the "alias" console command, this hook can be effectively circumvented |
NOTE |
To stop the user from using +attack, +left and any other movement commands of the sort, please look into using GM:StartCommand instead |
BUG |
The third argument will always be true. Issue Tracker: #1176 |
BUG |
This does not run for function keys binds (F1-F12). Issue Tracker: #2888 |
Arguments
Player ply
The player who used the command; this will always be equal to LocalPlayer
Arguments
string bind
The bind command
Arguments
boolean pressed
If the bind was activated or deactivated
Returns
Return true to prevent the bind
Examples
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 )