Skip to content

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

lua
local ok, credited = exports.cc_government:Collect(sourceKey, amount, note)
ArgTypeNotes
sourceKeystringA key of ServerConfig.Sources that lists your resource.
amountinteger1 .. that source's maxPerCall. Money your script already took from a player.
notestring?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).

lua
-- my_dmv, after charging the player:
if exports.cc_government:Collect('licences', 1500, 'Driving test') then ... end

Levies: GetLevy, ApplyLevy

lua
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 yourself

ApplyLevy 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

lua
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

ExportReturns
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

lua
exports.cc_government:OpenBar()   -- open the bar desk page (the server still checks the distance)

Server events (TriggerEvent, server side only)

lua
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.

lua
exports.cc_government:registerHook('beforeFund', function(p)
    if p.department == 'police' and p.amount > 250000 then return false end   -- block big police transfers
end)
HookPayloadCancellableNotes
beforeLevyChangesource, key, valueyesBefore the mayor changes a levy.
beforeFundsource?, department, amountyesBefore a transfer (source is nil for the auto-float). Amount is not read back.
beforeHiresource, target, citizenid, gradeyesBefore a government hire.
beforeAnnouncesource, author, bodyyes, mutableYou may reword body; it is cleaned and length-checked again.
afterCollectkey, amount, invokernoMoney arrived through Collect.
officeActivitysourcenoA staff member worked at the office (paycheck activity gates).
licenceChangedcitizenid, status, hownoSame moment as the server event above.
electionCertifiedelectionId, citizenid, name, votesnoA 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):

lua
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):

lua
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')