Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WeaponObject

Hierarchy

Index

Constructors

constructor

  • new WeaponObject(weaponHash: string | number, pos: Vector3, rot: Vector3, modelHash?: string | number, numAmmo?: number, createDefaultComponents?: boolean, scale?: number, useStreaming?: boolean, streamingDistance?: number): WeaponObject
  • Parameters

    • weaponHash: string | number
    • pos: Vector3
    • rot: Vector3
    • Optional modelHash: string | number
    • Optional numAmmo: number
    • Optional createDefaultComponents: boolean
    • Optional scale: number
    • Optional useStreaming: boolean
    • Optional streamingDistance: number

    Returns WeaponObject

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 isWeaponObject

isWeaponObject: 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

tintIndex

tintIndex: 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 WeaponObject[]

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

Methods

activatePhysics

  • activatePhysics(): 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

getComponentTintIndex

  • getComponentTintIndex(componentId: number): number
  • Parameters

    • componentId: number

    Returns number

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[]

giveComponent

  • giveComponent(componentType: number): void
  • Parameters

    • componentType: number

    Returns void

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

removeComponent

  • removeComponent(componentType: number): void
  • Parameters

    • componentType: number

    Returns void

resetAlpha

  • resetAlpha(): void

setComponentTintIndex

  • setComponentTintIndex(componentId: number, tintIndex: number): void
  • Parameters

    • componentId: number
    • tintIndex: number

    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.