Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "alt-shared"

module

alt-shared

Index

Variables

Const branch

branch: string

Represents the current branch.

Const debug

debug: boolean

Returns if the resource is in debug mode.

returns

True when the resource is launched with debug mode enabled.

Const defaultDimension

defaultDimension: number

Default dimension (0). Read more: https://docs.altv.mp/articles/dimensions.html

Const globalDimension

globalDimension: number

Global dimension (-2147483648). Read more: https://docs.altv.mp/articles/dimensions.html

Const isClient

isClient: boolean

A boolean indicating whether the current script is executed on the clientside.

Const isServer

isServer: boolean

A boolean indicating whether the current script is executed on the serverside.

Const resourceName

resourceName: string

Resource name of the executing resource.

Const sdkVersion

sdkVersion: string

Represents the current SDK version.

remarks

It's the version of the SDK the current runtime was compiled with.

Const version

version: string

Represents the current version.

remarks

It's a slighty modified semantic versioning specification, which can be matched using this regular expression pattern ^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))$.

Functions

clearEveryTick

  • clearEveryTick(id: number): void
  • Clears a timer set with the everyTick function.

    Parameters

    • id: number

      The id of a timer.

    Returns void

clearInterval

  • clearInterval(id: number): void
  • Clears a timer set with the setInterval function.

    Parameters

    • id: number

      The id of a timer.

    Returns void

clearNextTick

  • clearNextTick(id: number): void
  • Clears a timer set with the nextTick function.

    Parameters

    • id: number

      The id of a timer.

    Returns void

clearTimeout

  • clearTimeout(id: number): void
  • Clears a timer set with the setTimeout function.

    Parameters

    • id: number

      The id of a timer.

    Returns void

deleteMeta

  • deleteMeta(key: string): void
  • deleteMeta<K>(key: K): void
  • Removes the specified key and the data connected to that specific key.

    Parameters

    • key: string

      The key of the value to remove.

    Returns void

  • Type parameters

    Parameters

    • key: K

    Returns void

emit

  • emit(eventName: string, ...args: any[]): void
  • Emits specified event across resources.

    Parameters

    • eventName: string

      Name of the event.

    • Rest ...args: any[]

      Rest parameters for emit to send.

    Returns void

emitRaw

  • emitRaw(eventName: string, ...args: any[]): void
  • Emits specified event across resources.

    remarks

    Works only from JS resource to JS resource

    Parameters

    • eventName: string

      Name of the event.

    • Rest ...args: any[]

      Rest parameters for emit to send.

    Returns void

everyTick

  • everyTick(handler: (...args: any[]) => void): number
  • Schedules execution of handler on every tick/every frame.

    Parameters

    • handler: (...args: any[]) => void

      Handler that should be scheduled for execution.

        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns number

    A number representing the id value of the timer that is set. Use this value with the clearEveryTick function to cancel the timer.

getAllResources

  • Returns readonly IResource[]

getEventListeners

  • getEventListeners(eventName: string | null): readonly ((...args: any[]) => void)[]
  • Gets all the listeners for the specified local event.

    Parameters

    • eventName: string | null

      Name of the event or null for generic event.

    Returns readonly ((...args: any[]) => void)[]

    Array of listener functions for that event.

getMeta

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

  • deprecated

    See ICustomGlobalMeta

    Type parameters

    • V: any

    Parameters

    • key: string

    Returns V | undefined

getMetaKeys

  • getMetaKeys(): readonly string[]
  • Returns all meta keys which have been set

    Returns readonly string[]

getNetTime

  • getNetTime(): number
  • Gets the amount of milliseconds since the server was started.

    Returns number

getSyncedMeta

  • getSyncedMeta<K>(key: Exclude<K, keyof ICustomGlobalSyncedMeta>): unknown
  • getSyncedMeta<K>(key: K): ICustomGlobalSyncedMeta[K] | undefined
  • getSyncedMeta<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 ICustomGlobalSyncedMeta[K] | undefined

  • deprecated

    See ICustomGlobalSyncedMeta

    Type parameters

    • V: any

    Parameters

    • key: string

    Returns V | undefined

getSyncedMetaKeys

  • getSyncedMetaKeys(): readonly string[]
  • Returns all synced meta keys which have been set

    Returns readonly string[]

getVoiceConnectionState

hasMeta

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

    Parameters

    • key: string

      The key of the value to locate.

    Returns boolean

    True when element associated with the specified key is stored.

  • Type parameters

    Parameters

    • key: K

    Returns boolean

hasResource

  • hasResource(name: string): boolean
  • Returns whether the specified resource exists.

    Parameters

    • name: string

      Name of the resource.

    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

hash

  • hash(str: string): number
  • Creates a hash using Jenkins one-at-a-time algorithm.

    Parameters

    • str: string

      A string from which hash will be created.

    Returns number

log

  • log(arg: any, ...args: any[]): void
  • Logs the specified arguments to the console.

    remarks

    Uses alt.Utils.inspect to format values.

    Parameters

    • arg: any
    • Rest ...args: any[]

    Returns void

logDebug

  • logDebug(arg: any, ...args: any[]): void
  • Logs the specified arguments to the console if debug is enabled.

    remarks

    Uses alt.Utils.inspect to format values.

    Parameters

    • arg: any
    • Rest ...args: any[]

    Returns void

