OnPlayerChatCommand: Difference between revisions

From Onset Developer Wiki
No edit summary
No edit summary
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 call [[CancelChatCommand]] in this event to prevent the command from further processing.}}
{{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)}}
Line 14: Line 14:
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
CancelChatCommand()
AddPlayerChat(player, "Slow down with your commands")
return AddPlayerChat(player, "Slow down with your commands")
return false
end
end


Line 23: Line 23:
AddPlayerChat(player, "Command '/"..cmd.."' not found!")
AddPlayerChat(player, "Command '/"..cmd.."' not found!")
end
end
return true
end
end
AddEvent("OnPlayerChatCommand", OnPlayerChatCommand)
AddEvent("OnPlayerChatCommand", OnPlayerChatCommand)

Revision as of 22:44, 29 September 2019

OnPlayerChatCommand

Type: Event
Context: Server & Client
Introduced: v1.0

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)

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 (exists == 0) then
		AddPlayerChat(player, "Command '/"..cmd.."' not found!")
	end
	return true
end
AddEvent("OnPlayerChatCommand", OnPlayerChatCommand)

See also

Player

Vehicle

Game

Package

NPC

Object

Pickup

Text3D

Door