PlayerChat: Difference between revisions

From RAGE Multiplayer Wiki
mNo edit summary
No edit summary
 
(2 intermediate revisions by one other user 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}}
{{ServersideCsJsEvent}}
{{CSharpContainer|1=
See [[OnChatMessage]].
}}


{{JSContainer|
{{JSContainer|
{{Parameters}}
{{Parameters}}
* '''player''' - player, who send message
* '''player''': {{RageType|Player}} - player, who send message
* '''text''' - the text that was sent
* '''text''': {{RageType|String}} - the text that was sent


{{Example}}
{{Example}}
Line 20: Line 25:
</pre>
</pre>
}}
}}
{{ClientsideCsJsEvent}}
{{ClientsideCsJsEvent}}
{{CSharpContainer|
{{CSharpContainer|
<syntaxhighlight lang="c#">
<syntaxhighlight lang="csharp">
public delegate void OnPlayerChatDelegate(string text, CancelEventArgs cancel);
public delegate void OnPlayerChatDelegate(string text, CancelEventArgs cancel);
</syntaxhighlight>
</syntaxhighlight>
Line 31: Line 38:


{{Example}}
{{Example}}
<syntaxhighlight lang="c#">
<syntaxhighlight lang="csharp">
Events.OnPlayerChat += OnPlayerChat;
Events.OnPlayerChat += OnPlayerChat;
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="c#">
<syntaxhighlight lang="csharp">
public void OnPlayerChat(string text, RAGE.Events.CancelEventArgs cancel)
public void OnPlayerChat(string text, RAGE.Events.CancelEventArgs cancel)
{
{
Line 48: Line 55:
</syntaxhighlight>
</syntaxhighlight>
}}
}}
{{JSContainer|
{{JSContainer|
{{Parameters}}
* '''text''': {{RageType|String}}
{{Example}}
<pre>
<pre>
mp.events.add("playerChat", (text) => {
mp.events.add("playerChat", (text) => {
Line 57: Line 69:
</pre>
</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