Vehicle::destroy: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
m (Fixed numerous "outputChatBox" typographical errors that would break the code example.)
 
Line 24: Line 24:
dimension,
dimension,
     })
     })
player.ouptuChatBox(`You have successfully spawned a ${model} as id: ${vehicle.id}`);
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.ouptuChatBox("We couldn't find any vehicle with that id.");
return player.outputChatBox("We couldn't find any vehicle with that id.");
}
}
player.ouptuChatBox(`You have successfully deleted vehicle id ${vehicleid}`);
player.outputChatBox(`You have successfully deleted vehicle id ${vehicleid}`);
})
})
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 11:04, 26 July 2024

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.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