πŸͺHooks

Use hooks to run custom validation logic before or after banking actions. Block transactions, enforce limits, or add side effects like logging.

Overview

Hooks let you run custom validation logic before or after banking actions. Use them to enforce custom policies (e.g. max balance per character), blacklist checks, or external integration across deposits, withdrawals, transfers, society money, loans, cards, and ATM flows.

RegisterHook

If you are writing code inside tgg-banking (for example in server/custom/*.lua), use the built-in function:

RegisterHook(eventName, callback)

If you are writing code from an external resource, use export:

---@param eventName string
---@param callback fun(source: number, payload: table, result?: table): (boolean|table|nil)
---@return number | nil
exports['tgg-banking']:RegisterHook(eventName, callback)

registerHook (lowercase) is also available as an alias. Both registration methods are supported. Use the variant that matches where your script lives.

Supported events

Money actions (deposit, withdraw, transfer)

  • beforeDeposit

  • afterDeposit

  • beforeWithdraw

  • afterWithdraw

  • beforeTransfer

  • afterTransfer

Society money exports

  • beforeAddSocietyMoney

  • afterAddSocietyMoney

  • beforeRemoveSocietyMoney

  • afterRemoveSocietyMoney

Loan lifecycle

  • beforeLoanApply

  • afterLoanApply

  • beforeLoanPayment

  • afterLoanPayment

  • beforeLoanPayoff

  • afterLoanPayoff

  • beforeLoanApplyPayment

  • afterLoanApplyPayment

Card lifecycle

  • beforeCardCreate

  • afterCardCreate

  • beforeCardFreeze

  • afterCardFreeze

  • beforeCardUnfreeze

  • afterCardUnfreeze

  • beforeCardTerminate

  • afterCardTerminate

  • beforeCardUpdateLimits

  • afterCardUpdateLimits

ATM

  • beforeAtmAuthorize

  • afterAtmAuthorize

  • beforeAtmPinChange

  • afterAtmPinChange

Blocking behavior (before* hooks only)

  • return false -> blocks action with default message.

  • return { success = false, message = 'Your custom message' } -> blocks action with custom message.

  • any other return value -> allows action.

Where to use this code

Hook code runs on the server only. Add it in one of these ways:

chevron-rightInside tgg-banking (server/custom/*.lua)hashtag

Put your hook script in tgg-banking/server/custom/ (e.g. server/custom/limits.lua). It loads automatically with the resource. Use the native RegisterHook function.

chevron-rightExternal resourcehashtag

Create your own FiveM resource (e.g. my-banking-rules) with a server script. Add ensure tgg-banking before it in server.cfg, add tgg-banking to dependencies in your fxmanifest.lua, and use exports['tgg-banking']:RegisterHook(...). Your callback is written as a normal Lua function in your script; the runtime handles cross-resource function references automatically.

Register hooks once when the server or resource starts (top level of your server script, not inside an event handler).

Examples

Generic outline

chevron-rightInside tgg-banking (server/custom/*.lua)hashtag
chevron-rightExternal resourcehashtag

The examples below use the external resource form. Replace with RegisterHook when using server/custom/*.lua.

beforeDeposit

Payload: amount, reason, iban, cardNumber, accountType, accountOwnerId, playerIdentifier, newAccountBalance

Block deposits that would exceed a character's max bank balance:

afterDeposit

Same payload as beforeDeposit plus result.

Log successful deposits:

beforeWithdraw

Payload: amount, reason, iban, cardNumber, accountType, accountOwnerId, playerIdentifier

Block withdrawals above a limit or from blacklisted accounts:

afterWithdraw

Same payload as beforeWithdraw plus result.

Log successful withdrawals:

beforeTransfer

Payload: amount, reason, senderIban, targetIban, senderOwnerId, targetOwnerId, senderAccountType, targetAccountType, playerIdentifier, newTargetBalance

Block transfers that would exceed limits or to/from restricted accounts:

afterTransfer

Same payload as beforeTransfer plus result.

Log successful transfers:

beforeAddSocietyMoney / beforeRemoveSocietyMoney

Payload: society, iban, amount, currentBalance, newBalance, source, initiator (export calls use source = 0)

Block society deposits above a threshold:

beforeLoanApply / afterLoanApply

Payload: playerIdentifier, amount, duration, interestRate, paymentAmount, totalAmount, paymentFrequency, source. After hook adds loanId, loanStatus; result: { success, loanId, amount, paymentAmount, nextPaymentDate }

Log new loans:

beforeCardCreate / afterCardCreate

Payload: accountIban, playerIdentifier, displayName, color, source. After adds cardId, cardNumber. PIN and CVV never in payloads.

Block card creation for certain account types or players:

beforeAtmAuthorize / beforeAtmPinChange

Payload: cardNumber, accountIban, playerIdentifier, source. Raw PIN and new PIN never in payloads.

Block ATM access for specific cards (e.g. flagged accounts):

Last updated