Exports, events and hooks — CC Multicharacter
Everything another resource can use. Server exports can only be called from server code (a player can never call them). Replace cc_multicharacter with your folder name if you renamed it.
Everything another resource can use. Server exports can only be called from server code (a player can never call them). Replace cc_multicharacter with your folder name if you renamed it.
Server exports
local mc = exports.cc_multicharacter| Export | Arguments | Returns | What |
|---|---|---|---|
getActiveCharacter(src) | server id | string? | The framework's id of the active character (citizenid / identifier / charId) |
getCharacter(src) | server id | table? | Standalone only: { id, firstname, lastname }. On a framework ask the framework |
isSelecting(src) | server id | boolean | True while the player is on the select / create / spawn screens |
getPhase(src) | server id | string? | 'select', 'look' (clothing editor), 'spawn', 'landing', or nil in the world |
getBridge() | — | string?, string? | The framework and housing adapters in use |
getSlots(src) | server id | table? | { allowed, base, rank, ranks = { { id, label, extra, held } } } |
addSlots(identifier, n) | 'license:..'/'discord:..'/'fivem:..', 1–20 | integer? | Bought slots after the change (same as ccmc_addslots) |
removeSlots(identifier, n) | identifier, 1–20 | integer? | Same, removing; never below 0 |
restoreCharacter(charId) | id | string? | Restores a soft-deleted character; its name, or nil |
GetCharacterSlots(license2, license, src) | integer | Slot count (compatible with Qbox's slot hook and cc_loading's export) | |
SetCharacterSlots(license, total) | licence, total | boolean, integer | Set an absolute total (stores and coin shops) |
registerHook(name, fn, opts?) | see Hooks | id | Add a hook handler |
removeHook(id) | Remove one | ||
getHooks() | table | Every hook with its description and handler count | |
getVersion() / getApi() | Version and the whole surface (cc_lib 1.12+) |
Client exports
| Export | Returns | What |
|---|---|---|
isSelecting() | boolean | True while our screens own the player (hide your HUD) |
requestRelog() | — | Same as typing /relog (the server still decides) |
Server events (listen with AddEventHandler)
These are local server events: only server code fires them, a player cannot.
AddEventHandler('cc_multicharacter:characterSpawned', function(src, charId, info)
-- info = { isNew = bool, kind = 'city' | 'home' | 'last', home = homeId? }
end)| Event | Arguments | When |
|---|---|---|
cc_multicharacter:bridgeReady | framework, housing | Adapters picked at start |
cc_multicharacter:characterSelected | src, charId | A returning character was logged in |
cc_multicharacter:characterCreated | src, charId, { firstname, lastname, dob, sex, height, nationality } | A new character exists (and is logged in) |
cc_multicharacter:characterSpawned | src, charId, { isNew, kind, home } | The character is in the world |
cc_multicharacter:characterDeleted | src, charId, soft | A character was deleted (soft = restorable) |
cc_multicharacter:ready | version | Our API is published (cc_lib 1.12+) |
Client events
AddEventHandler('cc_multicharacter:spawned', function(info) -- info = { home = bool }
-- show your HUD, start your phone, etc.
end)Your framework's own loaded events still fire as usual (QBCore:Client:OnPlayerLoaded, esx:playerLoaded, ox_core's), so most resources need nothing new.
State bags
| Bag | Side | Value |
|---|---|---|
Player(src).state.isInSpawnSelector | server → all | Qbox: true while on the spawn map |
Player(src).state.cc_character | server → all | Standalone: { id, firstname, lastname } of the active character |
Hooks
A hook lets your resource refuse or adjust what cc_multicharacter does, without editing it. Handlers run in pcall (your bug never breaks us) and are removed automatically when your resource stops. A hook can only narrow what we do: refuse, hide. It never grants.
-- server side, in your own resource
exports.cc_multicharacter:registerHook('beforeRelog', function(payload)
if exports.my_jail:isJailed(payload.source) then return false end -- refuse
end)| Hook | Cancellable | Payload | Use it for |
|---|---|---|---|
beforeRelog | yes | source | No relog in jail, during a heist, in a court case |
beforeCreate | yes | source, firstname, lastname, dob, sex, height, nationality (already validated) | Your own name rules, whitelists |
beforeSelect | yes | source, charId, firstname, lastname | Ban one character without banning the player |
beforeDelete | yes | source, charId, name, soft | Protect characters that own a business or a gang |
spawnOptions | no (mutable) | source, charId, isNew, job, hidden | Hide cards: payload.hidden['paleto'] = true. Ids: last, home:<id>, or a Config.Spawn.points id |
When a cancellable hook refuses, the player sees a short "Not allowed right now" message (notify.refused / create.err.refused in locales/).
Adding a framework or housing adapter
bridge/framework/*.lua and bridge/housing/*.lua are readable. Copy the closest one; the functions each must provide are documented at the top of every file (detect, account, list, listAccount, login, create, logout, purge, nameTaken, lastPosition, activeId, starter, holding, clientLoaded for frameworks; detect, homes, enter for housing). Add the file to server_scripts in fxmanifest.lua and its key to the order list in server/boot.lua, or force it with the cc_multicharacter_framework / cc_multicharacter_housing convar.