Vehicle::destroy: Difference between revisions
No edit summary |
m (Fixed numerous "outputChatBox" typographical errors that would break the code example.) |
||
| Line 24: | Line 24: | ||
dimension, | dimension, | ||
}) | }) | ||
player. | player.outputChatBox(`You have successfully spawned a ${model} as id: ${vehicle.id}`); | ||
}) | }) | ||
| Line 36: | Line 36: | ||
const vehicle = mp.vehicles.at(vehicleid); | const vehicle = mp.vehicles.at(vehicleid); | ||
if (!vehicle || !mp.vehicles.exists(vehicle)) { | if (!vehicle || !mp.vehicles.exists(vehicle)) { | ||
return player. | return player.outputChatBox("We couldn't find any vehicle with that id."); | ||
} | } | ||
player. | player.outputChatBox(`You have successfully deleted vehicle id ${vehicleid}`); | ||
}) | }) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 11:04, 26 July 2024
Server-Side Function
JavaScript Syntax
This method will destroy (delete) a vehicle completely.
Syntax
vehicle.destroy()
Example
In this example we add two commands, one to spawn a vehicle and one to destroy them.
Server-Side
//Create a command that creates a vehicle.
mp.events.addCommand("vehicle", (player, fulltext, model) => {
if (!fulltext.length || !model.length) return player.outputChatBox("Usage: /vehicle [model]")
const { position, heading, dimension } = player;
const vehicle = mp.vehicles.new(mp.joaat(model), position, {
heading,
numberPlate: "CAR",
locked: false,
engine: false,
dimension,
})
player.outputChatBox(`You have successfully spawned a ${model} as id: ${vehicle.id}`);
})
//Create a command that destroys a vehicle by id.
mp.events.addCommand("destroyvehicle", (player, fulltext, vid) => {
if (!fulltext.length || !vid.length) return player.outputChatBox("Usage: /destroyvehicle [id]")
const vehicleid = parseInt(vid);
if (isNaN(vehicleid)) return player.outputChatBox("Usage: /destroyvehicle [id]");
const vehicle = mp.vehicles.at(vehicleid);
if (!vehicle || !mp.vehicles.exists(vehicle)) {
return player.outputChatBox("We couldn't find any vehicle with that id.");
}
player.outputChatBox(`You have successfully deleted vehicle id ${vehicleid}`);
})
See Also
- Functions
- Vehicle::Vehicle
- Vehicle::destroy
- Vehicle::explode
- Vehicle::getColor
- Vehicle::getColorRGB
- Vehicle::getExtra
- Vehicle::getMod
- Vehicle::getNeonColor
- Vehicle::getOccupant
- Vehicle::getOccupants
- Vehicle::getPaint
- Vehicle::isStreamed
- Vehicle::isStreamedFor
- Vehicle::repair
- Vehicle::setColor
- Vehicle::setColorRGB
- Vehicle::setExtra
- Vehicle::setMod
- Vehicle::setNeonColor
- Vehicle::setOccupant
- Vehicle::setPaint
- Vehicle::spawn
- Entity::destroy
- Entity::dist
- Entity::distSquared
- Entity::getVariable
- Entity::setVariable
- Entity::setVariables
- Properties
- Vehicle::bodyHealth
- Vehicle::brake
- Vehicle::dashboardColor
- Vehicle::dead
- Vehicle::engine
- Vehicle::engineHealth
- Vehicle::extras
- Vehicle::highbeams
- Vehicle::horn
- Vehicle::livery
- Vehicle::locked
- Vehicle::movable
- Vehicle::mods
- Vehicle::neonEnabled
- Vehicle::numberPlate
- Vehicle::numberPlateType
- Vehicle::pearlescentColor
- Vehicle::rocketBoost
- Vehicle::rotation
- Vehicle::siren
- Vehicle::steerAngle
- Vehicle::streamedPlayers
- Vehicle::taxiLights
- Vehicle::trailer
- Vehicle::traileredBy
- Vehicle::trimColor
- Vehicle::velocity
- Vehicle::windowTint
- Vehicle::wheelColor
- Vehicle::wheelType
- Entity::alpha
- Entity::data
- Entity::dimension
- Entity::id
- Entity::model
- Entity::position
- Entity::type