cc_jobcentre: exports, events and hooks (API reference)
Everything here is server-side. The client has no exports: the page and the client hold no authority, so there is nothing for another resource to call there.
Everything here is server-side. The client has no exports: the page and the client hold no authority, so there is nothing for another resource to call there.
Exports
local jc = exports.cc_jobcentreReading the board (read-only, every value is a copy)
| Export | Returns | Notes |
|---|---|---|
jc:isReady() | boolean | The board has been built from the config. Registrations are accepted before this too |
jc:getJobs() | table[] | The active board in display order. Each entry has the Config.Jobs fields |
jc:getJob(id) | table? | One active listing, or nil |
jc:getStartupCost(id) | { startup, reviewed }? | From ServerConfig.Costs or the registration |
jc:adviserReport() | table | Spend today, caps, where answers came from (desk / cached / model / refused / failed) |
jc:hasBoardOpen(src) | boolean | The player has the board open right now |
jc:getHooks(), jc:getApi(), jc:getVersion() | cc_lib's standard discovery exports |
There is no getEarnings: the office quotes no wages. A caller that wants to know what work pays asks the resource that pays it.
Listing your job from another resource
-- in your job script, server side
local function list()
exports.cc_jobcentre:registerJob({
id = 'mining', -- unique, lowercase
label = 'Quarry Miner',
category = 'handson', -- one of Config.Categories (else Config.Registry.fallbackCategory)
blurb = 'Break rock at the quarry and sell what you dig.',
where = 'The quarry office, north of Sandy Shores.',
coords = vec3(2953.9, 2789.6, 41.5),
applyVia = 'walk_in', -- walk_in | phone | hub | website | radio
needs = { { text = 'A pickaxe', item = 'pickaxe' }, 'A free afternoon' },
steps = { 'Talk to the foreman', 'Take a pickaxe from the rack', 'Mine the marked rocks' },
tips = { 'Ore sells for more at the smelter.' },
aliases = { 'mine', 'miner', 'quarry', 'ore' },
image = 'mining.webp', -- optional, a file in cc_jobcentre/web/assets/jobs/
startup = 2500, -- what it costs to get started (display only)
note = 'The pickaxe is sold at the quarry.',
})
end
AddEventHandler('cc_jobcentre:ready', list) -- cc_jobcentre (re)started after you
CreateThread(function() if GetResourceState('cc_jobcentre') == 'started' then list() end end)| Export | Returns | Notes |
|---|---|---|
jc:registerJob(def) | ok, reason | Validated with the same rules as Config.Jobs. The calling resource owns the listing; it goes when that resource stops. A config listing with the same id always wins |
jc:unregisterJob(id) | boolean | Removes a listing your resource registered |
Start-up loans (only while ServerConfig.Loans.enabled)
These are for the job script named as the loan's provider. A call from any other resource returns false.
| Export | Returns | When to call it |
|---|---|---|
jc:drawStartupLoan(src, jobId, price) | boolean | In your shop, when the player is short for the one start-up item. true = do not charge and hand the item over. price must be at most the loan's amount |
jc:cancelStartupLoan(src, jobId) | boolean | Your purchase failed after a draw (no room, item refused). Puts the offer back |
jc:reportLoanEarning(src, jobId, amount, account) | boolean | After every payout from your job, on frameworks without QBCore/Qbox's OnMoneyChange (ESX, ox_core, standalone). account is 'cash' or 'bank'. The loan's share is taken back from that account |
-- in your shop (server)
if not CC.money.canAfford(src, 'bank', price) then
if exports.cc_jobcentre:drawStartupLoan(src, 'mining', price) then
if not giveItem(src, 'mining_licence') then exports.cc_jobcentre:cancelStartupLoan(src, 'mining') end
return
end
return notify(src, 'You cannot afford it.')
endEvents
All are local (server-to-server or client-to-client). None is a net event, so no client can trigger one.
| Event | Side | Arguments | When |
|---|---|---|---|
cc_jobcentre:ready | server + client | version | The resource is up and takes registrations. Re-register on it |
cc_jobcentre:server:answered | server | src, kind, jobId | The adviser answered (kind = desk / cached / model) |
cc_jobcentre:server:boardChanged | server | count | The board changed (config load, a registration, a provider stopped) |
cc_jobcentre:opened | client | locationId | The board opened on this client |
cc_jobcentre:closed | client | The board closed |
Hooks
Register in custom/server.lua (outside escrow, survives updates) with CC.hooks.register(name, fn); it ships with commented examples. Every handler runs in pcall, and whatever it returns is re-validated: a hook can narrow what the script does, never widen it.
| Hook | Kind | Payload | What it can do |
|---|---|---|---|
jobFilter | mutable | source, job, visible | Set visible = false to hide a listing from one player (licence-gated trades, whitelists). It cannot add one |
beforeAsk | cancellable, mutable | source, question | Rewrite payload.question, or return false to drop it (the player gets the polite refusal) |
afterAnswer | informational | source, question, answer, kind | Log, count, react |
-- custom/server.lua: only show the lawyer listing to players holding the bar licence
CC.hooks.register('jobFilter', function(p)
if p.job == 'lawyer' and not CC.inventory.hasItem(p.source, 'bar_licence') then p.visible = false end
end)Net events (for reference: what the client may send)
Every one goes through CC.security.event / CC.callback.register with an argument spec, a cooldown and an open-session check at the office. The client sends ids, never values.
| Name | Arguments |
|---|---|
cc_jobcentre:board (callback) | locationId |
cc_jobcentre:ask | question (string, length-capped) |
cc_jobcentre:closed | |
cc_jobcentre:business (callback) | |
cc_jobcentre:biz:apply / :close | vacancyId |
cc_jobcentre:biz:post | businessId, grade, wage, title (all checked by cc_business) |
cc_jobcentre:biz:decide | appId, accept |
cc_jobcentre:loan:offer | jobId |
cc_jobcentre:selftestResult | two counts (admin only, log only) |