PlayerCommand: Difference between revisions

From RAGE Multiplayer Wiki
m (remove unnecessary semicolons and add a semicolon at the right place)
m (Replaced HTML with template)
Line 8: Line 8:
==Example #1==
==Example #1==
This example will write "Hello!" to player, who will enter command /meetme into chatbox.s
This example will write "Hello!" to player, who will enter command /meetme into chatbox.s
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">
{{ServersideCode|
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div>
<pre>
<syntaxhighlight lang="javascript">
mp.events.add("playerCommand", (player, command) => {
mp.events.add("playerCommand", (player, command) => {
const args = command.split(/[ ]+/);
const args = command.split(/[ ]+/);
Line 19: Line 18:
}
}
});
});
</syntaxhighlight>
</pre>
</div>
}}


==Example #2==
==Example #2==
Line 27: Line 26:
if you enter "/blah 123 566", it will output next message:
if you enter "/blah 123 566", it will output next message:
"You enter command a "blah", and all arguments it a [123,566]"
"You enter command a "blah", and all arguments it a [123,566]"
<div class="header" style="background-color: #AE4040; color: #FFFFFF; border: 2px solid #AE4040;">
{{ServersideCode|
<div style="margin: 10px 10px 10px 10px;"><b>Client-Side</b></div>
<pre>
<syntaxhighlight lang="javascript">
mp.events.add("playerCommand", (command) => {
mp.events.add("playerCommand", (command) => {
const args = command.split(/[ ]+/);
const args = command.split(/[ ]+/);
Line 40: Line 38:
}
}
});
});
</syntaxhighlight>
</pre>
</div>
}}


==See also==
==See also==
{{Player_events}}
{{Player_events}}

Revision as of 12:06, 26 October 2018

This event is triggered when player send command .

Parameters

  • player - player, who send command.
  • command - string with arguments.

Example #1

This example will write "Hello!" to player, who will enter command /meetme into chatbox.s

Server-Side
mp.events.add("playerCommand", (player, command) => {
	const args = command.split(/[ ]+/);
	const commandName = args.splice(0, 1)[0];
		
	if (commandName === "meetme") {
		player.outputChatBox("Hello!");
	}
});

Example #2

This example will output info about entered command into client chatbox.

if you enter "/blah 123 566", it will output next message: "You enter command a "blah", and all arguments it a [123,566]"

Server-Side
mp.events.add("playerCommand", (command) => {
	const args = command.split(/[ ]+/);
	const commandName = args[0];

	args.shift();
		
	if (commandName === "blah") {
		mp.gui.chat.push(`You enter command a "${commandName}", and all arguments it a [${args.join(",")}]`);
	}
});

See also

Checkpoint

Colshape

Entity

Player

Streaming

Vehicle

Waypoint