Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LocalObject

Hierarchy

Index

Constructors

constructor

  • new LocalObject(model: string | number, pos: Vector3, rot: Vector3, noOffset?: boolean, dynamic?: boolean, useStreaming?: boolean, streamingDistance?: number): LocalObject
  • Creates a new object.

    remarks

    The model for the object is automatically loaded, but because this happens asynchronously, the scriptID property might not be immediately available after creating the object. Setters will always work regardless of whether the model is already loaded or not.

    Parameters

    • model: string | number

      Model name or model hash for the object.

    • pos: Vector3

      Position of the object.

    • rot: Vector3

      Rotation of the object.

    • Optional noOffset: boolean

      If true, object position will not be adjusted to not collide with anything.

    • Optional dynamic: boolean

      If true, object reacts to actions in the world. (E.g. force by vehicle)

    • Optional useStreaming: boolean
    • Optional streamingDistance: number

    Returns LocalObject

Properties

alpha

alpha: number

Object transparency, values are between 0 and 255. (0 being fully transparent)

dimension

dimension: number

Object dimension.

remarks

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

Readonly dynamic

dynamic: boolean

frozen

frozen: boolean

hasGravity

hasGravity: boolean

Whether the object is affected by gravity.

Readonly id

id: number

Readonly isCollisionEnabled

isCollisionEnabled: boolean

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 isStreamedIn

isStreamedIn: boolean

Readonly isWorldObject

isWorldObject: boolean

lodDistance

lodDistance: number

The distance at which the LOD model of the object starts being applied.

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

positionFrozen

positionFrozen: boolean

Freeze the object on the position

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

Readonly scriptID

scriptID: number

Internal game id that can be used in native calls

Readonly streamingDistance

streamingDistance: number

textureVariation

textureVariation: number

Readonly type

Type of the object.

Readonly useStreaming

useStreaming: boolean

Readonly valid

valid: boolean

Object usability.

returns

False if object is no longer usable.

visible

visible: boolean

Static Readonly all

all: readonly LocalObject[]

Static Readonly allWorld

allWorld: readonly LocalObject[]

All objects created by the game. For example, a weapon item in the player's hand or a bag of rubbish in the street.

example
const object = alt.LocalObject.allWorld[0];
alt.Utils.assert(object != null);

// Wait for the object to be deleted by the game.
await alt.Utils.waitFor(() => !object.valid);

Static Readonly count

count: number

Static Readonly streamedIn

streamedIn: readonly Object[]

Accessors

model

  • get model(): number
  • set model(model: number | string): any
  • Returns number

  • Parameters

    • model: number | string

    Returns any

Methods

activatePhysics

  • activatePhysics(): void
  • Returns void

attachToEntity

  • attachToEntity(entity: Entity, boneIndex: number, offset: Vector3, rot: Vector3, useSoftPinning?: boolean, collision?: boolean, fixedRot?: boolean): void
  • attachToEntity(scriptID: number, boneIndex: number, offset: Vector3, rot: Vector3, useSoftPinning?: boolean, collision?: boolean, fixedRot?: boolean): void
  • Attaches the object to another entity.

    Parameters

    • entity: Entity

      Entity or scriptID of the entity the object should be attached to.

    • boneIndex: number

      Bone index of the entity to attach to. (-1 for entity center).

    • offset: Vector3

      Offset of the object.

    • rot: Vector3

      Rotation of the object in radians.

    • Optional useSoftPinning: boolean

      Whether the object should be able to detach when not fixed.

    • Optional collision: boolean

      Whether the object and the entity should collide with each other.

    • Optional fixedRot: boolean

      Whether the rotation of the object is fixed or follows that of the entity.

    Returns void

  • Parameters

    • scriptID: number
    • boneIndex: number
    • offset: Vector3
    • rot: Vector3
    • Optional useSoftPinning: boolean
    • Optional collision: boolean
    • Optional fixedRot: boolean

    Returns void

deleteMeta

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

destroy

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

    Returns void

detach

  • detach(dynamic?: boolean): void
  • Detaches the object from the current attached entity.

    Parameters

    • Optional dynamic: boolean

      Set to true to keep velocity after dettaching. Default value is false.

    Returns void

getMeta

  • getMeta<K>(key: Exclude<K, keyof ICustomEntityMeta>): unknown
  • getMeta<K>(key: K): ICustomEntityMeta[K] | undefined
  • getMeta<V>(key: string): 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

getStreamSyncedMetaKeys

  • getStreamSyncedMetaKeys(): readonly string[]

getSyncInfo

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

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

placeOnGroundProperly

  • placeOnGroundProperly(): void
  • Places the object properly on the ground.

    Returns void

resetAlpha

  • resetAlpha(): void
  • Returns void

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

toggleCollision

  • toggleCollision(toggle: boolean, keepPhysics: boolean): void
  • Parameters

    • toggle: boolean
    • keepPhysics: boolean

    Returns void

waitForSpawn

  • waitForSpawn(timeout?: number): Promise<void>
  • Waits asynchronously until the object spawns.

    Parameters

    • Optional timeout: number

    Returns Promise<void>

Static getByID

  • Retrieves the ped from the pool.

    Parameters

    • id: number

      The id of the ped.

    Returns LocalObject | null

    Entity if it was found, otherwise null.

Static getByRemoteID

  • getByRemoteID(id: number): Object | null

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.