logError

  • logError(arg: any, ...args: any[]): void
  • Logs the specified arguments as an error to the console.

    remarks

    Uses alt.Utils.inspect to format values.

    Parameters

    • arg: any
    • Rest ...args: any[]

    Returns void

logWarning

  • logWarning(arg: any, ...args: any[]): void
  • Logs the specified arguments as a warning to the console.

    remarks

    Uses alt.Utils.inspect to format values.

    Parameters

    • arg: any
    • Rest ...args: any[]

    Returns void

nextTick

  • nextTick(handler: (...args: any[]) => void): number
  • Schedules execution of handler on next tick/next frame.

    Parameters

    • handler: (...args: any[]) => void

      Handler that should be scheduled for execution.

        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns number

    A number representing the id value of the timer that is set. Use this value with the clearNextTick function to cancel the timer.

off

  • off(eventName: string, listener: (...args: any[]) => void): void
  • off(listener: (eventName: string, ...args: any[]) => void): void
  • Unsubscribes from a event with the specified listener.

    remarks

    Listener should be of the same reference as when event was subscribed to.

    Parameters

    • eventName: string

      Name of the event.

    • listener: (...args: any[]) => void

      Listener that should be removed.

        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns void

  • Unsubscribes from all user-created events with the specified listener.

    remarks

    Listener should be of the same reference as when event was subscribed to.

    Parameters

    • listener: (eventName: string, ...args: any[]) => void

      Listener that should be removed.

        • (eventName: string, ...args: any[]): void
        • Parameters

          • eventName: string
          • Rest ...args: any[]

          Returns void

    Returns void

on

  • on(eventName: string, listener: (...args: any[]) => void): void
  • on(listener: (eventName: string, ...args: any[]) => void): void
  • Subscribes to a custom local event with the specified listener.

    Parameters

    • eventName: string

      Name of the event.

    • listener: (...args: any[]) => void

      Listener that should be added.

        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns void

  • Subscribes to all events with the specified listener.

    remarks

    Listener will be only called for user-created events.

    Parameters

    • listener: (eventName: string, ...args: any[]) => void

      Listener that should be added.

        • (eventName: string, ...args: any[]): void
        • Parameters

          • eventName: string
          • Rest ...args: any[]

          Returns void

    Returns void

once

  • once(eventName: string, listener: (...args: any[]) => void): void
  • once(listener: (eventName: string, ...args: any[]) => void): void
  • Subscribes to a custom local event with the specified listener, which only triggers once.

    Parameters

    • eventName: string

      Name of the event.

    • listener: (...args: any[]) => void

      Listener that should be added.

        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns void

  • Subscribes to all events with the specified listener, which only triggers once.

    remarks

    Listener will be only called for user-created events.

    Parameters

    • listener: (eventName: string, ...args: any[]) => void

      Listener that should be added.

        • (eventName: string, ...args: any[]): void
        • Parameters

          • eventName: string
          • Rest ...args: any[]

          Returns void

    Returns void

setInterval

  • setInterval(handler: (...args: any[]) => void, miliseconds: number): number
  • Schedules execution of handler in specified intervals.

    Parameters

    • handler: (...args: any[]) => void

      Handler that should be scheduled for execution.

        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    • miliseconds: number

      The time, in milliseconds, between execution of specified handler.

    Returns number

    A number representing the id value of the timer that is set. Use this value with the clearInterval function to cancel the timer.

setMeta

  • setMeta<K>(key: K, value: InterfaceValueByKey<ICustomGlobalMeta, K>): void
  • setMeta<K>(key: K, value: ICustomGlobalMeta[K]): void
  • setMeta<V, K>(key: K, value: InterfaceValueByKey<ICustomGlobalMeta, K, V>): void
  • Stores the given value with the specified key.

    remarks

    The given value will be shared locally to all resources.

    Type parameters

    • K: string

    Parameters

    • key: K

      The key of the value to store.

    • value: InterfaceValueByKey<ICustomGlobalMeta, K>

      The value to store.

    Returns void

  • Type parameters

    Parameters

    • key: K
    • value: ICustomGlobalMeta[K]

    Returns void

  • deprecated

    See ICustomGlobalMeta

    Type parameters

    • V: any

    • K: string = string

    Parameters

    Returns void

setTimeout

  • setTimeout(handler: (...args: any[]) => void, miliseconds: number): number
  • Schedules execution of handler once after the expiration of interval.

    Parameters

    • handler: (...args: any[]) => void

      Handler that should be scheduled for execution.

        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    • miliseconds: number

      The time, in milliseconds, before execution of specified handler.

    Returns number

    A number representing the id value of the timer that is set. Use this value with the clearTimeout function to cancel the timer.

stringToSHA256

  • stringToSHA256(string: string): string
  • Parameters

    • string: string

    Returns string

time

  • time(timerName: string): void
  • time(): void
  • Parameters

    • timerName: string

    Returns void

  • Returns void

timeEnd

  • timeEnd(timerName: string): void
  • timeEnd(): void
  • Parameters

    • timerName: string

    Returns void

  • Returns void