Events::addCommand: Difference between revisions
CocaColaBear (talk | contribs) No edit summary |
CocaColaBear (talk | contribs) No edit summary |
||
| Line 31: | Line 31: | ||
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | |||
{{Player_function}} | |||
Revision as of 12:29, 17 April 2017
This function registers command handler.
Syntax
void events.addCommand(string commandName, function handlerFunction);
Required Arguments
- commandName: The name of the command you wish to attach a handler to
- handlerFunction: The function that you want the command to trigger, which has to be defined before you add the handler
Handler function parameters
Player playerSource, string fullText [, string arg1, string arg2, ...]
- playerSource: The player who triggered the command.
- fullText: All words after command name.
- arg1, arg2, ...: Each word after command name.
Example
Example 1: This example give weapon to current player with the specified number of ammo or 10000
mp.events.addCommand("weapon", (player, fullText, weapon, ammo) => {
var weaponHash = mp.joaat(weapon);
player.giveWeapon(weaponHash, parseInt(ammo) || 10000);
});
Example 2: This example implements /me command
mp.events.addCommand("me", (player, message) => {
mp.players.broadcast(`* ${player.name}: ${message}`);
});
See Also
- Functions
- Player::kick
- Player::ban
- Player::spawn
- Player::giveWeapon
- Player::outputChatBox
- Player::getClothes
- Player::setClothes
- Player::getProp
- Player::setProp
- Player::putIntoVehicle
- Player::removeFromVehicle
- Player::invoke
- Player::call
- Player::notify
- Player::getHeadBlend
- Player::setHeadBlend
- Player::updateHeadBlend
- Player::setFaceFeature
- Player::getFaceFeature
- Player::setHairColour
- Player.setOwnVariable
- Player.getOwnVariable
- Player.setOwnVariables
- Properties
- Entity::id
- Entity::dimension
- Entity::type
- Player::action
- Player::name
- Player::model
- Player::alpha
- Player::position
- Player::heading
- Player::health
- Player::armour
- Player::isJumping
- Player::isInCover
- Player::isClimbing
- Player::isEnteringVehicle
- Player::isLeavingVehicle
- Player::vehicle
- Player::seat
- Player::weapon
- Player::isAiming
- Player::aimTarget
- Player::ping
- Player::ip
- Player::eyeColour
- Player::hairColour
- Player::hairHighlightColour