Esc to clear, Enter to open the best match, click an export to open it in its page
Money

Bank API

Server exports for charging and paying players, money holds and bank accounts. Read Charging a Player for the common path and Bank Accounts for roles and rules.

Charging and paying

ChargePlayer(source, amount, opts?)SERVERWAITS#

Takes a payment in cash or from the bank and returns a receipt RefundPlayer can undo. See Charging a Player.

ParamTypeDescription
sourcenumberPlayer server ID
amountnumberA whole number, 0 or more (0 takes nothing and still returns a receipt)
opts.methodstring?'cash', 'bank' or 'auto' (default: cash if they carry enough, else the bank)
opts.accountIdnumber?Bank: which account (default their default one); their withdraw permission is checked
opts.currencystring?Cash: the item that counts as money (default 'cash'). A refund returns the very items taken, with what they carry (a paid gun keeps its serial)
opts.reasonstring?On the statement and the activity log (default 'Payment')
Returns: receipt|false, string|nil: receipt { id, amount, method, accountId, currency, refunded }; the error is a sentence the player can read
RefundPlayer(receipt, amount?)SERVERWAITS#

Gives back a payment ChargePlayer took, the way it came, with no permission check (see Refunding). Only the resource that charged may refund, up to what's left, within 30 minutes.

ParamTypeDescription
receipttable|numberThe receipt, or its id
amountnumber?How much (default: everything not yet refunded)
Returns: bool, string|nil: false when it couldn't be delivered (also printed as CRITICAL)
PayPlayer(who, amount, opts?)SERVERWAITS#

Pays a player: a wage, a reward, a sale. Cash that doesn't fit their pockets lands at their feet, and every payment is on the activity log with your resource's name.

