DoesEntityExist

From GT-MP
Jump to: navigation, search
DoesEntityExist
Shared Function
Utilities-terminal.png Server-Side System-users.png Client-Side
Csharp.png C# Javascript.png JavaScript

Checks if an entity exists, the function returns true if it does, otherwise it returns false.


Syntax

API.doesEntityExist(NetHandle entity);

Required Arguments

  • entity: parameter input should be in NetHandle type.


Dialog-warning.png

Note: This function returns data in bool type.

Usage example(s)

The command below checks if the player's vehicle entity exists, it's redundant seeing as every vehicle needs a entity to exists, but it's understandable as an example.

In C#
Server-Side Function

[Command("myvehicle")]
public void MyVehicle(Client playerid)
{
    if(API.hasEntitySyncedData(playerid, "VehicleID"))
    {
        NetHandle myvehicle = API.getEntitySyncedData(playerid, "VehicleID");
        if(!API.doesEntityExist(myvehicle)) 
        {
            API.sendChatMessageToPlayer(playerid, "Entity:", "Your car doesn't exist");
            return;
        }
        if(API.isPlayerInAnyVehicle(playerid))
        {    
            if(API.getPlayerVehicle(playerid) == myvehicle)
            {
                API.sendChatMessageToPlayer(playerid, "Entity:", "Your car exist, and you are in it.");
                return;
            }
        }
        if(API.doesEntityExist(myvehicle))
        {
            API.sendChatMessageToPlayer(playerid, "Entity:", "Your car exist, but i don't know where is it.");
        }
    }    
}

References