Skip to content

Exports & events

Public API of Cuxial Tablet: exports for coins, pass XP, history and the tablet itself, state bags and the events other resources can use.

Cuxial Tablet exposes its coins, the season pass XP, the VIP history and the tablet window to other resources, plus a few state bags to know what a player is doing. Everything else is internal.

Server exports ​

GetCoins ​

Returns the coin balance of an online player.

lua
---@param src integer
---@return integer
local coins = exports.cuxial_tablet:GetCoins(source)

AddCoins ​

Adds coins to an online player, records the movement in the wallet and refreshes the tablet. Returns whether it succeeded and the balance after it.

lua
---@param src integer
---@param amount integer      1 or more
---@param reason? string      shown in the wallet history
---@return boolean ok, integer balance
local ok, balance = exports.cuxial_tablet:AddCoins(source, 500, 'Tournament prize')

RemoveCoins ​

Removes coins from an online player. Fails when the player cannot afford the amount.

lua
---@param src integer
---@param amount integer
---@param reason? string
---@return boolean ok, integer balance
local ok, balance = exports.cuxial_tablet:RemoveCoins(source, 100, 'Casino entry')
if not ok then
    -- not enough coins
end

GrantPassXp ​

Gives season pass XP. The player levels up as needed and sees the gain on screen when online. Returns nil when the pass is disabled or the player is unknown.

lua
---@param src integer|string   server id or citizenid (works for offline players)
---@param amount integer
---@param source? string       daily | shop | cases | job | playtime | mission | admin (default admin)
---@return { level: integer, xp: integer, leveled: boolean }?
local result = exports.cuxial_tablet:GrantPassXp(source, 250, 'job')

EmitJobCompleted ​

Tells the tablet that a player completed a job. The pass grants pass.xpSources.jobComplete XP and the weekly job missions advance. Call it from the server only.

lua
---@param src integer
---@param info? { job?: string, money?: number }
exports.cuxial_tablet:EmitJobCompleted(source, { job = 'trucker', money = 1200 })

With cuxial_jobs running, the tablet listens to its cuxial_jobs:server:JobCompleted event and you do not need to call this.

LogHistory ​

Adds an entry to the player's VIP history, the list shown in the History tab.

lua
---@param src integer|string   server id or citizenid
---@param entry { source: string, title: string, subtitle?: string, amount?: integer, currency?: 'coins'|'cash'|'item', itemKey?: string, rarity?: string, ref?: string }
---@return boolean
exports.cuxial_tablet:LogHistory(source, {
    source = 'admin',
    title = 'Event reward',
    amount = 200,
    currency = 'coins',
})

source is one of shop, cases, daily, pass, wallet, code, gift, loyalty, admin or mission. For coins, amount is negative when spent and positive when received.

getSetting ​

Returns a copy of a settings section as it is now, after the changes made from the admin panel.

lua
---@param id string   config.tablet | config.vip | config.daily | config.pass | config.cases | config.news | config.live | config.crosshair | config.jobs | data.shop | data.daily | data.pass | data.cases | data.missions | data.jobsOnline | data.jobsCity
---@return table?
local vip = exports.cuxial_tablet:getSetting('config.vip')
print(vip.codes.prefix)

Client exports ​

Open, Close, Toggle, IsOpen ​

Control the tablet window. Open accepts a page id; without it, the tablet opens on its usual page. The tablet still refuses to open when the player is in a state that tablet.canOpen forbids.

lua
---@param page? 'player'|'news'|'jobsOnline'|'jobsCity'|'crosshair'|'vip'
exports.cuxial_tablet:Open('news')
exports.cuxial_tablet:Close()
exports.cuxial_tablet:Toggle()

---@return boolean
local open = exports.cuxial_tablet:IsOpen()

SetPage ​

Changes the page while the tablet is open. Returns false when the page does not exist or is turned off in tablet.pages.

lua
---@param page string
---@return boolean
exports.cuxial_tablet:SetPage('vip')

IsCrosshairActive ​

Tells whether the player's custom crosshair is drawn at the moment.

lua
---@return boolean
local active = exports.cuxial_tablet:IsCrosshairActive()

State bags ​

BagWhereValue
cuxialTablet:openPlayertrue while that player has the tablet open.
cuxialTablet:livePlayerThe id of the stream while that player is broadcasting.
cuxialTabletLivesGlobalA counter that grows each time a stream starts or ends.
cuxialTabletCatalogRevGlobalA counter that grows each time the shop, the daily reward, the pass or the cases change.
lua
-- server
local open = Player(src).state['cuxialTablet:open']

-- client
AddStateBagChangeHandler('cuxialTablet:live', nil, function(bagName, _, value)
    -- value is the stream id, or nil when it ends
end)

Events ​

cuxial_tablet:settingsApplied ​

Server and client, local to the resource's side. Fired after a settings section changes, with the section id. Listen to it from your own resources with AddEventHandler to react to live edits.

lua
AddEventHandler('cuxial_tablet:settingsApplied', function(id)
    if id == 'data.shop' then
        -- the shop catalogue changed
    end
end)

Events it listens to ​

EventSideEffect
cuxial_jobs:server:JobCompletedServerGrants pass XP and advances the job missions, when cuxial_jobs is running

Hooks ​

The profile data (vehicles, properties, worked hours, extra stats), the pass XP for jobs and the item images come from the adapters in hooks/. They are plain Lua files you can edit to connect your own resources. See Hooks.

Internal events ​

Every other event and callback starting with cuxial_tablet: is internal. They check the caller on the server and may change without notice. Do not trigger them from your own resources.

© Cuxial