fivem-ts

a library to speed up the development of Fivem scripts and frameworks


Project maintained by Purpose-Dev Hosted on GitHub Pages — Theme by mattgraham

fivem-ts - Documentation v0.7.5Docs


fivem-ts - Documentation v0.7.5 / Shared / DynamicProperty

Function: DynamicProperty()

DynamicProperty(propertyName): (target, propertyKey) => void

A decorator for dynamically binding a class property to a FiveM resource KVP (Key-Value Pair). This allows for automatic persistence of the property’s value and synchronization across the network.

Parameters

propertyName: string

The name of the KVP to associate with the decorated property.

Returns

Function

Parameters

target: unknown

propertyKey: string

Returns

void

Example

class PlayerSettings {
  // Bind the 'playerName' property to a KVP, automatically syncing changes across the network.
  @DynamicProperty('playerNameKvp')
  public playerName: string;
}

const settings = new PlayerSettings();
settings.playerName = 'NewName'; // Automatically sets the KVP and syncs across the network
console.log(settings.playerName); // Retrieves the current value from the KVP

Remarks

Defined in

shared/decorators/game/DynamicProperty.ts:26