Entity::destroy: Difference between revisions

From RAGE Multiplayer Wiki
m (Adjusting some grammatical mistakes.)
No edit summary
 
Line 1: Line 1:
__TOC__
__TOC__
{{SharedFunctionJS}}
{{SharedFunctionJS}}
This function is used to destroy a created entity.
{{JSContainer|
{{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==
Line 13: Line 10:


==Example==
==Example==
This example creates a vehicle, and destroys after waiting 5 seconds.
Below you will find examples of this method being used in each entity
{{SharedCode|
{{SharedCode|
<pre>
 
mp.events.addCommand('veh', (player) => {
<syntaxhighlight lang="javascript">
    let vehicle = mp.vehicles.new(mp.joaat(`zentorno`), player.position); //Create a Vehicle
//Vehicle
    setTimeout(()=>{ //Create a Timer
const vehicle = mp.vehicles.at(0); //find vehicle with id 0.
        if(vehicle){
if (vehicle && mp.vehicles.exists(vehicle)) vehicle.destroy(); //destroy the vehicle if it exists and its valid.
            vehicle.destroy(); //Destroy the Vehicle
 
        }
 
    },5000);
//Ped (NPC)
});
const ped = mp.peds.at(0); //find ped with id 0.
</pre>
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.
 
</syntaxhighlight>
 
}}
}}
}}
}}

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.