OnPlayerChatCommand: Difference between revisions
From Onset Developer Wiki
No edit summary |
No edit summary |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Info|Event|Server & Client|1.0}} | {{Info|Event|Server & Client|1.0}} | ||
{{FuncDescription|Called when a player executes a command in the chat. See [[AddCommand]] to handle specific commands. You can | {{FuncDescription|Called when a player executes a command in the chat. See [[AddCommand]] to handle specific commands. You can return '''false''' in this event to prevent the command from being passed to it's handler.}} | ||
{{FuncSyntax|OnPlayerChatCommand(player, command, exists)}} | {{FuncSyntax|OnPlayerChatCommand(player, command, exists)}} | ||
{{FuncSyntaxClient|OnPlayerChatCommand(command, exists)}} | |||
{{FuncParameters}} | {{FuncParameters}} | ||
{{FuncParam|player|The player who has executed the command.}} | {{FuncParam|player|The player who has executed the command.}} | ||
{{FuncParam|command|The command name without slashes. For example: help}} | {{FuncParam|command|The command name without slashes. For example: help}} | ||
{{FuncParam|exists|''' | {{FuncParam|exists|'''false''' if the command is not bound by [[AddCommand]]. '''true''' if there is such handler.}} | ||
== Example == | == Example == | ||
Line 14: | Line 15: | ||
function OnPlayerChatCommand(player, cmd, exists) | function OnPlayerChatCommand(player, cmd, exists) | ||
if (GetTimeSeconds() - PlayerData[player].cmd_cooldown < 0.5) then | if (GetTimeSeconds() - PlayerData[player].cmd_cooldown < 0.5) then | ||
AddPlayerChat(player, "Slow down with your commands") | |||
return false | |||
end | end | ||
PlayerData[player].cmd_cooldown = GetTimeSeconds() | PlayerData[player].cmd_cooldown = GetTimeSeconds() | ||
if | if not exists then | ||
AddPlayerChat(player, "Command '/"..cmd.."' not found!") | AddPlayerChat(player, "Command '/"..cmd.."' not found!") | ||
end | end | ||
return true | |||
end | end | ||
AddEvent("OnPlayerChatCommand", OnPlayerChatCommand) | AddEvent("OnPlayerChatCommand", OnPlayerChatCommand) | ||
Line 28: | Line 30: | ||
{{RelatedFunctions}} | {{RelatedFunctions}} | ||
{{ | {{PlayerEvents}} |
Latest revision as of 13:33, 14 August 2020
Description
Called when a player executes a command in the chat. See AddCommand to handle specific commands. You can return false in this event to prevent the command from being passed to it's handler.
Syntax
OnPlayerChatCommand(player, command, exists)
Client Syntax
OnPlayerChatCommand(command, exists)
Parameters
- player
The player who has executed the command. - command
The command name without slashes. For example: help - exists
false if the command is not bound by AddCommand. true if there is such handler.
Example
function OnPlayerChatCommand(player, cmd, exists)
if (GetTimeSeconds() - PlayerData[player].cmd_cooldown < 0.5) then
AddPlayerChat(player, "Slow down with your commands")
return false
end
PlayerData[player].cmd_cooldown = GetTimeSeconds()
if not exists then
AddPlayerChat(player, "Command '/"..cmd.."' not found!")
end
return true
end
AddEvent("OnPlayerChatCommand", OnPlayerChatCommand)
See also
- OnPlayerServerAuth
- OnPlayerSteamAuth
- OnPlayerStreamIn
- OnPlayerStreamOut
- OnPlayerJoin
- OnPlayerQuit
- OnPlayerSpawn
- OnPlayerDeath
- OnPlayerWeaponShot
- OnPlayerDamage
- OnPlayerChat
- OnPlayerChatCommand
- OnPlayerInteractDoor
- OnPlayWeaponHitEffects
- OnPlayerSwitchCamera
- OnPlayerEnterWater
- OnPlayerLeaveWater
- OnPlayerCrouch
- OnPlayerEndCrouch
- OnPlayerEndFall
- OnPlayerFall
- OnPlayerTalking