Money
Functions for reading and modifying a player's money on the server.
getMoney
Get the amount of money a player has of a given type.
local amount = KOJA.Server.getMoney(source, mtype)
| Parameter | Type | Description |
|---|---|---|
source | number | Player server ID |
mtype | string | Money type — "cash", "bank", "black" |
Returns number
addMoney
Add money to a player's account.
local ok = KOJA.Server.addMoney(source, amount, mtype, reason)
| Parameter | Type | Description |
|---|---|---|
source | number | Player server ID |
amount | number | Amount to add |
mtype | string | Money type — "cash", "bank", "black" |
reason | string? | Reason (logged by some frameworks) |
Returns boolean
removeMoney
Remove money from a player's account.
local ok = KOJA.Server.removeMoney(source, amount, mtype, reason)
Same parameters as addMoney.
Returns boolean
Money Types
| Value | ESX | QBCore |
|---|---|---|
"cash" | money account | cash money type |
"bank" | bank account | bank money type |
"black" | black_money account | crypto money type |
Examples
-- Read balances
local cash = KOJA.Server.getMoney(source, 'cash')
local bank = KOJA.Server.getMoney(source, 'bank')
print(('Cash: $%d | Bank: $%d'):format(cash, bank))
-- Pay out a reward
KOJA.Server.addMoney(source, 500, 'cash', 'job_reward')
-- Charge for a service
local price = 250
if KOJA.Server.getMoney(source, 'bank') < price then
KOJA.Server.SendNotify({ source = source, type = 'error', desc = 'Not enough bank balance.' })
return
end
KOJA.Server.removeMoney(source, price, 'bank', 'shop_purchase')
KOJA.Server.addInventoryItem(source, 'burger', 1)
Related pages
- Police — Functions for checking how many police officers are online.
- Callbacks — The callback system allows server scripts to handle requests from clients and vice versa.
- Licenses — Check whether a player holds a specific driving or skill license.
- Inventory — Server-side inventory functions.
- Notifications — Send notifications to a player from the server side.
- Player — Functions for reading player information on the server.
- Server API — back to the section overview