Skip to content

Exports & hooks ​

What other resources may rely on. All exports are server-side unless marked client, called as exports.np_gangs:<name>(...). They answer nil / false / 0 / {} until np_gangs is ready (np_gangs:server:ready), and every table they return is a plain copy.

Server exports ​

server

Export Returns
GetGang(src | identifier) { id, name, tag, color, print, rank = 'og' | 'trusted' | 'member' } or nil
GetGangById(id) { id, name, tag, color, print, og, members = { { identifier, rank, name } }, turfs = { turfId }, stashout, status } or nil
IsBandanaOn(src) boolean. True only for a member wearing their own gang's bandana (or anyone wearing one when Config.Bandana.strangersCanWear is on)
GetBandanaGang(src) Gang id of the bandana being worn, or nil
GetTurfAt(coords) { id, name, holder, color, contested, noGang } or nil (released turfs only). holder is a gang id or nil; noGang marks an area nobody can hold
GetTurf(id) The turf record: the fields of GetTurfAt plus polygon, pickPrice, policeAttention, inPool, released, takeover, heldSince, meta, shops, walls, corners, grip = { [gangId] = 0..100 }
GetTurfs() All released turfs: the fields of GetTurfAt plus polygon
GetGrip(turfId, gangId) 0..100
AddGrip(turfId, gangId, amount, reason) New grip (clamped to 0..100), or nil for an unknown turf / gang. Written to the gang's ledger from 1 point on
AddPoliceAttention(turfId, amount, reason) New value (clamped to Config.Police.attention), or nil
GetStashInventory(gangId) Inventory id of the gang's back room, or nil (no stashout, or an inventory without stashes). There is one inventory per protected shop, so the id changes when the stashout is switched
Notify(gangId, data, opts) Sends a toast to members, returns how many were reached. See below
ReportShopRobbery(coords | src, robberSrc?) Tells np_gangs a shop was robbed. See below
registerHook(name, fn) Hook id, or nil for an unknown name. See Hooks
removeHook(id) boolean

The items the inventory bridges register also get a lower-case use export (gang_bandana, lester_note) for ox_inventory's server.export (Items); don't call them yourself.

Client exports ​

client

Export Returns
IsBandanaOn() boolean
GetGang() { id, name, tag, color, print, rank } or nil
GetCurrentTurf() { id, name, relation?, color?, contested? } or nil. relation, color and contested are only known while the player wears their colours

Notify ​

lua
local reached = exports.np_gangs:Notify(gangId, data, opts)
Field
data { type, title, message, icon?, tint?, duration?, waypoint? }. waypoint sets a waypoint for the members who get it
opts.bandanaOnly true (default): only members wearing the bandana
opts.rank Only this rank and above ('trusted', 'og')
opts.except A server id to leave out
opts.offlineText Text Lester sends to members who are offline (np_phone, else shown at the next login). Never put a location in it
lua
-- tell the gang that holds a turf that a raid is coming, without saying who sent it
local turf = exports.np_gangs:GetTurfAt(coords)
if turf and turf.holder then
  exports.np_gangs:Notify(turf.holder, { type = 'warning', title = 'Word on the street', message = 'Lots of blue lights tonight.' })
end

ReportShopRobbery ​

lua
exports.np_gangs:ReportShopRobbery(coords | src, robberSrc?)

Tells np_gangs that a shop was robbed at that place (or where that player stands). The protected shop within Config.Protection.robbery.radius (30 m) loses mood and part of the money waiting, and its gang is alerted with the robber's colour if they wore one. One report per shop per Config.Protection.robbery.cooldownMinutes (30). Returns the shop id or false.

np_gangs already listens to np_shops:server:robbed, esx_holdup:robberyStarted and qb-storerobbery:server:takeMoney; add your script's event to Config.Protection.robbery.events or call the export.

lua
-- your shop robbery script, when the register is emptied
exports.np_gangs:ReportShopRobbery(source, source)

Hooks ​

lua
local id = exports.np_gangs:registerHook(name, fn)
exports.np_gangs:removeHook(id)

Hooks run synchronously in registration order; returning false, reason vetoes. A hook that errors is skipped and logged. The hooks of a resource are removed when it stops. Hook payloads carry gang and turf as ids.

Name Payload Return
beforeAction { source, gang, action, turf, target } for the street actions spray, paintOver, rob (target = the victim's server id), takeBandana (target = the downed player), collect, lean, corner, openStash (target = shop / wall / point id) false, reason to veto
eligibility { source, identifier } when Lester checks a founder false, reason to refuse
gangName { source, identifier, name, tag } before a gang name is put forward (creation, renaming) false, reason to refuse the name
lua
-- no gang business in the hospital
exports.np_gangs:registerHook('beforeAction', function(p)
  if p.turf == 'pillbox' then return false, 'Not here' end
end)

-- only whitelisted players may found a gang
exports.np_gangs:registerHook('eligibility', function(p)
  if not exports.my_whitelist:IsGangWhitelisted(p.identifier) then return false, 'Not whitelisted' end
end)

-- names your staff never want to see
exports.np_gangs:registerHook('gangName', function(p)
  if p.name:lower():find('police') then return false, 'Pick another name' end
end)

Server events are on Events, commands & keys.