Skip to content
On this page

Athena.document.character

Type Aliases

KeyChangeCallback

Ƭ KeyChangeCallback: (player: alt.Player, newValue: any, oldValue: any) => void

Type declaration

Usage

Athena.document.character.(player, newValue, oldValue): void

Parameters
NameType
playeralt.Player
newValueany
oldValueany
Returns

void

Defined in

server/document/character.ts:8

Functions

bind

Usage

Athena.document.character.bind(player, document): any

Binds a player identifier to a Character document.

This document is cleared on disconnected automatically.

This should be the first thing you do after having a user authenticate and select a character.

Example

ts
import Database from '@stuyk/ezmongodb';

async function doSomething(somePlayer: alt.Player, someMongoDBId: string) {
    const someData = await Database.fetchData('_id', someMongoDBId, 'characters')
    Athena.document.character.bind(somePlayer, someData);
}

Parameters

NameTypeDescription
playerPlayerAn alt:V Player Entity
documentCharacter

Returns

any

Defined in

server/document/character.ts:43


get

Usage

Athena.document.character.get<T>(player): T | undefined

Return current player data and their associated character object.

Can also append custom objects to the generic type to obtain custom data from the database.

Example

ts
interface Testing {
    myProperty: string;
}

function someFunction(player: alt.Player) {
     const data = Athena.document.character.get<Testing>(player);
     if (typeof data === 'undefined') {
         // Player likely not logged in...
         return;
     }

     if (data.myProperty) {
         console.log(data.myProperty);
     }
}

Type parameters

NameType
TCharacter

Parameters

NameTypeDescription
playerPlayerAn alt:V Player Entity

Returns

T | undefined

Defined in

server/document/character.ts:104


getAllOnline

Usage

Athena.document.character.getAllOnline<T>(): { document: player & T ; id: number }[]

Return all available and online characters, and their associated alt:V player ids.

The player can be fetched with alt.Player.all.find(x => x.id === someResult.id);

Export

Type parameters

NameType
T{}

Returns

{ document: player & T ; id: number }[]

Defined in

server/document/character.ts:320


getField

Usage

Athena.document.character.getField<T, ReturnType>(player, fieldName): ReturnType | undefined

Get the current value of a specific field inside of the player data object. Can be extended to obtain any value easily.

Example

Get a default value.

ts
const cash = Athena.document.character.getField<{}, number>(somePlayer, 'cash');
if (typeof cash === 'undefined') {
    return;
}

Alternatively, pass a custom interface.

ts
interface CustomData {
    bitcoin: number
}

const bitcoins = Athena.document.character.getField<CustomData, number>(somePlayer, 'bitcoin');
if (typeof bitcoins === 'undefined') {
    return;
}

Type parameters

NameType
T{}
ReturnTypeany

Parameters

NameTypeDescription
playerPlayerAn alt:V Player Entity
fieldNamestring | number | symbol

Returns

ReturnType | undefined

Defined in

server/document/character.ts:145


onChange

Usage

Athena.document.character.onChange<T>(fieldName, callback): any

Invokes the callback function when a document with a specific field name has changed.

Example

ts
Athena.document.character.onChange('cash', (player: alt.Player, newValue: number, oldValue: number) => {
    // Do whatever you want with it.
    // Never, ever update the same document value twice in a row.
    // It creates an endless loop
})

Type parameters

NameType
T{}

Parameters

NameType
fieldNamestring | number | symbol
callbackKeyChangeCallback

Returns

any

Defined in

server/document/character.ts:297


override

Usage

Athena.document.character.override(functionName, callback): any

Used to override any character document functionality

Parameters

NameType
functionName"bind"
callback(player: Player, document: Character) => any

Returns

any

Defined in

server/document/character.ts:347

Usage

Athena.document.character.override(functionName, callback): any

Used to override any character document functionality

Parameters

NameType
functionName"unbind"
callback(id: number) => any

Returns

any

Defined in

server/document/character.ts:348

Usage

Athena.document.character.override(functionName, callback): any

Used to override any character document functionality

Parameters

NameType
functionName"get"
callback<T>(player: Player) => T | undefined

Returns

any

Defined in

server/document/character.ts:349

Usage

Athena.document.character.override(functionName, callback): any

Used to override any character document functionality

Parameters

NameType
functionName"getField"
callback<T, ReturnType>(player: Player, fieldName: string | number | symbol) => ReturnType | undefined

Returns

any

Defined in

server/document/character.ts:350

Usage

Athena.document.character.override(functionName, callback): any

Used to override any character document functionality

Parameters

NameType
functionName"set"
callback<T, Keys>(player: Player, fieldName: Keys, value: any, skipCallbacks: boolean) => any

Returns

any

Defined in

server/document/character.ts:351

Usage

Athena.document.character.override(functionName, callback): any

Used to override any character document functionality

Parameters

NameType
functionName"setBulk"
callback<T, Keys>(player: Player, fields: Keys) => any

Returns

any

Defined in

server/document/character.ts:352

Usage

Athena.document.character.override(functionName, callback): any

Used to override any character document functionality

Parameters

NameType
functionName"onChange"
callback<T>(fieldName: string | number | symbol, callback: KeyChangeCallback) => any

Returns

any

Defined in

server/document/character.ts:353


set

Usage

Athena.document.character.set<T, Keys>(player, fieldName, value, skipCallbacks?): any

Sets a player document value, and saves it automatically to the selected character's database.

Automatically calls all callbacks associated with the field name.

Example

ts
await Athena.document.character.set(somePlayer, 'cash', 50);

Alternatively, pass a custom interface.

ts
interface CustomCharacter {
     someKey: string;
}

await Athena.document.character.set<CustomCharacter>(somePlayer, 'someKey', 'hello world');

Type parameters

NameType
T{}
Keysstring | number | symbol

Parameters

NameTypeDefault valueDescription
playerPlayerundefinedAn alt:V Player Entity
fieldNameKeysundefined
valueanyundefined
skipCallbacksbooleanfalse-

Returns

any

Defined in

server/document/character.ts:186


setBulk

Usage

Athena.document.character.setBulk<T, Keys>(player, fields): any

Sets player document values, and saves it automatically to the selected character's database.

Automatically calls all callbacks associated with the field name.

Example

ts
await Athena.document.character.setBulk(player, { cash: 25, bank: 100 });

Type parameters

NameType
T{}
KeysPartial<any>

Parameters

NameTypeDescription
playerPlayerAn alt:V Player Entity
fieldsKeys

Returns

any

Defined in

server/document/character.ts:245


unbind

Usage

Athena.document.character.unbind(id): any

Unbind stored player character cache data.

Example

ts
Athena.document.character.unbind(1);

Parameters

NameType
idnumber

Returns

any

Defined in

server/document/character.ts:68

Created by Stuyk | Est. 2020