Skip to content

cc_tradie API: exports, events and hooks

Everything another resource (or your custom/ files) can use. All of it is server side unless marked client. Nothing here can create money or items: exports read, the one action (addXp) grants XP only,

Everything another resource (or your custom/ files) can use. All of it is server side unless marked client. Nothing here can create money or items: exports read, the one action (addXp) grants XP only, and hooks can only narrow what the job was already going to do.

Server exports

Call them as exports.cc_tradie:(...).

ExportArgumentsReturns
isOnShift(src)player server idboolean
getRank(src)player server id{ level, label, xp } (level 1 for an unknown player)
getXp(src)player server idinteger, 0 when the profile is not loaded
ownsJackhammer(src)player server idboolean
getCrew(src)player server id{ leader, members = { ids }, site } or nil when not in a crew. site is the contract's site name or nil
getShift(src)player server id{ holes, finds, chest, personal, startedAt } or nil when off shift. chest = slots in use, personal = holes toward the current contract
addXp(src, amount)id, 0–100000boolean. Adds XP (a training course, an event). The pay/XP boost applies when enabled
getVersion()—the resource version string
getApi()—a table describing this API (from cc_lib's CC.api.publish)
getHooks()—the hook names below
registerHook(name, fn)hook name, functiona handle for removeHook
removeHook(handle)the handleboolean
lua
-- Give 250 tradie XP for finishing a safety course in your own resource
if exports.cc_tradie:isOnShift(src) then
    exports.cc_tradie:addXp(src, 250)
end

Server events

Listen with AddEventHandler('cc_tradie:server:', function(src, data) end). They are local server events (never net events), fired after the action happened. Or define Custom. = function(src, data) end in custom/server.lua.

EventWhendata
shiftStarteda worker clocked onshift summary
shiftEndeda worker clocked off, dropped, or the resource stoppedshift stats
holeDrilleda hole was finished{ site, results, holes }
findStoreda find went into the chest (or pockets){ item, count, runId? }
wagePaida site wage was paid{ amount, capped }
chestUnloadeda tool chest was unloaded at the depotunload result (delivered, lost)
cargoForfeiteda chest was lost (truck wrecked, clocked off away, drop, restart){ runId, ... }
workOrderFinishedevery chest in a crew is empty after a contract{ site, holes, ... }
rankUpa worker reached a new rank{ level, label }
jackhammerBoughta jackhammer was boughtpurchase details
upgradeBoughtan upgrade tier or chest tier was boughtpurchase details
lua
AddEventHandler('cc_tradie:server:rankUp', function(src, data)
    print(('%s is now a %s'):format(GetPlayerName(src), data.label))
end)

Client events

Listen in any client script, or in custom/client.lua. Display only: the server has already decided.

EventArgument
cc_tradie:client:shifton (boolean)
cc_tradie:client:holeResultresult (ok, results, xp, rankUp, done, target, ...)
cc_tradie:client:unloadedresult (delivered and lost stacks)

Hooks

Register in custom/server.lua with CC.hooks.register(name, fn), or from another resource with exports.cc_tradie:registerHook(name, fn). A hook receives a payload table.

  • Return false to refuse (for the can* hooks).
  • Change a number in payload to lower it. The resource re-checks every value: a hook can never raise a price discount below zero, a wage, a find, XP or a loss chance above what the code was already going to do.
  • A hook that errors is logged and ignored.
HookPayloadWhat you can do
canClockInsourcereturn false to refuse
canAcceptContractsource, site, holesreturn false to refuse
canDrillsource, sitereturn false to refuse
drillRewardsource, site, kind ('item' / 'wage' / 'xp' / 'none'), item, count, amount, xplower count, amount or xp
beforePurchasesource, kind, ref, pricereturn false to refuse, or lower price
cargoLosssource, condition, lossChancelower lossChance
lua
-- custom/server.lua: no wages on the training site
CC.hooks.register('drillReward', function(payload)
    if payload.site == 'zone_951' and payload.kind == 'wage' then payload.amount = 0 end
end)

-- only workers with the ACE "tradie.night" may clock on at night
CC.hooks.register('canClockIn', function(payload)
    local hour = tonumber(os.date('%H'))
    if (hour < 6 or hour >= 22) and not IsPlayerAceAllowed(payload.source, 'tradie.night') then
        return false
    end
end)

Commands

CommandWho
/tradieeveryoneopen the board (at the depot, or while on shift)
/jhinfoeveryonethe board on the Equipment tab
/jhservice chisel|filter|oileveryoneservice a part with a spare
/tradieadminACE cc_tradie.adminthe staff recovery panel
/tradierun TR-00000012ACEprint a run
/tradierestore TR-00000012 [note]ACEgive a forfeited run's cargo back (player online)
/tradieupgrade <id or char id> chisel|regulator|air|hammer <1-3>ACEset an upgrade tier
/tradieimport [run]ACE / consoleimport acc_tradie data (dry run unless run)

Every name is changeable in Config.Commands.

Logs

Through cc_lib's logger (console always; Discord when a webhook convar is set; Fivemanage or the cc_lib:log event when cc_lib is set up for them):

ChannelConvarWhat
economycc_tradie:webhook_economypurchases, upgrades, chest tiers, wages, refunds, item rollbacks
drillscc_tradie:webhook_drillsholes, batched per player
cargocc_tradie:webhook_cargotruck issued / returned / destroyed, unloads, losses, forfeits, restores
admincc_tradie:webhook_adminevery staff action and import
securitycc_tradie:webhook_securityevery anti-cheat flag, collapsed per minute

Use set (never setr) for webhooks: setr sends them to every player.