Vehicle::destroy: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
This | |||
{{ServersideJsFunction}} | |||
{{JSContainer| | |||
This method will destroy (delete) a vehicle completely. | |||
== Syntax == | == Syntax == | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
vehicle.destroy() | vehicle.destroy() | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Example == | == Example == | ||
In this example we add two commands, one to spawn a vehicle and one to destroy them. | |||
{{ServersideCode| | |||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
mp.events. | //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.ouptuChatBox(`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.ouptuChatBox("We couldn't find any vehicle with that id."); | |||
} | } | ||
}); | player.ouptuChatBox(`You have successfully deleted vehicle id ${vehicleid}`); | ||
}) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | |||
}} | |||
==See Also== | |||
{{Vehicle_definition}} | |||
Revision as of 13:13, 6 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.ouptuChatBox(`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.ouptuChatBox("We couldn't find any vehicle with that id.");
}
player.ouptuChatBox(`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