PlayerChat: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
 
(5 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.


==Parameters==
{{ServersideCsJsEvent}}
* '''player''' - player, who send message
* '''text''' - the text that was sent


==Example==
{{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.
{{ServerSide}}
 
<syntaxhighlight lang="javascript">
<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}}


{{ClientSide}}
{{Example}}
<syntaxhighlight lang="javascript">
<pre>
mp.events.add("playerChat", (value) => {
mp.events.add("playerChat", (text) => {
     if (value == "test") {
     if (text === "test") {
           mp.gui.chat.push("You wrote 'test' in chat.");
           mp.gui.chat.push("You wrote 'test' in chat.");
     }
     }
});
});
</syntaxhighlight>
</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#  JavaScript




C# Syntax


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#  JavaScript



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

Streaming

Vehicle

Waypoint