Events & state bags ​
Server events ​
Server-local (AddEventHandler), never sent over the network. target = the server id while the character is online,
else the identifier.
| Event | Arguments |
|---|---|
np_faction:ready |
None: np_faction booted, the exports answer, the players already online are loaded (state bags written). Never fires when a core store could not be loaded (the boot aborts) |
np_faction:jobChanged |
src, newJob, oldJob (job shapes, either may be nil): the active job changed (hire, fire, grade, switch, duty, callsign, a framework change). Also on character load (src, job, nil, when the character has a job) and on unload, logout or a character switch (src, nil, oldJob) |
np_faction:dutyChanged |
src, faction, onduty |
np_faction:hired |
target, faction, grade, info (info = { identifier, source?, by?, reason?, name? }) |
np_faction:fired |
target, faction, grade, info |
np_faction:gradeChanged |
target, faction, newGrade, oldGrade, info |
np_faction:shiftEnded |
target, faction, info (info = { identifier, source?, id, seconds, afk, reason, unit?, callsign?, started, ended, name }): a shift ended (clock out, auto off for AFK / zone / max length, disconnect) |
np_faction:placeUsed |
src, place, faction: a place of a registered type was used; place = { id, type, label, faction, coords, data } |
np_faction:vehicleSpawned |
src, netId, plate, faction, info (info = { id, model, label, identifier, class, takeHome }): a fleet vehicle was taken out. Hand out keys here |
np_faction:vehicleStored |
src, plate, faction, info (info = { id, fuel, engine, repairs }) |
lua
AddEventHandler('np_faction:vehicleSpawned', function(src, netId, plate)
exports.my_keys:GiveKeys(src, plate)
end)
Client events ​
AddEventHandler on the client, sent only to that player:
| Event | Arguments |
|---|---|
np_faction:client:jobChanged |
job | false (the new active job shape) |
np_faction:client:dutyChanged |
faction, onduty |
Net event ​
TriggerServerEvent('np_faction:toggleDuty') (no arguments) toggles the caller's duty in the active job. np_menu's F1
duty switch and /jobduty use it.
Commands and keys ​
| Command | Does |
|---|---|
/faction [id] |
The Faction HQ of the active (or that) faction (Config.Commands.hq) |
/jobduty |
Toggles duty of the active job (Config.Commands.duty) |
/factionapp |
The tablet (the phone app's pages) when np_phone is not running; also a key mapping (unbound by default) and the faction_tablet item (Config.Phone.tablet) |
/factionadmin |
The staff editor (Config.Staff.command, staff node np_faction.editor) |
false instead of a name turns a command off.
State bags ​
| Bag | Value |
|---|---|
Player(src).state.npFaction |
{ active = <job shape> | false, jobs = { <job shape> }, onduty = bool } (replicated, readable by every client). Memberships of hidden factions are left out of jobs (the active job stays: the framework job is public anyway). Cleared to { active = false, jobs = {}, onduty = false } when the character unloads |
GlobalState['npFaction:factions'] |
{ { id, label, short, type, tint, icon, link } }, the public faction list (hidden factions left out) |
Player(src).state.npFactionJob |
Standalone only: the job np_faction keeps instead of a framework |
Entity(vehicle).state.vehicleOrganizationId |
The faction id of a fleet vehicle (np_manufacturing reads it) |
Entity(vehicle).state.npFactionVehicle |
{ id, faction, plate, label, livery, extras, fuel, engine, body, callsign } of a fleet vehicle (replicated, set at spawn). Info only: np_faction never reads it back; the server keeps its own table of which entity is which fleet vehicle (GetFleetVehicle) |
The owner of a character gets the rest in a separate event sent to that player alone: hidden memberships, the
permission nodes per faction and a pending hire offer. np_faction's client exports merge
both, so on the own client GetJobs() and Can() see everything, while other clients only see the public bag.
lua
-- client: a job chip that follows np_faction
AddStateBagChangeHandler('npFaction', ('player:%s'):format(GetPlayerServerId(PlayerId())), function(_, _, value)
local job = value and value.active
if job then print(job.label, job.gradeLabel, job.onduty and 'on duty' or 'off duty') end
end)