PlayerCommand: Difference between revisions
No edit summary |
m (Adds detection for unknown commands) |
||
| Line 35: | Line 35: | ||
mp.gui.chat.push(`You enter command a "${commandName}", and all arguments it a [${args.join(",")}]`); | mp.gui.chat.push(`You enter command a "${commandName}", and all arguments it a [${args.join(",")}]`); | ||
} | } | ||
}); | |||
</pre> | |||
'''Detecting invalid commands: | |||
<pre> | |||
mp.events.add('playerCommand', (player, command) => { | |||
player.outputChatBox(`${command} is not a valid command. Use /help to find a list of commands.`); | |||
}); | }); | ||
</pre> | </pre> | ||
| Line 65: | Line 72: | ||
} | } | ||
} | } | ||
}} | }} | ||
==See also== | ==See also== | ||
{{Player_events}} | {{Player_events}} | ||
Revision as of 03:10, 9 February 2019
This event is triggered when a player sends a command.
Server-Side Event
JavaScript Syntax
Parameters
- player - player, who send command.
- command - string with arguments.
Example
This example will write "Hello!" to player, who will enter command /meetme into chatbox.s
mp.events.add("playerCommand", (player, command) => {
const args = command.split(/[ ]+/);
const commandName = args.splice(0, 1)[0];
if (commandName === "meetme") {
player.outputChatBox("Hello!");
}
});
Example
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]"
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(",")}]`);
}
});
Detecting invalid commands:
mp.events.add('playerCommand', (player, command) => {
player.outputChatBox(`${command} is not a valid command. Use /help to find a list of commands.`);
});
Client-Side Event
C# Syntax
{{{1}}}
See also
Checkpoint
Colshape
Entity
Player
- playerChat
- playerCommand
- playerDamage
- playerDeath
- playerJoin
- playerQuit
- playerReady
- playerSpawn
- playerWeaponChange
Streaming
Vehicle
- playerStartEnterVehicle
- playerEnterVehicle
- playerStartExitVehicle
- playerExitVehicle
- trailerAttached
- vehicleDamage
- vehicleDeath
- vehicleHornToggle
- vehicleSirenToggle