Skip to content

cc_crafting: exports, events and hooks

Back to the overview. Every export is server-side. srcOrCitizenId takes a player's server id or a character id.

Back to the overview. Every export is server-side. srcOrCitizenId takes a player's server id or a character id.

#

Exports (server)

lua
exports.cc_crafting:getProgress(srcOrCitizenId)   -- { processing = bar, fabrication = bar }; bar = { tier, xp, floor, next, max }
exports.cc_crafting:getTier(srcOrCitizenId, track) -- 1..5, track = 'processing' | 'fabrication'
exports.cc_crafting:addXp(srcOrCitizenId, track, amount, reason) -- new tier or nil; capped, logged
exports.cc_crafting:getOpenJobs(srcOrCitizenId)   -- copies: { id, kind, station, recipe, batch, startedAt, readyAt, expressed, outputs }
exports.cc_crafting:hasFacilityAccess(src)        -- card + Facility.minTier
exports.cc_crafting:giveCard(src, reason)         -- one access card; logged
exports.cc_crafting:getRecipes()                  -- the public recipe list
exports.cc_crafting:getRecipe(id)                 -- one recipe's server data (copy): { id, kind, tier, seconds, inputs, outputs }
exports.cc_crafting:isReady()                     -- boot finished (config valid, schema installed)
exports.cc_crafting:getStations()                 -- { id, kind, coords }
exports.cc_crafting:getVersion() / getApi() / getHooks()

Outbound events (server only, AddEventHandler)

EventPayload
cc_crafting:server:jobStarted{ source, citizenid, job, station, kind, recipe, batch, seconds, readyAt }
cc_crafting:server:jobCollected{ source, citizenid, job, station, kind, recipe, batch, outputs, xp, track }
cc_crafting:server:jobCancelled{ source, citizenid, job, station, recipe, loss, refund, lost }
cc_crafting:server:jobExpressed{ source, citizenid, job, recipe, fee, account, readyAt }
cc_crafting:server:recycled{ source, citizenid, station, recipe, times, taken, given, cash }
cc_crafting:server:facilityEnter / facilityExit{ source, citizenid, spawn } (use these with Facility.teleport = false)
cc_crafting:server:cardIssued{ source, citizenid, fee, replacement }
cc_crafting:server:log(channel, title, source, fields) for every log entry: feed your own log stack
cc_crafting:readythe API is published

Hooks

lua
exports.cc_crafting:registerHook('canStart', function(p)
    if p.kind == 'armory' and not myWhitelist(p.citizenid) then return false end
end)
exports.cc_crafting:registerHook('jobSeconds', function(seconds, ctx)
    if isVip(ctx.source) then return seconds * 0.9 end
end)
HookKindArgumentsNotes
canStartcancellablesource, citizenid, station, kind, recipe, batchbefore inputs are taken
canRecyclecancellablesource, citizenid, station, recipe, times
canEnterFacilitycancellablesource, citizenidafter the card and tier checks
jobSecondsfilterseconds; { source, citizenid, recipe, kind, batch }clamped to Queue.minSeconds .. the kind's cap
expressFeefilterfee; { citizenid, job, recipe, batch }at least $1
tierfiltertier; { citizenid, track, xp }clamped to 1..5: source tiers from your own progression
gangSpeedfiltermult; { gang }clamped to Gang.minMult..maxMult

Hooks narrow or adjust what the resource already allows; every adjusted number is clamped.

custom/

custom/client.lua and custom/server.lua load last and stay open under escrow, for small additions without a second resource. Never grant items from there.

Examples

lua
-- A quest that rewards fabrication rep:
exports.cc_crafting:addXp(source, 'fabrication', 50, 'quest: first rifle')

-- Show a recipe's inputs on a tablet:
local r = exports.cc_crafting:getRecipe('lockpick')
if r then for _, v in ipairs(r.inputs) do print(v[1], v[2]) end end

-- React when a job is collected:
AddEventHandler('cc_crafting:server:jobCollected', function(e)
    if e.kind == 'armory' then print(e.citizenid, 'collected', e.recipe) end
end)

-- Call cc_crafting only once it is up:
AddEventHandler('cc_crafting:ready', function() print(exports.cc_crafting:isReady()) end)