Entity::destroy: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
No edit summary
 
(10 intermediate revisions by 6 users not shown)
Line 1: Line 1:
This function used for destroy created entities.
__TOC__
{{SharedFunctionJS}}
{{JSContainer|
'''This method is used to destroy a created entity, see [[Entity::type]] for a list of entities you can use this method to.'''


==Syntax==
==Syntax==
<syntaxhighlight lang="typescript">
<pre>
entity.destroy();
entity.destroy();
</syntaxhighlight>  
</pre>  


==Example==
==Example==
This example create vehicle, and destroy after few seconds.
Below you will find examples of this method being used in each entity
<syntaxhighlight lang="javascript" highlight="8">
{{SharedCode|
mp.events.addCommand(`veh`, (player) => {
 
let pos = player.position;
<syntaxhighlight lang="javascript">
let vehicleHash = mp.joaat(`zentorno`);
//Vehicle
let vehicle = mp.vehicles.new(vehicleHash, pos);
const vehicle = mp.vehicles.at(0); //find vehicle with id 0.
if (vehicle && mp.vehicles.exists(vehicle)) vehicle.destroy(); //destroy the vehicle if it exists and its valid.
 
 
//Ped (NPC)
const ped = mp.peds.at(0); //find ped with id 0.
if (ped && mp.peds.exists(ped)) ped.destroy(); //destroy the ped if it exists and its valid.
 
 
//Colshape
const colshape = mp.colshapes.at(0); //find colshape with id 0
if (colshape && mp.colshapes.exists(colshape)) colshape.destroy(); //destroy the colshape if it exists and its valid.
 
 
//Textlabel
const label = mp.labels.at(0); //find label with id 0
if (label && mp.labels.exists(label)) label.destroy(); //destroy the label if it exists and its valid.
 
 
//Object
const object = mp.objects.at(0); //find object with id 0
if (object && mp.objects.exists(object)) object.destroy(); //destroy the object if it exists and its valid.
 
//Blip
const blip = mp.blips.at(0); //find blip with id 0
if (blip && mp.blips.exists(blip)) blip.destroy(); //destroy the blip if it exists and its valid.
 
 
//Marker
const marker = mp.markers.at(0); //find marker with id 0
if (marker && mp.markers.exists(marker)) marker.destroy(); //destroy the marker if it exists and its valid.
 
 
//Checkpoint
const checkpoint = mp.checkpoints.at(0); //find marker with id 0
if (checkpoint && mp.checkpoints.exists(checkpoint)) checkpoint.destroy(); //destroy the marker if it exists and its valid.


let destroyVehicle = (vehicle) => {
if (vehicle) {
vehicle.destroy();
};
};
setTimeout(destroyVehicle, 5000, vehicle);
});
</syntaxhighlight>
</syntaxhighlight>
}}
}}
[[Category:Entity API]]
[[Category:Shared Function]]

Latest revision as of 13:42, 6 July 2024

Shared
Function

 JavaScript


JavaScript Syntax

This method is used to destroy a created entity, see Entity::type for a list of entities you can use this method to.

Syntax

entity.destroy();

Example

Below you will find examples of this method being used in each entity

Shared


//Vehicle
const vehicle = mp.vehicles.at(0); //find vehicle with id 0.
if (vehicle && mp.vehicles.exists(vehicle)) vehicle.destroy(); //destroy the vehicle if it exists and its valid.


//Ped (NPC)
const ped = mp.peds.at(0); //find ped with id 0.
if (ped && mp.peds.exists(ped)) ped.destroy(); //destroy the ped if it exists and its valid.


//Colshape
const colshape = mp.colshapes.at(0); //find colshape with id 0
if (colshape && mp.colshapes.exists(colshape)) colshape.destroy(); //destroy the colshape if it exists and its valid.


//Textlabel
const label = mp.labels.at(0); //find label with id 0
if (label && mp.labels.exists(label)) label.destroy(); //destroy the label if it exists and its valid.


//Object
const object = mp.objects.at(0); //find object with id 0
if (object && mp.objects.exists(object)) object.destroy(); //destroy the object if it exists and its valid.

//Blip
const blip = mp.blips.at(0); //find blip with id 0
if (blip && mp.blips.exists(blip)) blip.destroy(); //destroy the blip if it exists and its valid.


//Marker
const marker = mp.markers.at(0); //find marker with id 0
if (marker && mp.markers.exists(marker)) marker.destroy(); //destroy the marker if it exists and its valid.


//Checkpoint
const checkpoint = mp.checkpoints.at(0); //find marker with id 0
if (checkpoint && mp.checkpoints.exists(checkpoint)) checkpoint.destroy(); //destroy the marker if it exists and its valid.