Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Player

Hierarchy

Index

Constructors

Protected constructor

Properties

Readonly aimPos

aimPos: Vector3

Position the player is currently aiming at.

Readonly armour

armour: number

Current armour.

Readonly currentWeapon

currentWeapon: number

Currently equipped weapon.

Readonly currentWeaponComponents

currentWeaponComponents: readonly number[]

Current weapon components.

Readonly currentWeaponTintIndex

currentWeaponTintIndex: number

Tint index for currently equipped weapon.

dimension

dimension: number

Object dimension.

remarks

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

Readonly entityAimOffset

entityAimOffset: Vector3

The current aim offset of the player.

Readonly entityAimingAt

entityAimingAt: Entity | null

The entity the player is aiming at.

filter

filter: AudioFilter | null

Readonly flashlightActive

flashlightActive: boolean

Is the flashlight of the player activated.

Readonly forwardSpeed

forwardSpeed: number

Forward speed of the player.

frozen

frozen: boolean

Readonly headRot

headRot: Vector3

Rotation of the head of the player.

Readonly health

health: number

Current health of the player.

Readonly id

id: number

Readonly isAiming

isAiming: boolean

Is the player currently aiming.

remarks

Returns true ONLY if:

  • you are in first person with a gun equipped and you are not sprinting
  • you are in third person and aiming/shooting

Readonly isCrouching

isCrouching: boolean

Is the player currently crouching.

Readonly isDead

isDead: boolean

Readonly isEnteringVehicle

isEnteringVehicle: boolean

Readonly isInCover

isInCover: boolean

Readonly isInMelee

isInMelee: boolean

Readonly isInRagdoll

isInRagdoll: boolean

Is the player currently in ragdoll.

Readonly isLeavingVehicle

isLeavingVehicle: boolean

Readonly isOnLadder

isOnLadder: boolean

Readonly isParachuting

isParachuting: boolean

Readonly isReloading

isReloading: boolean

Is the player currently reloading their weapon.

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 isStealthy

isStealthy: boolean

Is the player currently stealthy.

Readonly isTalking

isTalking: boolean

Player talking state

Readonly maxArmour

maxArmour: number

Max available armour value.

Readonly maxHealth

maxHealth: number

Current max health of the player.

Readonly micLevel

micLevel: number

Player talking volume

Readonly moveSpeed

moveSpeed: number

Current player movement speed.

Readonly name

name: string

Player name

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.

nonSpatialVolume

nonSpatialVolume: number

Set & get the volume for 2D Voice.

remarks

Value needs to be between 0-1.

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 seat

seat: number

Curent seat the player is sitting in. If player is not in any vehicle it is equal to 0.

remarks

The seat indexes start with 1 (driver seat).

spatialVolume

spatialVolume: number

Set & get the volume for 3D Voice.

remarks

Value needs to be between 0-1.

Readonly strafeSpeed

strafeSpeed: number

Strafe speed of the player.

Readonly taskData

taskData: string

Readonly type

Type of the object.

Readonly valid

valid: boolean

Object usability.

returns

False if object is no longer usable.

Readonly vehicle

vehicle: Vehicle | LocalVehicle | null

Player's vehicle, null if player is not in any vehicle

Readonly visible

visible: boolean

Static Readonly all

all: readonly Player[]

Array with all players.

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 players = alt.Player.all; // Store it in a variable, so it doesn't create a copy of the array on each iteration
for(let i = 0; i < players.length; i++)
{
  alt.log(`${players[i].name}`); // Logs the name of every player
}

Static Readonly count

count: number

Static Readonly local

The local player instance.

Static Readonly streamedIn

streamedIn: readonly Player[]

Array with all streamed in players.

Accessors

model

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

    Returns number

Methods

deleteMeta

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

    • key: string

    Returns void

  • Type parameters

    Parameters

    • key: K

    Returns void

destroy

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

    Returns void

getMeta

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

    • K: string

    Parameters

    Returns unknown

  • Type parameters

    Parameters

    • key: K

    Returns ICustomPlayerMeta[K] | undefined

  • deprecated

    See ICustomPlayerMeta

    Type parameters

    • V: any

    Parameters

    • key: string

    Returns V | undefined

getMetaDataKeys

  • getMetaDataKeys(): readonly string[]

getStreamSyncedMeta

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

getStreamSyncedMetaKeys

  • getStreamSyncedMetaKeys(): readonly string[]

getSyncInfo

getSyncedMeta

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

getSyncedMetaKeys

  • getSyncedMetaKeys(): readonly string[]

getWeaponTintIndex

  • getWeaponTintIndex(weaponModel: string | number): number
  • Parameters

    • weaponModel: string | number

    Returns number

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

hasSyncedMeta

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

hasWeaponComponent

  • hasWeaponComponent(weaponModel: string | number, component: string | number): boolean
  • Parameters

    • weaponModel: string | number
    • component: string | number

    Returns boolean

setMeta

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

    • K: string

    Parameters

    Returns void

  • Type parameters

    Parameters

    • key: K
    • value: ICustomPlayerMeta[K]

    Returns void

  • deprecated

    See ICustomPlayerMeta

    Type parameters

    • V: any

    • K: string = string

    Parameters

    Returns void

Static getByID

  • getByID(id: number): Player | null
  • Retrieves the player from the pool.

    Parameters

    • id: number

      The id of the player.

    Returns Player | null

    Entity if it was found, otherwise null.

Static getByRemoteID

  • getByRemoteID(id: number): Player | null
  • Gets the player with the given remote id

    Parameters

    • id: number

    Returns Player | null

Static getByScriptID

  • getByScriptID(scriptID: number): Player | null
  • Retrieves the player from the pool.

    Parameters

    • scriptID: number

      The script id of the player.

    Returns Player | null

    Entity if it was found, otherwise null.