Vehicle::destroy: Difference between revisions
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
if (arr[0] == 'destroyrandomveh') { | if (arr[0] == 'destroyrandomveh') { | ||
let vehicles = mp.vehicles.toArray(); | let vehicles = mp.vehicles.toArray(); | ||
let randomValue = Math.floor(Math.random() * vehicles.length); | if (vehicles.length > 0) { | ||
let randomValue = Math.floor(Math.random() * vehicles.length); | |||
vehicles[randomValue].destroy(); | |||
} else { | |||
player.outputChatBox('Vehicles does not exist!'); | |||
} | |||
} | } | ||
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 13:41, 5 January 2017
mp.events.add('playerCommand', (player, cmd) => {
let arr = cmd.split(' ');
if (arr[0] == 'destroyrandomveh') {
let vehicles = mp.vehicles.toArray();
if (vehicles.length > 0) {
let randomValue = Math.floor(Math.random() * vehicles.length);
vehicles[randomValue].destroy();
} else {
player.outputChatBox('Vehicles does not exist!');
}
}
});