PlayerCommand: Difference between revisions

From RAGE Multiplayer Wiki
(Created page with " This event is triggered when player send command . ==Parameters== * '''player - player, who send command.''' * '''command - string with arguments.''' ==Example== <div cla...")
 
No edit summary
Line 10: Line 10:
<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">
class CommandHandler {
    cunstrunctor() {
        this.commands = new Map();
    }
   
    add(commandName, commandFunction) {
        this.commands.set(commandName, commandFunction);
        return true;
    }
   
    execute(player, commandName, args, fulltext) {
        if(!this.commands.has(commandName))
            return false;
       
        const commandFunction = this.commands.get(commandName);
       
        commandFunction(player, args, fulltext);
        return true;
    }
}
const commandHandler = new CommandHandler();
commandHandler.add('test', (player, args) => {
    player.outputChatBox(`your name - ${player.name}`);
});
mp.events.add(
mp.events.add(
     {
     {
Line 43: Line 16:
      
      
             const commandName = args.splice(0, 1)[0];
             const commandName = args.splice(0, 1)[0];
             if (!commandHandler.execute(player, commandName, args, args.join(' '))) {
             if (commandName == "meetme") {
                 player.outputChatBox("Unknown command.");
                 player.outputChatBox("Hello!");
             }
             }
         }
         }

Revision as of 21:13, 20 September 2017

This event is triggered when player send command .

Parameters

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

Example

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

See also

Checkpoint

Colshape

Entity

Player

Streaming

Vehicle

Waypoint