Skip to main content
Branch: Release Candidate

WeaponObject

Hierarchy

  • LocalObject
    • WeaponObject

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

Properties

publicalpha

alpha: number

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

publicdimension

dimension: number

Object dimension.

Remarks

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

publicreadonlydynamic

dynamic: boolean

publicfrozen

frozen: boolean

publichasGravity

hasGravity: boolean

Whether the object is affected by gravity.

publicreadonlyid

id: number

publicreadonlyisCollisionEnabled

isCollisionEnabled: boolean

publicreadonlyisRemote

isRemote: boolean

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

publicreadonlyisSpawned

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.

publicreadonlyisStreamedIn

isStreamedIn: boolean

publicreadonlyisWeaponObject

isWeaponObject: boolean

publicreadonlyisWorldObject

isWorldObject: boolean

publiclodDistance

lodDistance: number

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

publicreadonlynetOwner

netOwner: null | Player

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.

publicpos

pos: Vector3

publicpositionFrozen

positionFrozen: boolean

Freeze the object on the position

publicreadonlyrefCount

refCount: number

Returns the ref count of the entity.

Remarks

It’s only available in debug-mode.

publicreadonlyremoteID

remoteID: number

The serverside id of this entity.

publicrot

rot: Vector3

publicreadonlyscriptID

scriptID: number

Internal game id that can be used in native calls

publicreadonlystreamingDistance

streamingDistance: number

publictextureVariation

textureVariation: number

publictintIndex

tintIndex: number

publicreadonlytype

type: BaseObjectType

Type of the object.

publicreadonlyuseStreaming

useStreaming: boolean

publicreadonlyvalid

valid: boolean

Object usability.

Returns

False if object is no longer usable.

publicvisible

visible: boolean

publicstaticreadonlyall

all: readonly WeaponObject[]

publicstaticreadonlyallWorld

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);

publicstaticreadonlycount

count: number

publicstaticreadonlystreamedIn

streamedIn: readonly Object[]

Accessors

publicmodel

  • get model(): number
  • set model(model: string | number): void

    Getter

    Setter

Methods

publicactivatePhysics

  • activatePhysics(): void

publicattachToEntity

  • 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.

publicdeleteMeta

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

publicdestroy

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

publicdetach

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

publicgetComponentTintIndex

  • getComponentTintIndex(componentId: number): number

publicgetMeta

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

    • K: string

publicgetMetaDataKeys

  • getMetaDataKeys(): readonly string[]

publicgetStreamSyncedMeta

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


    Type parameters

    • K: string

publicgetStreamSyncedMetaKeys

  • getStreamSyncedMetaKeys(): readonly string[]

publicgetSyncInfo

  • getSyncInfo(): ISyncInfo

publicgetSyncedMeta

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


    Type parameters

    • K: string

publicgetSyncedMetaKeys

  • getSyncedMetaKeys(): readonly string[]

publicgiveComponent

  • giveComponent(componentType: number): void

publichasMeta

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

publichasStreamSyncedMeta

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

publichasSyncedMeta

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

publicplaceOnGroundProperly

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

publicremoveComponent

  • removeComponent(componentType: number): void

publicresetAlpha

  • resetAlpha(): void

publicsetComponentTintIndex

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

publicsetMeta

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

    • K: string

publictoggleCollision

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

publicwaitForSpawn

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

publicstaticgetByID

  • getByID(id: number): null | LocalObject
  • Retrieves the ped from the pool.

publicstaticgetByRemoteID

  • getByRemoteID(id: number): null | Object
  • Gets the object with the given remote id

publicstaticgetByScriptID

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