ParamTypeDescription
whonumber|tableA server id, or { charId = n } for a character who may be offline
amountnumberA whole number, 0 or more (0 pays nothing)
opts.methodstring?'cash', 'bank' or 'auto' (default: cash while they're online, else their bank)
opts.accountIdnumber?Bank: which account (default their default one)
opts.currencystring?Cash: the item paid (default 'cash')
opts.reasonstring?On the statement and the activity log
Returns: { method, amount, currency?, placement?, accountId? } (placement: 'inventory' or 'ground'), or false, reason: as ChargePlayer returns its receipt

Money holds#

For a metered service (fuel, a taxi fare), hold the most it could cost, report what's used as it runs, and settle: the rest goes back. whip_fuel's pumps work this way. Nothing is lost if your resource or the server stops first: the refund owed is noted on the character with the charge and paid at their next login. The payer leaving, or your resource or whip_core stopping, settles it for what was used. Cash change goes to their pockets (the bank if it doesn't fit). Only your resource can spend or settle its holds.

HoldMoney(source, amount, opts?)SERVERWAITS#

Takes amount from the player now, cash or bank. opts = { method = 'cash' | 'bank', reason, vehicle? }: vehicle (a vehicleId) keeps that car's row unwritten until the settle, so fuel not yet paid for is never saved.

Returns: the hold's id, or false, why (not enough money, no bank account)
local holdId, why = exports.whip_core:HoldMoney(source, 100, { method = 'cash', reason = 'Car wash' })
if not holdId then return false, why end
-- each cycle: SpendMoneyHold(holdId, usedSoFar); at the end: SettleMoneyHold(holdId)
SpendMoneyHold(id, spent)SERVER#

Reports how much of the hold is used so far (0 up to what was held): what a settle keeps if your resource or the server stops first.

Returns: true, or false, why when the hold is gone (the payer left) or isn't yours: stop the service then
SettleMoneyHold(id, spent?)SERVERWAITS#

Ends the hold: spent (default: what SpendMoneyHold last said) is kept, the rest goes back, the note is cleared and a held vehicle's row is written, all together.

Returns: { spent, refunded, paidNow } (paidNow false: the change is paid at the next login), or false, why when already settled or not yours
GetMoneyHold(id)SERVER#

One of your holds as it is now. Ask before giving more of the service.

Returns: { source, amount, spent, method }, or nil: it's over, or not yours

Reading accounts

GetBalance(who)SERVERWAITS#

A balance from memory: only the first read of an account waits for the database, and every bank write keeps it true. A HUD, phone app or ATM prompt can ask as often as it shows it.

ParamTypeDescription
whonumber|tableA person for their main account, or { accountId = n }
Returns: integer, or false, why: no such person or account, no bank account, or it's closed
GetBankAccount(ref)SERVERWAITS#

An account, by its ID or its number.

ParamTypeDescription
refnumber|tableA bank account ID, or { number = 'WB-XXXXXX' }
Returns: table|nil: { accountId, accountNumber, label, type, ownerCharId, jobId, balance, isDefault, frozen, createdAt }, as every account read; times are epoch seconds
GetDefaultBankAccount(who)SERVERWAITS#

A person's default account: a database read every call. To show a balance, use GetBalance.

ParamTypeDescription
whonumber|tableServer id, or { charId = n }
Returns: table|nil
IsNearAtm(source, range?)SERVER#

Is the player standing at a cash machine? GTA's own machines and Config.AtmExtraPositions, measured across the ground from each machine's base. For a resource that wants the standing-at-a-machine rule; WHIP's own ATMs find machines by model and don't ask this.

ParamTypeDescription
sourcenumberServer id
rangenumber?Metres, 0.5 to 10. Default AtmActiveRange + 1
Returns: true, at (the machine's base) or false, why
GetNearestAtm(coords)SERVER#

The cash machine nearest a place, from the same list as IsNearAtm, within 3 m of its height.

ParamTypeDescription
coordsvector3|tableThe place
Returns: at, distance (the machine's base, and the distance across the ground), or nil
GetCharacterBankAccounts(charId)SERVERWAITS#

Every account a character can use, each with their role on it. To offer accounts to pay from, keep withdraw, manager and owner: the others are refused at the till.

ParamTypeDescription
charIdnumberCharacter ID
Returns: table[]: accounts with a role field
GetJobBankAccounts(job)SERVERWAITS#

A job's accounts. None yet means the job has no owner.

ParamTypeDescription
jobnumber|stringjobId or key ('police')
Returns: table: accounts; {}, 'No such job' for a job that doesn't exist
GetBankTransactions(accountId, limit?, offset?)SERVERWAITS#

An account's history, newest first.

ParamTypeDescription
accountIdnumberBank account ID
limitnumber?Rows to return (default 50, at most 500)
offsetnumber?Rows to skip (default 0)
Returns: table: rows of { txId, fromAccountId, toAccountId, type, amount, fromBalance, toBalance, actorCharId, message, createdAt }; type is 'deposit', 'withdraw', 'transfer' or 'payment'. A row is money out when fromAccountId is this account
GetBankAccessList(accountId)SERVERWAITS#

Who has access to an account, and their roles.

ParamTypeDescription
accountIdnumberBank account ID
Returns: table: array of { charId, role, grantedBy }

A player's moves

CanUseBankAccount(accountId, who, role)SERVERWAITS#

Whether a person may act at role level on an account, by the bank's own rule: ask before offering accounts or menu options.

ParamTypeDescription
accountIdnumberBank account ID
whonumber|tableA person
rolestring'view', 'deposit', 'withdraw', 'manager' or 'owner'; each includes those before it
Returns: bool, string|nil: false, 'Needs withdraw access to this account', 'Account not found'
BankDeposit(accountId, amount, actor, opts?)SERVERWAITS#

A player pays into an account. For the system paying in, use BankSystemDeposit.

ParamTypeDescription
accountIdnumberBank account ID
amountnumberA whole number, 1 or more
actornumber|tableThe person depositing (required): deposit or higher
opts.reasonstring?Shown on the statement
Returns: bool, string|nil; fires whip_core:bank:balanceChanged
No cash is taken. For a cash deposit, first take the notes with ChargePlayer(source, n, { method = 'cash' }), and refund that receipt if the deposit is refused. Otherwise a deposit makes money from nothing.
BankWithdraw(accountId, amount, actor, opts?)SERVERWAITS#

A player takes money out of an account. To charge for something, use ChargePlayer instead.

ParamTypeDescription
accountIdnumberBank account ID
amountnumberA whole number, 1 or more
actornumber|tableThe person withdrawing (required): withdraw or higher
opts.reasonstring?Shown on the statement
Returns: bool, string|nil
No cash is given. For a cash withdrawal, give the notes with PayPlayer(source, amount, { method = 'cash' }) once this returns true. Otherwise the money leaves the account and they get nothing.
BankTransfer(fromId, toId, amount, actor, opts?)SERVERWAITS#

A player moves money between accounts; withdraw on the source is checked. For payroll, use BankSystemTransfer.

ParamTypeDescription
fromIdnumberSource account
toIdnumberDestination account
amountnumberA whole number, 1 or more
actornumber|tableThe person transferring (required)
opts.reasonstring?Shown on the statement
Returns: bool, string|nil: 'Insufficient funds', 'No withdraw permission on source account'...

System moves

Your resource decides: no permission check, and the activity log records your resource's name.

BankSystemDeposit(accountId, amount, opts?)SERVERWAITS#

Pays into an account: a wage, a sale's takings, a reward.

ParamTypeDescription
accountIdnumberTarget bank account ID
amountnumberA whole number, 1 or more
optstable?{ reason, actorCharId }: the reason (on the statement), and who caused it
Returns: bool, string|nil
BankSystemWithdraw(accountId, amount, opts?)SERVERWAITS#

Takes money out of an account: a fine, a fee, a bill.

ParamTypeDescription
accountIdnumberBank account ID
amountnumberA whole number, 1 or more
optstable?{ reason, actorCharId }
Returns: bool, string|nil: 'Insufficient funds', 'Account is frozen'
BankSystemTransfer(fromId, toId, amount, opts?)SERVERWAITS#

Moves money between two accounts, such as payroll from a job's account (GetJobBankAccounts) to an employee's default one. Otherwise refused as a transfer would be.

ParamTypeDescription
fromIdnumberSource account
toIdnumberDestination account
amountnumberA whole number, 1 or more
optstable?{ reason, actorCharId }
Returns: bool, string|nil

Opening, sharing and closing

CreateBankAccount(owner, label?, opts?)SERVERWAITS#

Opens an account at $0. A character may own at most Config.MaxExtraAccounts savings and shared accounts (default 5); personal and job accounts don't count.

ParamTypeDescription
ownernumber|tableThe person who owns it
labelstring?Display name, 1-50 characters (default Config.DefaultAccountLabel)
opts.typestring?'personal' (default), 'savings', 'business' or 'shared'
opts.jobnumber|string?A business account's job, by jobId or key; a missing job returns false, 'No such job'
Returns: table|false, string|nil: the account, or false and why ('A character may have at most 5 savings and shared accounts'...)
GrantBankAccess(accountId, who, role, grantedBy)SERVERWAITS#

Gives a character access to an account. The granter can only give roles below their own, to someone below them, and can't change the owner. Refused for another character of the granter's or owner's player while Config.BlockOwnCharacterTransfers is on.

ParamTypeDescription
accountIdnumberBank account ID
whonumber|tableThe person getting access
rolestring'view', 'deposit', 'withdraw' or 'manager'
grantedBynumber|tableThe person granting: their role is checked
Returns: bool, string|nil
CanGrantBankAccess(accountId, who, role, grantedBy)SERVERWAITS#

Whether GrantBankAccess would allow it, writing nothing: the phone's Bank app asks before sending an invite, then grants on acceptance.

ParamTypeDescription
accountIdnumberBank account ID
whonumber|tableThe person who would get it
rolestringThe role they would get
grantedBynumber|tableThe person who would grant it
Returns: bool, string|nil
RevokeBankAccess(accountId, who, revokedBy)SERVERWAITS#

Removes a character's access to an account.

ParamTypeDescription
accountIdnumberBank account ID
whonumber|tableThe person to revoke
revokedBynumber|tableThe person revoking: must outrank them
Returns: bool, string|nil
CloseBankAccount(accountId, who?)SERVERWAITS#

Marks an account closed, and everyone's access goes with it. The balance must be zero, and a default account can't be closed.

ParamTypeDescription
accountIdnumberBank account ID
whonumber|table?The person closing it, checked: they must own it, and it must be savings or shared. Leave it out when your code or an admin decides
Returns: bool, string|nil: 'Account must have zero balance', 'Cannot close default account', 'Only the owner can close this account'...
SetBankAccountFrozen(accountId, frozen)SERVERWAITS#

Freezes or unfreezes an account, say for a court order. Every move in or out is then refused with 'Account is frozen', also on the ATM; money and access stay. No permission check; the activity log records your resource.

ParamTypeDescription
accountIdnumberBank account ID
frozenbooleantrue to freeze, false to unfreeze
Returns: true, or false, why ('Account not found'...)

Vehicle values

SetVehiclePrices(prices)SERVER#

What your resource charges for vehicles. Banks values an owned car at this price, averaged across resources. Declare it in Whip.register; again replaces your list, and it goes when your resource stops.

ParamTypeDescription
pricestable{ [model] = price } in dollars, more than 0: { adder = 1000000 }
Returns: true, or false, why