Skip to content

Player Commands

dev2alert edited this page Feb 3, 2022 · 1 revision

Home ▸ Player commands

Before you start creating commands, you need to initialize their work:

Player.command.init();

Creating command:

Player.command("veh", "nnn", (player, model: number, color1: number, color2: number) => {
    const {x, y, z}: Position = player.pos;
    const rotation: number = player.angle;
    const vehicle: Vehicle = Vehicle.create({x, y, z, model, colors: [color1, color2], rotation});
    if(player.isInAnyVehicle())
        player.vehicle.destroy();
    player.put(vehicle);
});

Where veh is the command name, nnn are parameter types.
And the third argument is the command handler.

Types of parameters:

  • b - Boolean. 0 or 1.
  • i - Integer. Example: 89.
  • f - Float. Example: 1,23 or 1.23.
  • n - Any number. Example: 89, 1.23.
  • s - String. Example: Hello, world!
  • w - Word. Example: Hello.

Creating an alternative name for the command:

Player.command.alt("veh", "vehicle");

Where veh is the name of the command to create an alternative name for, and vehicle is the alternative name of the command.

Event if the command is entered incorrectly:

Player.on("command-invalid", (player) => {
    player.send("[Error]{FFFFFF} Command invalid.", 0xe04010AA);
    player.retval = 1;
});

Event if the command does not exist:

Player.on("command-not-found", (player, name) => {
    player.send(`[Error]{FFFFFF} Command {dbce12}${name}{FFFFFF} not found.`, 0xe04010AA);
    player.retval = 1;
});

Event if the typing of the command parameters does not match:

Player.on("command-params-mismatch", (player, cmdList) => {
    if(cmdList.desc) {
        player.send(cmdList.desc, 0xdbdbdbAA);
        player.send();
    }
    for(const cmd of cmdList)
        player.send(`{b3afaf}/${cmd.name} {dbce12}${cmd.params.map(({name, type}) => `<${name}: ${Player.command.paramTypeNames[type]}>`).join(" ")}`);
    player.retval = 1;
});

Specifying the description and names of the command parameters:

Player.command.desc("veh", "Create vehicle.");
Player.command("veh", [["n", "model"], ["n", "color1"], ["n", "color2"]], (player, model: number, color1: number, color2: number) => {
    /* <...> */
});

Overloading the command:

Player.command("health", "", (player) => {
    player.health = 100;
});
Player.command("health", [["n", "health"]], (player, health: number) => {
    player.health = health;
});
Clone this wiki locally