Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Entity

Hierarchy

Index

Constructors

Protected constructor

Properties

dimension

dimension: number

Object dimension.

remarks

Check https://docs.altv.mp/articles/dimensions.html to understand how it works.

frozen

frozen: boolean

Readonly id

id: number

Readonly isRemote

isRemote: boolean

Whether this entity was created clientside or serverside. (Clientside = false, Serverside = true).

Readonly isSpawned

isSpawned: boolean

Returns whether the entity is spawned in the game world.

remarks

This does the same thing as checking if the scriptID is 0.

Readonly netOwner

netOwner: Player | null

Network owner of the entity.

remarks

Network owner is responsible for syncing entity with the server. It changes when actual network owner passes the migration range, then the new one is determined based on distance from the entity (if entity is a vehicle, then the driver will take priority for becoming network owner). Disabling migration range will stop this process from happening until turned on again.

pos

pos: Vector3

Object position.

remarks

Setting this throws an error if the client is not the network owner of an entity

Readonly refCount

refCount: number

Returns the ref count of the entity.

remarks

It's only available in debug-mode.

Readonly remoteID

remoteID: number

The serverside id of this entity.

rot

rot: Vector3

Entity rotation in radians

remarks

Setting this throws an error if the client is not the network owner of an entity

Readonly scriptID

scriptID: number

Internal game id that can be used in native calls

Readonly type

Type of the object.

Readonly valid

valid: boolean

Object usability.

returns

False if object is no longer usable.

Readonly visible

visible: boolean

Static Readonly all

all: readonly Entity[]

Array with all entities.

remarks

This creates a clone of the array everytime it is called. It is advised to call this once and store the result in a variable, before iterating over it.

example
const entities = alt.Entity.all; // Store it in a variable, so it doesn't create a copy of the array on each iteration
for(let i = 0; i < entities.length; i++)
{
  alt.log(`${entities[i].id}`); // Logs the id of every entity
}

Accessors

model

  • get model(): number
  • Hash of entity model

    Returns number

Methods

deleteMeta

  • deleteMeta(key: string): void
  • deleteMeta<K>(key: K): void

destroy

  • destroy(): void
  • Removes the object from the world.

    Returns void

getMeta

  • getMeta<K>(key: Exclude<K, keyof ICustomEntityMeta>): unknown
  • getMeta<K>(key: K): ICustomEntityMeta[K] | undefined
  • getMeta<V>(key: string): V | undefined
  • Type parameters

    • K: string

    Parameters

    Returns unknown

  • Type parameters

    Parameters

    • key: K

    Returns ICustomEntityMeta[K] | undefined

  • deprecated

    See ICustomEntityMeta

    Type parameters

    • V: any

    Parameters

    • key: string

    Returns V | undefined

getMetaDataKeys

  • getMetaDataKeys(): readonly string[]

getStreamSyncedMeta

  • getStreamSyncedMeta<K>(key: Exclude<K, keyof ICustomEntityStreamSyncedMeta>): unknown
  • getStreamSyncedMeta<K>(key: K): ICustomEntityStreamSyncedMeta[K] | undefined
  • getStreamSyncedMeta<V>(key: string): V | undefined
  • Gets a value using the specified key.

    Type parameters

    • K: string

    Parameters

    Returns unknown

    Dynamic value associated with the specified key or undefined if no data is present.

  • Type parameters

    Parameters

    • key: K

    Returns ICustomEntityStreamSyncedMeta[K] | undefined

  • Type parameters

    • V: any

    Parameters

    • key: string

    Returns V | undefined

getStreamSyncedMetaKeys

  • getStreamSyncedMetaKeys(): readonly string[]
  • Returns readonly string[]

getSyncInfo

  • Returns ISyncInfo

getSyncedMeta

  • getSyncedMeta<K>(key: Exclude<K, keyof ICustomEntitySyncedMeta>): unknown
  • getSyncedMeta<K>(key: K): ICustomEntitySyncedMeta[K] | undefined
  • getSyncedMeta<V>(key: string): V | undefined

getSyncedMetaKeys

  • getSyncedMetaKeys(): readonly string[]

hasMeta

  • hasMeta(key: string): boolean
  • hasMeta<K>(key: K): boolean
  • Parameters

    • key: string

    Returns boolean

  • Type parameters

    Parameters

    • key: K

    Returns boolean

hasStreamSyncedMeta

  • hasStreamSyncedMeta(key: string): boolean
  • hasStreamSyncedMeta<K>(key: K): boolean
  • Determines whether contains the specified key.

    Parameters

    • key: string

      The key of the value to locate.

    Returns boolean

    True if the meta table contains any data at the specified key or False if not

  • Type parameters

    Parameters

    • key: K

    Returns boolean

hasSyncedMeta

  • hasSyncedMeta(key: string): boolean
  • hasSyncedMeta<K>(key: K): boolean
  • Determines whether contains the specified key.

    Parameters

    • key: string

      The key of the value to locate.

    Returns boolean

    True if the meta table contains any data at the specified key or False if not

  • Type parameters

    Parameters

    • key: K

    Returns boolean

setMeta

  • setMeta<K>(key: K, value: shared.InterfaceValueByKey<ICustomEntityMeta, K>): void
  • setMeta<K>(key: K, value: ICustomEntityMeta[K]): void
  • setMeta<V, K>(key: K, value: shared.InterfaceValueByKey<ICustomEntityMeta, K, V>): void
  • Type parameters

    • K: string

    Parameters

    Returns void

  • Type parameters

    Parameters

    • key: K
    • value: ICustomEntityMeta[K]

    Returns void

  • deprecated

    See ICustomEntityMeta

    Type parameters

    • V: any

    • K: string = string

    Parameters

    Returns void

Static getByID

Static getByRemoteID

Static getByScriptID

  • getByScriptID(scriptID: number): Entity | null
  • Retrieves the entity from the pool.

    Parameters

    • scriptID: number

      The script id of the entity.

    Returns Entity | null

    Entity if it was found, otherwise null.