OnPlayerChatCommand: Difference between revisions

From Onset Developer Wiki
(Created page with "{{Info|Event|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|OnPlayerChatCommand}} {{FuncParameters}} == Example == __EDIT_ME__ {{RelatedFunctions}} {{ServerEven...")
 
No edit summary
Line 1: Line 1:
{{Info|Event|Server|1.0}}
{{Info|Event|Server|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|Called when a player executes a command in the chat. See [[AddCommand]] to handle specific commands. You can call [[CancelChatCommand]] in this event to prevent the command from further processing.}}


{{FuncSyntax|OnPlayerChatCommand}}
{{FuncSyntax|OnPlayerChatCommand(player, command, exists)}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|player|The player who has executed the command.}}
{{FuncParam|command|The command name without slashes. For example: help}}
{{FuncParam|exists|'''0''' if the command is not bound by [[AddCommand]]. '''1''' if there is such handler.}}
== Example ==
== Example ==
__EDIT_ME__
<syntaxhighlight lang="Lua">
function OnPlayerChatCommand(player, cmd, exists)
if (GetTimeSeconds() - PlayerData[player].cmd_cooldown < 0.5) then
CancelChatCommand()
return AddPlayerChat(player, "Slow down with your commands")
end
 
PlayerData[player].cmd_cooldown = GetTimeSeconds()
 
if (exists == 0) then
AddPlayerChat(player, "Command '/"..cmd.."' not found!")
end
end
AddEvent("OnPlayerChatCommand", OnPlayerChatCommand)
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
{{ServerEvents}}
{{ServerEvents}}

Revision as of 22:31, 22 March 2019

OnPlayerChatCommand

Type: Event
Context: Server
Introduced: v1.0

Description

Called when a player executes a command in the chat. See AddCommand to handle specific commands. You can call CancelChatCommand in this event to prevent the command from further processing.

Syntax

OnPlayerChatCommand(player, command, exists)

Parameters

  • player
    The player who has executed the command.
  • command
    The command name without slashes. For example: help
  • exists
    0 if the command is not bound by AddCommand. 1 if there is such handler.

Example

function OnPlayerChatCommand(player, cmd, exists)	
	if (GetTimeSeconds() - PlayerData[player].cmd_cooldown < 0.5) then
		CancelChatCommand()
		return AddPlayerChat(player, "Slow down with your commands")
	end

	PlayerData[player].cmd_cooldown = GetTimeSeconds()

	if (exists == 0) then
		AddPlayerChat(player, "Command '/"..cmd.."' not found!")
	end
end
AddEvent("OnPlayerChatCommand", OnPlayerChatCommand)

See also

Player

Vehicle

Game

Package

NPC

Object

Pickup

Text3D

Door