PlayerCommand: Difference between revisions

From RAGE Multiplayer Wiki
(Undo revision 5908 by Jack Savage (talk))
No edit summary
Line 6: Line 6:
* '''command - string with arguments.'''  
* '''command - string with arguments.'''  


==Example==
==Example #1==
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;">
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div>
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div>
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
mp.events.add(
mp.events.add("playerCommand",
    {
(player, command) => {
        "playerCommand": (player, command) => {
const args = command.split(/[ ]+/);
            let args = command.split(/[ ]+/);
const commandName = args.splice(0, 1)[0];
   
            const commandName = args.splice(0, 1)[0];
if (commandName == "meetme") {
            if (commandName == "meetme") {
player.outputChatBox("Hello!");
                player.outputChatBox("Hello!");
};
            }
}
        }
);
    }
</syntaxhighlight>
</div>
 
==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]"
<div class="header" style="background-color: #AE4040; color: #FFFFFF; border: 2px solid #AE4040;">
<div style="margin: 10px 10px 10px 10px;"><b>Client-Side</b></div>
<syntaxhighlight lang="javascript">
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(`,`)}]`)
};
}
);
);
</syntaxhighlight>
</syntaxhighlight>

Revision as of 09:38, 26 September 2017

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]"

Client-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