Multicharacter
Exports and Events
Client and server exports and events for other resources.
On this page6 sections
Client exports
exports.sc_multicharacter:IsBusy()exports.sc_multicharacter:IsOpen()exports.sc_multicharacter:IsSpawned()exports.sc_multicharacter:GetCharacter()exports.sc_multicharacter:GetCitizenId()| Export | Returns |
|---|---|
IsBusy() | true until the player is actually playing (loading, select, editor, spawn, arrival) |
IsOpen() | true while the resource UI is on screen |
IsSpawned() | The opposite of IsBusy() |
GetCharacter() | Copy of the current character data or nil |
GetCitizenId() | Citizen id of the current character or nil |
Example for an anticheat:
if exports.sc_multicharacter:IsBusy() then return endServer exports
exports.sc_multicharacter:IsSelecting(source)exports.sc_multicharacter:IsPlaying(source)exports.sc_multicharacter:GetCharacter(source)exports.sc_multicharacter:GetCitizenId(source)exports.sc_multicharacter:GetCharacters(license)exports.sc_multicharacter:GetPlayingCharacters()| Export | Returns |
|---|---|
IsSelecting(source) | true when connected but no character is selected yet |
IsPlaying(source) | true when playing a character |
GetCharacter(source) | Live character data with current position, money, and job |
GetCitizenId(source) | Citizen id of the current character or nil |
GetCharacterId(source) | Same as GetCitizenId |
GetCharacters(license) | List of all characters of a license |
GetPlayingCharacters() | { [source] = citizenid } for everyone playing |
Character data
GetCharacter returns the same shape on every framework:
| Field | Description |
|---|---|
citizenid | Character identifier |
license | Player identifier |
cid | Slot number |
firstname, lastname | Name |
birthdate | Birth date |
gender | 0 male, 1 female |
nationality | Nationality |
height, weight | Height and weight |
appearance | Saved appearance |
job | { name, label, grade, gradeLabel } |
gang | Gang on QBCore and Qbox |
money | { cash, bank } |
metadata | Metadata |
position | { x, y, z, heading } |
is_dead | Whether the character is dead |
last_played | Last played |
Client events
| Event | Arguments | When |
|---|---|---|
sc_multicharacter:stateChanged | state | Stage change. state is { open, spawned, busy, citizenid }. Only on a real change. |
sc_multicharacter:playerLoaded | character | The character is known, before spawn |
sc_multicharacter:playerSpawned | character | The flow ended and the player has control |
sc_multicharacter:inventoryReady | citizenid | The character inventory exists |
AddEventHandler('sc_multicharacter:playerSpawned', function(character) print(('Playing as %s %s'):format(character.firstname, character.lastname))end)AddEventHandler('sc_multicharacter:stateChanged', function(state) DisplayRadar(state.spawned)end)Server events
| Event | Arguments | When |
|---|---|---|
sc_multicharacter:characterCreated | source, character, isFirst | Character saved in the database |
sc_multicharacter:characterDeleted | source, citizenid | Character deleted |
sc_multicharacter:playerLoaded | source, character | Selected and handed to the framework |
sc_multicharacter:playerLogout | source, citizenid | Relog or disconnect |
sc_multicharacter:inventoryReady | source, citizenid | The character inventory exists |
sc_multicharacter:startingItemsGranted | source, citizenid, lines, total | Starter basket granted |
sc_multicharacter:bridgeReady | frameworkName | Framework detected and ready |
AddEventHandler('sc_multicharacter:characterCreated', function(source, character, isFirst) if isFirst then print(('New player: %s %s'):format(character.firstname, character.lastname)) endend)AddEventHandler('sc_multicharacter:characterDeleted', function(source, citizenid) MySQL.query('DELETE FROM my_table WHERE citizenid = ?', { citizenid })end)Framework events
After selection, the character is handed to the framework with its own method, such as ESX esx:onPlayerJoined, QBCore Player.Login, or Qbox Login.
The framework then fires its standard events, such as esx:playerLoaded or QBCore:Client:OnPlayerLoaded. Resources waiting for them work unchanged.