Move money, leave paychecks, charge cards and read accounts from your own resources. All exports run on the server.
exports.cuxial_banking:<Name>(...)Amounts are positive whole numbers. Decimals are cut off. Zero, negative, invalid or absurdly large values make the export return false.
Player money
AddMoney
Pays money to a character, online or offline.
exports.cuxial_banking:AddMoney(citizenId, amount, account)| Parameter | Type | Description |
|---|---|---|
citizenId | string | Character identifier. |
amount | number | Amount to add. |
account | string | 'bank', 'cash' or 'crypto'. Optional; 'bank' by default. |
Returns: boolean.
exports.cuxial_banking:AddMoney(citizenId, 1500)RemoveMoney
Takes money from a character if they have enough.
exports.cuxial_banking:RemoveMoney(citizenId, amount, account)Same parameters as AddMoney.
Returns: boolean. false when the balance is not enough.
if exports.cuxial_banking:RemoveMoney(citizenId, 250, 'bank') then
-- paid
endAddMoney and RemoveMoney write nothing to the history. Add the entry yourself with AddTransaction.
GetAccount
Reads the money of a character who is online.
local account = exports.cuxial_banking:GetAccount(citizenId)Returns: { citizenid, name, bank, cash }, or nil when the character is not online.
local account = exports.cuxial_banking:GetAccount(citizenId)
if account and account.bank >= 5000 then
-- can afford it
endHistory
AddTransaction
Writes a movement to the history of an account.
exports.cuxial_banking:AddTransaction(identifier, transaction)| Parameter | Type | Description |
|---|---|---|
identifier | string | Character identifier, job name or shared account code. |
transaction.value | number | Positive for money in, negative for money out. |
transaction.reason | string | Text shown in the history. Up to 255 characters. |
transaction.type | string | 'deposit', 'withdraw', 'transfer', 'loan', 'card', 'fee' or 'interest'. Anything else is stored as 'deposit'. |
transaction.sender_name | string | Name of the sender. |
transaction.sender_identifier | string | Identifier of the sender. |
transaction.receiver_name | string | Name of the receiver. |
transaction.receiver_identifier | string | Identifier of the receiver. |
transaction.date | string | 'YYYY-MM-DD HH:MM:SS'. Optional; now by default. |
Returns: boolean.
exports.cuxial_banking:AddTransaction(citizenId, {
value = -250,
reason = 'Parking fine',
type = 'fee',
sender_name = 'John Doe',
sender_identifier = citizenId,
receiver_name = 'City Hall',
receiver_identifier = 'cityhall',
})GetPlayerTransactions
Returns the latest movements of an account.
local list = exports.cuxial_banking:GetPlayerTransactions(identifier)Returns: table[]. Each entry has the fields of AddTransaction. The length is limited by MaxTransactionsPerPlayer.
for _, tx in ipairs(exports.cuxial_banking:GetPlayerTransactions(citizenId)) do
print(tx.date, tx.value, tx.reason)
endBusiness accounts
The society parameter is the job name. The form society_<job> is accepted too.
AddSocietyMoney
exports.cuxial_banking:AddSocietyMoney(society, amount, reason)| Parameter | Type | Description |
|---|---|---|
society | string | Job name. |
amount | number | Amount to add. |
reason | string | Optional. When given, the movement is written to the history of the account. |
Returns: boolean. false when the account does not exist.
exports.cuxial_banking:AddSocietyMoney('mechanic', 800, 'Repair invoice')RemoveSocietyMoney
exports.cuxial_banking:RemoveSocietyMoney(society, amount, reason)Same parameters as AddSocietyMoney.
Returns: boolean. false when the account does not exist or the balance is not enough.
if exports.cuxial_banking:RemoveSocietyMoney('police', 500, 'Equipment') then
-- paid from the business account
endGetSocietyAccount
local account = exports.cuxial_banking:GetSocietyAccount(society)Returns: { society, society_name, balance, iban, credit_score, opening_date }, or nil when the account does not exist.
local account = exports.cuxial_banking:GetSocietyAccount('police')
print(account and account.balance or 0)Paychecks
AddPaycheck
Leaves a paycheck for a character to collect at a branch. This is how salaries reach the bank: it does not create them on its own.
exports.cuxial_banking:AddPaycheck(citizenId, sourceKey, sourceName, amount, status)| Parameter | Type | Description |
|---|---|---|
citizenId | string | Character identifier. |
sourceKey | string | Where it comes from, usually the job name. |
sourceName | string | Name shown to the player. |
amount | number | Amount of the paycheck. |
status | string | 'ready' or 'pending'. Optional; 'ready' by default. |
Returns: boolean.
exports.cuxial_banking:AddPaycheck(citizenId, 'police', 'Police Department', 500)Cards
ChargeCard
Charges a card the player is carrying. Use it for card payments in shops.
local result = exports.cuxial_banking:ChargeCard(source, cardNumber, pin, amount, reason)| Parameter | Type | Description |
|---|---|---|
source | number | Server id of the player who pays. They must carry the card. |
cardNumber | string | Number of the card. |
pin | string | number | PIN typed by the player. |
amount | number | Amount to charge. Limited by cards.posMaxCharge and by the daily limit of the card. |
reason | string | Name of the merchant, shown in the history. Optional. |
Returns: { success, message, cardHolder, last4 }. message is only set on failure; cardHolder and last4 only on success.
local result = exports.cuxial_banking:ChargeCard(source, cardNumber, pin, 120, 'Supermarket')
if not result.success then
print(result.message)
endRefundCard
Returns a charge to the owner of the card.
exports.cuxial_banking:RefundCard(cardNumber, amount, reason)Returns: boolean. The money always goes to the owner of the card, never to whoever paid with it.
exports.cuxial_banking:RefundCard(cardNumber, 120, 'Supermarket')GetPlayerCards
Lists the cards a player is carrying.
local cards = exports.cuxial_banking:GetPlayerCards(source)Returns: table[]. Each entry has cardNumber, cardHolder, cardHolderCitizenId, cardHolderIBAN, cardType, cardTypeLabel, dailyLimit, accountType, status, expiryDate, slot and item.
for _, card in ipairs(exports.cuxial_banking:GetPlayerCards(source)) do
if card.status == 'active' then
-- offer it as a payment method
end
endSettings
getSetting
Reads a section of the live settings, as it is in use right now.
local cards = exports.cuxial_banking:getSetting('config.cards')| Parameter | Type | Description |
|---|---|---|
id | string | 'config.general', 'config.accounts', 'config.cards', 'config.loans', 'config.savings', 'config.cheques', 'config.rewards', 'config.creditScore', 'config.atm', 'config.admin' or 'config.logs'. |
Returns: table, or nil for an unknown section.
local general = exports.cuxial_banking:getSetting('config.general')
print(general.currency)Wealth report
The Citizens tab of the staff panel adds up everything a character owns. Your resource can add its own lines.
RegisterWealthProvider
exports.cuxial_banking:RegisterWealthProvider(name, fn)| Parameter | Type | Description |
|---|---|---|
name | string | Unique name of the source. |
fn | function | Receives the character identifier and returns a list of lines. |
Each line:
| Field | Type | Description |
|---|---|---|
key | string | Identifier of the line. |
label | string | Text shown in the panel. |
amount | number | Value. Lines with zero are dropped. |
kind | string | 'asset' adds to the net worth. 'transit' adds too: money on its way. 'liability' subtracts. 'control' is shown without adding: funds the character manages but does not own. 'asset' by default. |
detail | table | Optional. Extra text, number or boolean values. |
Returns: boolean. false when another resource already registered that name.
exports.cuxial_banking:RegisterWealthProvider('myshop', function(citizenId)
return {
{ key = 'till', label = 'Shop till', amount = 3200, kind = 'asset' },
}
end)The source is removed by itself when your resource stops.
UnregisterWealthProvider
exports.cuxial_banking:UnregisterWealthProvider(name)Returns: boolean. Only the resource that registered a source can remove it.
Events
cuxial_banking:client:OpenAtm
Client event. Opens the ATM for the local player from your own resource, for example from a custom ATM prop.
| Parameter | Type | Description |
|---|---|---|
coords | vector3 | Position of the ATM. Optional; the position of the player by default. |
TriggerEvent('cuxial_banking:client:OpenAtm', GetEntityCoords(atmEntity))The player still needs an active card and its PIN, and must stay within atmDistance of those coordinates.
cuxial_banking:settingsApplied
Local event, on the server and on each client. Triggered when a settings section is loaded or changed from the staff panel.
| Parameter | Type | Description |
|---|---|---|
id | string | Section that changed, for example 'config.cards'. |
-- server side
AddEventHandler('cuxial_banking:settingsApplied', function(id)
if id == 'config.cards' then
local cards = exports.cuxial_banking:getSetting('config.cards')
end
end)