Exports, events and hooks
Everything here is server side unless it says client. Calls that move money check the calling resource with GetInvokingResource(), so list your resource in server/config.lua first.
Everything here is server side unless it says client. Calls that move money check the calling resource with GetInvokingResource(), so list your resource in server/config.lua first.
Money in: Collect
local ok, credited = exports.cc_government:Collect(sourceKey, amount, note)| Arg | Type | Notes |
|---|---|---|
sourceKey | string | A key of ServerConfig.Sources that lists your resource. |
amount | integer | 1 .. that source's maxPerCall. Money your script already took from a player. |
note | string? | Shown in the ledger (cut to 160). |
Returns ok (false for an unknown key, an unlisted caller or a bad amount) and credited, what the treasury really took after maxBalance (the rest is logged as overflow).
-- my_dmv, after charging the player:
if exports.cc_government:Collect('licences', 1500, 'Driving test') then ... endLevies: GetLevy, ApplyLevy
local pct = exports.cc_government:GetLevy('registration') --> 110 (percent), or nil for an unknown key
local fee = exports.cc_government:ApplyLevy('registration', 2500) --> 2750 = floor(2500 * 110 / 100)
local rate = exports.cc_government:GetLevy('sales_tax') --> 3 (points); apply it yourselfApplyLevy multiplies only pct levies; a pts levy returns the base unchanged. Each read records your resource so the office shows "applied by my_dmv". Before the mayor changes anything, the default is returned.
Money out: PayService
local ok, err = exports.cc_government:PayService(key, source, amount, note)Pays an online player from the treasury for a service your resource verified (a published news story, a city contract). key must be in ServerConfig.Payouts with your resource listed. Capped per call, per rolling hour and day (for the whole key), never below the reserve; a failed bank add is put back. err is a locale key: gov.service_key|invoker|amount|player|hour_cap|day_cap|treasury|bank|busy.
Reads
| Export | Returns |
|---|---|
GetTreasuryBalance() | integer or nil |
GetTreasurySummary() | { balance, reserve, in24, out24 } |
IsMayor(source) | boolean |
GetGovernmentGrade(source) | integer or nil (not staff) |
GetMayor() | { cid, name } or nil |
HasLawyerLicence(source or citizenid) | true / false, or nil when the registry cannot be read (keep your own behaviour then) |
GetLawyerLicenceStatus(citizenid) | 'active', 'suspended', 'revoked', 'not_found', ... or nil |
BarStanding(citizenid) | the registry status, or the last one recorded here during an outage |
ActiveLawyerLicensees() | { [citizenid] = true } or nil |
BarView(source) | the bar desk view for a player (for your own City Hall portal or tablet) |
Client export
exports.cc_government:OpenBar() -- open the bar desk page (the server still checks the distance)Server events (TriggerEvent, server side only)
AddEventHandler('cc_government:licenceChanged', function(citizenid, status, how) end)
-- status: 'active' | 'suspended' | 'revoked' | 'expired' | ...; how: 'exam' | 'staff' | 'grandfather' | 'reinstated' | 'synced' | 'withdrawn'
AddEventHandler('cc_government:electionCertified', function(electionId, citizenid, name, votes) end)These are local server events: a client cannot trigger them.
Hooks
Register from your own resource; your handler runs inside pcall, is removed when your resource stops, and can only narrow what cc_government does, never widen it.
exports.cc_government:registerHook('beforeFund', function(p)
if p.department == 'police' and p.amount > 250000 then return false end -- block big police transfers
end)| Hook | Payload | Cancellable | Notes |
|---|---|---|---|
beforeLevyChange | source, key, value | yes | Before the mayor changes a levy. |
beforeFund | source?, department, amount | yes | Before a transfer (source is nil for the auto-float). Amount is not read back. |
beforeHire | source, target, citizenid, grade | yes | Before a government hire. |
beforeAnnounce | source, author, body | yes, mutable | You may reword body; it is cleaned and length-checked again. |
afterCollect | key, amount, invoker | no | Money arrived through Collect. |
officeActivity | source | no | A staff member worked at the office (paycheck activity gates). |
licenceChanged | citizenid, status, how | no | Same moment as the server event above. |
electionCertified | electionId, citizenid, name, votes | no | A mayor was installed by election. |
exports.cc_government:getHooks(), getApi() and getVersion() list all of this at runtime.
Recipes
Discord role for lawyers (your own bot bridge):
AddEventHandler('cc_government:licenceChanged', function(cid, status)
exports.my_discord:SetRole(cid, 'Lawyer', status == 'active')
end)Pay staff only when they work (with your paycheck script): ServerConfig.Integrations.officeActivity = { resource = 'my_paychecks', export = 'TouchActivity' }.
Business tax from the mayor's slider (in your business script):
local rate = exports.cc_government:GetLevy('business_tax') or 8 -- points
local tax = math.floor(profit * rate / 100)
exports.cc_government:Collect('other', tax, 'Business tax')