PlayerChat: Difference between revisions
m (→Example) |
No edit summary |
||
| (6 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
This event is triggered when a player send a message in the chat. | This event is triggered when a player send a message in the chat. | ||
{{ServersideCsJsEvent}} | |||
= | {{CSharpContainer|1= | ||
See [[OnChatMessage]]. | |||
}} | |||
{{JSContainer| | |||
{{Parameters}} | |||
* '''player''': {{RageType|Player}} - player, who send message | |||
* '''text''': {{RageType|String}} - the text that was sent | |||
{{Example}} | |||
This example will gives 300 money a player if his nickname is "Modernß" and he types "sorry" in chat. | This example will gives 300 money a player if his nickname is "Modernß" and he types "sorry" in chat. | ||
< | <pre> | ||
function checkChatMessage(player, text) { | function checkChatMessage(player, text) { | ||
if (player.name === "Modernß" && text == "sorry") { | if (player.name === "Modernß" && text == "sorry") { | ||
| Line 16: | Line 23: | ||
mp.events.add("playerChat", checkChatMessage); | mp.events.add("playerChat", checkChatMessage); | ||
</pre> | |||
}} | |||
{{ClientsideCsJsEvent}} | |||
{{CSharpContainer| | |||
<syntaxhighlight lang="csharp"> | |||
public delegate void OnPlayerChatDelegate(string text, CancelEventArgs cancel); | |||
</syntaxhighlight> | |||
{{Parameters}} | |||
* '''text''': text, expects '''System.String''' type. | |||
* '''cancel''': cancel, expects '''RAGE.Events.CancelEventArgs''' type. | |||
{{Example}} | |||
<syntaxhighlight lang="csharp"> | |||
Events.OnPlayerChat += OnPlayerChat; | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="csharp"> | |||
public void OnPlayerChat(string text, RAGE.Events.CancelEventArgs cancel) | |||
{ | |||
if (text == "who is george") | |||
{ | |||
RAGE.Chat.Output("He is the bossmen"); | |||
} | |||
else if (text == "who is jaimuzu") | |||
{ | |||
RAGE.Chat.Output("He is a beast"); | |||
} | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | |||
{{JSContainer| | |||
{{Parameters}} | |||
* '''text''': {{RageType|String}} | |||
{{Example}} | |||
<pre> | |||
mp.events.add("playerChat", (text) => { | |||
if (text === "test") { | |||
mp.gui.chat.push("You wrote 'test' in chat."); | |||
} | |||
}); | |||
</pre> | |||
}} | |||
==See also== | ==See also== | ||
{{Player_events}} | {{Player_events}} | ||
[[Category:Player]] | |||
[[Category:Server-side Event]] | |||
[[Category:Client-side Event]] | |||
Latest revision as of 19:01, 15 May 2024
This event is triggered when a player send a message in the chat.
Server-Side Event
C# Syntax
See OnChatMessage.
JavaScript Syntax
Parameters
- player: Player - player, who send message
- text: String - the text that was sent
Example
This example will gives 300 money a player if his nickname is "Modernß" and he types "sorry" in chat.
function checkChatMessage(player, text) {
if (player.name === "Modernß" && text == "sorry") {
player.money += 300;
}
};
mp.events.add("playerChat", checkChatMessage);
Client-Side Event
C# Syntax
public delegate void OnPlayerChatDelegate(string text, CancelEventArgs cancel);
Parameters
- text: text, expects System.String type.
- cancel: cancel, expects RAGE.Events.CancelEventArgs type.
Example
Events.OnPlayerChat += OnPlayerChat;
public void OnPlayerChat(string text, RAGE.Events.CancelEventArgs cancel)
{
if (text == "who is george")
{
RAGE.Chat.Output("He is the bossmen");
}
else if (text == "who is jaimuzu")
{
RAGE.Chat.Output("He is a beast");
}
}
JavaScript Syntax
Parameters
- text: String
Example
mp.events.add("playerChat", (text) => {
if (text === "test") {
mp.gui.chat.push("You wrote 'test' in chat.");
}
});
See also
Checkpoint
Colshape
Entity
Player
- playerChat
- playerCommand
- playerDamage
- playerDeath
- playerJoin
- playerQuit
- playerReady
- playerSpawn
- playerWeaponChange
Streaming
Vehicle
- playerStartEnterVehicle
- playerEnterVehicle
- playerStartExitVehicle
- playerExitVehicle
- trailerAttached
- vehicleDamage
- vehicleDeath
- vehicleHornToggle
- vehicleSirenToggle