Exports & hooks
Server and client exports, hooks, outbound events and the custom/ files.
Back to the overview. Everything here is server-trusted: a client can never call a server export or a hook. A hook can narrow what the job does (block it, lower a value), never grant more than the job would have.
Server exports
exports.cc_mowing:isWorking(src) --> boolean
exports.cc_mowing:getLevel(src) --> integer | nil
exports.cc_mowing:getJob(src) --> table | nil
exports.cc_mowing:getWorker(identifier) --> table | nil
exports.cc_mowing:getActiveWorkers() --> integer[]
exports.cc_mowing:getCompany(src) --> table | nil
exports.cc_mowing:addXp(src, amount) --> boolean
exports.cc_mowing:endJob(src, reason, refund) --> boolean| Export | Arguments | Returns |
|---|---|---|
isWorking(src) | server id | true while the player is on a contract, as leader or crew member |
getLevel(src) | server id | The worker's level, or nil if they have not been loaded this session |
getJob(src) | server id | { contract, stage, property, properties } for a leader's live contract, or nil. stage is 'travel', 'mowing' or 'returning'. |
getWorker(identifier) | character identifier | { level, xp, earnings, jobs } for a loaded worker, or nil |
getActiveWorkers() | none | Server ids of every player on a contract (leaders, then their crew) |
getCompany(src) | server id | { id, name, level, rank } (rank 1 worker, 2 manager, 3 owner), or nil |
addXp(src, amount) | server id, number | Grants XP, floored and capped at ServerConfig.Exports.maxXpGrant (5,000). false for a junk or negative amount or an unknown player. Logged to the admin channel with the calling resource. Never moves money. |
endJob(src, reason, refund) | server id, short string, boolean | Ends a leader's contract with no pay (the deposit comes back only with refund = true), or takes a crew member off the crew. false if the player is not working. |
registerHook(name, fn) / removeHook(id) | see below | A hook id |
getVersion() / getApi() / getHooks() | none | The version, the export list, and the hook list with their payloads |
Example: hide a radial menu entry while working.
if exports.cc_mowing:isWorking(source) then return endClient exports
| Export | Returns |
|---|---|
exports.cc_mowing:isWorking() | true while this player is on a contract |
exports.cc_mowing:getStage() | 'travel', 'mowing' or 'returning' while working, else nil |
Hooks
Register from your own resource, or from custom/server.lua. A handler gets one payload table. Return false from a cancellable hook to stop the action. Change a field of a mutable hook's payload to change the value; the job checks it again afterwards and keeps it only if it is lower.
| Hook | Kind | Payload | When |
|---|---|---|---|
beforeJobStart | cancellable | source, contract | Before the deposit is taken |
afterJobStart | info | source, contract, properties | The kit is out |
ratingFilter | mutable (lower only) | source, property, stars, request, honoured | A lawn is being scored |
afterProperty | info | source, property, stars | A customer signed a lawn off |
payFilter | cancellable, mutable (lower only) | source, identifier, contract, properties, stars, amount | Before the contract pays |
afterJobFinish | info | source, contract, amount | The contract has paid |
beforeUpgrade | cancellable | source, upgrade, tier, price, fleet | Before a Garage or company-fleet upgrade is charged |
-- Only players with the 'gardener' job may take contracts.
exports.cc_mowing:registerHook('beforeJobStart', function(p)
return CC.framework.hasJob(p.source, { 'gardener' })
end)
-- A 10% tax on every contract.
exports.cc_mowing:registerHook('payFilter', function(p)
p.amount = math.floor(p.amount * 0.9)
end)
-- The top ute tier needs a commercial licence.
exports.cc_mowing:registerHook('beforeUpgrade', function(p)
if p.upgrade == 'ute' and p.tier >= 4 then
return exports['my-licences']:has(p.source, 'commercial')
end
end)Outbound server events
Fired with TriggerEvent on the server, for your own logs, phone apps and integrations. Listen with AddEventHandler; they never come from a client.
| Event | Arguments |
|---|---|
cc_mowing:server:jobStarted | source, contractId, propertyCount |
cc_mowing:server:propertyDone | source, propertyId, stars |
cc_mowing:server:jobFinished | source, contractId, amountPaid |
cc_mowing:server:levelUp | source (may be nil), identifier, newLevel, oldLevel |
cc_mowing:server:goalDone | source, kind ('achievement' or 'daily'), goalId |
cc_mowing:server:upgradeBought | source, upgradeId, tier, price, fleet |
AddEventHandler('cc_mowing:server:levelUp', function(src, identifier, level)
if src and level % 10 == 0 then
TriggerClientEvent('chat:addMessage', -1, { args = { 'Lawn care', ('%s reached level %d'):format(GetPlayerName(src), level) } })
end
end)Where the money goes
- Wages are created by the server, or paid out of a society account with
ServerConfig.Pay.society.enabled = true. - Garage and fleet purchases leave the economy by default. Set
ServerConfig.UpgradeSink.society = 'government'(any society your banking script knows) to pay them into that account instead, or listen tocc_mowing:server:upgradeBoughtand route them yourself. - Every money move writes a line to the
economywebhook channel and tocc_mowing_ledger.
The custom/ files
custom/server.lua and custom/client.lua are yours. They are not escrowed and an update never overwrites them (keep your copy when you replace the folder). Both ship with commented examples.