Vehicle::destroy

From RAGE Multiplayer Wiki
Revision as of 13:13, 6 July 2024 by Shr0x (talk | contribs)

Server-Side
Function

 JavaScript



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