Exports & hooks ​
Nothing here needs np_faction as a hard dependency. Check GetResourceState('np_faction') == 'started' at call time
and wrap the calls in pcall. Exports answer nil / false / 0 / {} until np_faction has booted
(np_faction:ready); tables that leave np_faction are plain copies.
np_faction keeps the framework in sync: the active job and its duty flag are written through ESX setJob, qbx
AddPlayerToJob / SetPlayerPrimaryJob / SetJobDuty, qb Player.Functions.SetJob / SetJobDuty, so esx:setJob,
QBCore:Server:OnJobUpdate, QBCore:Client:OnJobUpdate and QBCore:Server:SetDuty keep firing for scripts that only
know the framework. On qbx every linked membership is also one of qbx's job groups (PlayerData.jobs), so HasGroup /
GetGroups and qbx_management see the same jobs.
np_faction decides duty (Config.Jobs.dutyAuthority, the default): characters log in off duty, and a framework duty
flag set by another script (QBCore:ToggleDuty, SetJobDuty, ESX setJob with onDuty) passes the same rules as
SetDuty and is written back when refused.
Arguments used below: target = a server id or a character identifier (offline works); faction = a faction id or a
framework job name (the same for linked factions); jobs = 'police' | { 'police', 'sheriff' } |
{ police = 2, sheriff = 0 } (minimum grade per job).
Server exports ​
exports.np_faction:<Name>(...). PascalCase = queries and commands, camelCase = extension registries.
Jobs and duty ​
| Export | Returns |
|---|---|
GetJob(src) |
The active job shape (below), the one mirrored into the framework, or nil |
GetJobs(target) |
Every job shape of the character, active first (multi-job and club memberships, plus a framework job np_faction has no faction for) |
HasJob(src, jobs, minGrade?, needDuty?) |
bool, jobShape? over all of the player's jobs; needDuty = true needs duty in that job; suspended memberships do not count |
IsOnDuty(src, faction?) |
bool; faction nil = the active job (a framework job np_faction has no faction for: the framework's flag) |
SetDuty(src, on, faction?) |
true | false, code (not_member, suspended, on_leave, duty_disabled, not_active_job, a beforeDuty veto) |
GetOnDuty(jobs) |
{ src, ... } on duty in any of jobs (at the minimum grade) |
CountOnDuty(jobs) |
number |
SetActiveJob(src, faction) |
true | false, code: switches the active framework job (on_duty, cooldown, not_linked, suspended, a beforeSwitch veto) |
Permissions ​
| Export | Returns |
|---|---|
Can(src, faction?, node) |
bool, limit?: the node from the player's grade and certifications in that faction (faction nil = the active job), e.g. bank.spend, bank.manage, members.hire, boss |
IsBoss(src, faction?) |
bool (node boss) |
GetNodes(faction?) |
The node catalogue { { group, label, icon, nodes = { { node, label, description?, limit? } } } } |
AddCertification(target, faction, cert, opts?) |
true | false, code; opts = { by?, days? | expires? } |
RemoveCertification(target, faction, cert, opts?) |
true | false, code |
HasCertification(target, faction, cert) |
bool |
Factions and members ​
| Export | Returns |
|---|---|
GetFaction(faction) |
{ id, label, short, type, tint, icon, link, job, hidden, grades = { [n] = { name, label, salary, boss } } } or nil |
GetFactions(filter?) |
{ <GetFaction shape> }, hidden ones flagged; filter = { type?, link?, hidden? } |
GetMembers(faction) |
{ { identifier, name, grade, gradeLabel, gradeName, boss, callsign, status, joined, lastSeen, online = src | nil, onduty, certs } } |
GetMember(target, faction?) |
The same shape for one member (faction nil = the active job), or nil |
SetJob(target, job, grade, opts?) |
true | false, code: the staff / admin path (np_admin's Set job). Works offline and for link none factions, makes a linked faction the active job, unemployed ends the active membership. No node, slot or hierarchy checks; opts.by = the staff member. Unknown job names: false, 'unknown_faction' |
Hire(target, faction, grade?, opts?) |
true | false, code; grade nil = the start grade. opts.by = src checks the actor's members.hire node and the hierarchy |
Fire(target, faction, opts?) |
true | false, code (last_boss, hierarchy, a beforeFire veto …); opts = { by?, reason? } |
SetGrade(target, faction, grade, opts?) |
true | false, code; opts.by checks members.promote (up to their own grade − 1) |
PostBoard(faction, post) |
Post id | false, code; post = { title, body?, pinned?, days?, minGrade?, icon?, author? }. Members online get a toast and an np_phone notification |
Money ​
| Export | Returns |
|---|---|
GetAccount(faction, purpose?) |
The account id (np_banking id, or ledger:<id>); purpose default 'operating'; nil without a money provider |
GetBalance(faction, purpose?) |
number |
AddMoney(faction, amount, reason, purpose?) |
true | false, code (no_bank while no money provider runs) |
RemoveMoney(faction, amount, reason, purpose?) |
true | false, code |
BankWithdraw(src, faction, amount, reason?, account?) |
true, { done = true, balance } | true, { pending = approvalId } | false, code: a withdrawal the player asked for (another boss menu, the compat shims). The HQ Bank path: membership, bank.withdraw, the grade's daily budget, two signatures above the threshold, the beforeWithdraw hook, frozen / restricted accounts and a per-player cooldown (Config.Bank.playerCooldownMs, code cooldown). Paid to Config.Bank.withdrawTo; account = a faction account id (nil = operating) |
BankDeposit(src, faction, amount, reason?, account?) |
true, { balance } | false, code: the player's Config.Bank.depositFrom money is taken first, then the faction is credited (refunded when that fails); bank.deposit node, same cooldown |
With np_banking running the operating account is np_banking's society account of the job, so
exports.np_banking:GetSocietyAccount(job), np_payments' payee { type = 'society', id = job } and these exports
reach the same money. purpose names an account: 'operating' (always there), 'payroll' (falls back to operating
while a faction has none) or any extra account ('evidence', 'budget' …). Codes: unknown_faction,
invalid_amount, insufficient_funds, account_frozen, no_account, bank_unavailable, no_bank. Every move is
written to the faction's audit log.
AddMoney / RemoveMoney are server-to-server and check nothing about a player. Anything a player triggers (a boss
menu button, a net event) belongs in BankWithdraw / BankDeposit, so budgets, signatures and hooks always apply.
-- a boss menu's withdraw button
local ok, res = exports.np_faction:BankWithdraw(src, 'mechanic', 2500, 'Parts')
if not ok then notify(src, res) -- 'cooldown', 'insufficient_funds', a hook's code ...
elseif res.pending then notify(src, 'Waiting for a second signature')
end
World and pay ​
| Export | Returns |
|---|---|
PayTask(src, faction, name, units?) |
true, amount | false, code: credits a registered task to the player's running shift, paid by the next payroll when the faction pays per task (task / mix). units multiplies the amount (1..maxUnits, default 100). Codes: unknown_task, wrong_faction, not_member, not_on_duty (unless needDuty = false: then paid at once), not_paid_per_task, cooldown |
GetPlaces(faction, type?) |
{ { id, type, label, station, coords, radius, faction } }, config and placed in game, shared places included |
GetFleetVehicle(plate | netId) |
{ id, faction, plate, label, model, state, holder, takeHome, class } of a fleet vehicle, or nil (key scripts, mechanics, impound lots) |
faction_tablet(event, item, inventory, slot) |
np_inventory's item callback for the tablet item (named after Config.Phone.tablet.item) |
Registries ​
Extension exports for other resources and np_faction addons. They are owner-tracked: whatever a resource registers is removed when that resource stops.
| Export | Returns |
|---|---|
addHook(name, fn) |
Hook id, or nil for an unknown hook / a non-function (Hooks) |
removeHook(id) |
true when the hook existed |
registerNode(factionOrType, node, def) |
true | false, code: adds a permission node to the editor's catalogue. factionOrType = '*', a type ('government') or a faction id; def = { label, group?, description?, limit? } or a label |
registerPayTask(name, def) |
true | false, code: a task the payroll pays for; def = { label, amount, faction? | type?, cooldown?, needDuty? = true, maxUnits? } |
registerPlaceType(type, def) |
true | false, code: a placeable point type; def = { label, icon, tint?, node?, radius?, boss? } (boss = true lets bosses place it). Using one fires np_faction:placeUsed |
-- a mechanic script: a node for the editor, a pay task and a place type
exports.np_faction:registerNode('business', 'mechanic.tune', { label = 'Tune vehicles', group = 'assets' })
exports.np_faction:registerPayTask('repair', { label = 'Repair', amount = 80, type = 'business', cooldown = 30, maxUnits = 5 })
exports.np_faction:registerPlaceType('tuning_bench', { label = 'Tuning bench', icon = 'gauge-high', node = 'mechanic.tune', boss = true })
AddEventHandler('np_faction:placeUsed', function(src, place, faction)
if place.type == 'tuning_bench' then openTuning(src, faction) end
end)
As an np_addon ​
np_faction is an np_addon host (Addons). An addon declares np_addon 'np_faction' in its manifest
and registers inside npAddon.attach('np_faction', fn, { api = 1 }), which runs again after a restart of either
resource. The host exports npAddonAttach(info) and npAddonList() belong to the lib; never call them by hand.
Hooks ​
local id = exports.np_faction:addHook('beforeHire', function(p)
if p.faction == 'police' and not exports.my_academy:Passed(p.identifier) then return false, 'academy_required' end
end)
| Name | Payload | Return |
|---|---|---|
beforeHire |
{ source?, faction, identifier, grade, by } |
false, 'code' cancels the hire |
beforeFire |
{ source?, faction, identifier, grade, by, reason? } |
false, 'code' cancels |
beforeGrade |
{ source?, faction, identifier, from, to, by } |
false, 'code' cancels the promotion / demotion |
beforeDuty |
{ source, faction, on } |
false, 'code' keeps the duty state |
beforeSwitch |
{ source, from, to } |
false, 'code' cancels the active-job switch |
beforeWithdraw |
{ source, faction, account, amount, reason? } |
false, 'code' cancels the withdrawal |
applicationCheck |
{ source, identifier, faction, mode = 'form' | 'apply' | 'join' } |
false, 'code' fails the background check (an MDT: false, 'active_warrants'); the reviewers see the code's text |
Staff paths (SetJob, np_admin actions) and changes adopted from the framework skip the hooks.
Client exports ​
Read from the replicated state bag npFaction merged with the owner-only part np_faction sends to that player alone
(hidden memberships, nodes, a pending offer), so the own character's exports see every job. No server round trip; UI
hints only, the server decides every action again.
| Export | Returns |
|---|---|
GetJob() |
The active job shape, or nil |
GetJobs() |
Every job shape the character holds, active first |
IsOnDuty(faction?) |
true while on duty (in the active job, or in that faction) |
HasJob(jobs, minGrade?, needDuty?) |
bool, jobShape?, same forms as the server export |
Can(faction?, node) |
bool, limit? from the owner-only nodes (wildcards members.*, *; the most specific entry decides, an explicit false denies, like the server) |
Job shape ​
{ name = 'police', label = 'LSPD', grade = 5, gradeName = 'sergeant2', gradeLabel = 'Sergeant II',
isBoss = false, isboss = false, onduty = true, onDuty = true, faction = 'police',
type = 'government' | 'business' | 'organisation' | 'club', link = 'mirror' | 'create' | 'none',
callsign = '2-ADAM-14' | nil, status = 'active' | 'probation' | 'leave' | 'suspended', active = true | false }
Both key spellings on purpose: np_banking reads isBoss / gradeName, np_payments isboss / gradeLabel, ESX
scripts onDuty, qb scripts onduty. name is the framework job name (the faction id for link none). A framework
job np_faction has no faction for is still returned (without callsign / status), so GetJob never hides a job.