Events and state
Server hooks
Functions in the config files that fx-pocketbook calls on the server, so your own code runs when a bill changes, an identity card is made or the calendar lists payments.
FX Pocketbook has no server events for other resources. Where it lets your code run, it calls a function you write in a config file. The functions run on the server. An error inside them is caught and does not break the notebook.
#Billing hooks
apps/billing/config.lua > Config.Billing.Hooks:
luaHooks = {
Sent = function(src, id) end,
Paid = function(src, id, amount) end,
Cancelled = function(src, id) end,
}
| Hook | Arguments | When |
|---|---|---|
Sent |
src, id |
A bill was written, in the app or with CreateInvoice. src is the player who wrote it. |
Paid |
src, id, amount |
A payment was recorded. amount is in dollars. It also runs for a part payment (an installment). |
Cancelled |
src, id |
A bill was cancelled by its sender. |
idis the bill id. Read it with [GetInvoice](/phone/docs/pocketbook/exports/server/bills).- When overdue collection takes the money (
Config.Billing.Collection),Paidruns withsrc = 0if the player is offline. - A repeated request with the same nonce does not run a hook twice.
luaPaid = function(src, id, amount)
TriggerEvent('my-saloon:billPaid', id, amount)
end,
apps/billing/config.lua is a shared file: the client loads it too. Keep server-only code inside the function body.
#Kartlarim identity card
apps/kartlarim/config_server.lua > PocketServerConfig.Apps.kartlarim.Identity. It runs when Kartlarim creates the automatic identity card (Config.Kartlarim.AutoIdentity) and returns extra lines for it.
lua---@param src integer
---@param char table { id, name, job, grade, framework }
---@return table { birth?, class?, terms? }
Identity = function(src, char)
return { birth = '12 May 1870', class = 'Citizen' }
end,
| Field | What it is |
|---|---|
birth |
Birth date text, up to 40 characters, written at the start of the conditions text |
class |
Line under the name |
terms |
Conditions text |
The file that ships reads the birth date from RSG's charinfo.birthdate and the age from VORP.
#Calendar payment days
apps/takvim/config_server.lua > PocketServerConfig.Apps.takvim.PaymentDays. It lists things the player must pay (bills, tax, rent) in the calendar, read only. The calendar pays nothing.
lua---@param src integer
---@param char table { id, name, job, grade, framework }
---@return table list up to 20 rows { title, place?, note?, at }
PaymentDays = function(src, char)
local rows = MySQL.query.await("SELECT description,sender_label,UNIX_TIMESTAMP(due_at) AS due FROM fx_pocketbook_invoices WHERE recipient_account=? AND state='open' ORDER BY due_at LIMIT 20", { 'person:' .. char.id })
local list = {}
for _, row in ipairs(rows or {}) do list[#list + 1] = { title = row.description, place = row.sender_label, at = row.due } end
return list
end,
at is a unix time. If the function fails, the list is empty. The default is nil (no list).