Skip to content

Exports, hooks and events

All server-side. Clients can call none of these.

All server-side. Clients can call none of these.

Exports (read)

lua
exports.cc_pcmining:GetPrice()                 --> number   LGC (coin 1) price in dollars
exports.cc_pcmining:GetCoinPrice(symbol)       --> number|nil  live price of a coin by symbol ('LGC', 'VSP', ...)
exports.cc_pcmining:GetWallet(src)             --> number   LGC in an online player's personal wallet
exports.cc_pcmining:GetBalances(src)           --> { [symbol] = number }  every coin an online player holds
exports.cc_pcmining:GetSoldToday(cid)          --> number   dollars this character's licence sold today
exports.cc_pcmining:GetSoldTodayLicence(lic)   --> number   dollars every character on this licence sold today

GetSoldToday / GetSoldTodayLicence exist so another passive-income resource can share one daily ceiling with this one (see ServerConfig.Sell.combined).

Hooks

Three ways in, all fed by the same calls:

  1. custom/server.lua — replace a function in the Custom table.
  2. Another resource — exports.cc_pcmining:RegisterHook(name, fn) returns an id; exports.cc_pcmining:RemoveHook(id) removes it. Hooks of a resource that stops are dropped.
  3. A server event — AddEventHandler('cc_pcmining:<name>', function(src, data) end) for the "on" hooks. These are fired with TriggerEvent (server-local): a client cannot fire them.

Before hooks: may refuse, cannot change

Return false to refuse; an optional second value is a locale key or text shown to the player. They can never change a price, an amount or an item: those come from server/config.lua.

Hookdata
canBuy{ item, qty, total } — a part at the shop
canSell{ coin, symbol, fraction } — a sale at the exchange (fraction of the balance)
canBuild{ tier, site, unit?, bay? } — placing a rig in a house (site = 'home') or racking it in a warehouse ('farm')
canRent{ bay, weeks, cost } — renting a warehouse

After hooks: told once it is paid and done

The return value is ignored. An error in your handler is logged and never undoes the action.

Hookdata
onBuy{ item, qty, total } or { build, qty, total } for a ready build / planner basket
onSell{ coin, symbol, amount, cash, price }
onBuild{ rig, tier, site }
onRent{ bay, weeks, cost }
onAction{ channel, title, fields, rig? } — every logged action (the same rows as the Discord and activity log)

Examples

lua
-- custom/server.lua: only players with the 'crypto' licence may sell
Custom.canSell = function(src, data)
    local ok = exports['my_licences']:Has(src, 'crypto')
    if not ok then return false, 'You need a crypto trading licence.' end
    return true
end

-- another resource: give XP for every sale
exports.cc_pcmining:RegisterHook('onSell', function(src, data)
    exports['my_xp']:Add(src, 'trading', math.floor(data.cash / 1000))
end)

-- a plain event: count rentals
AddEventHandler('cc_pcmining:onRent', function(src, data)
    print(('player %d rented warehouse %d for %d weeks'):format(src, data.bay, data.weeks))
end)

Bridges you can edit

FileFor
server/housing.luaHousing providers (Custom.housingUnit, Custom.housingCanBuild)
server/inventory.luaReading an unusual inventory's items and metadata
custom/client.luaClient flavour (sounds, emotes); it cannot grant or charge anything

Admin commands (ACE cc_pcmining.admin)

/pcmadmin opens the economy panel. Sub-commands: status, price [SYMBOL], pause, resume, pos, rigs, wipe (also needs cc_pcmining.wipe), units, enter, leave, log [filter], debug, calibrate [export [all]].