Exports, hooks and events
Everything here is server-side. All of it is read-only or narrowing: no export, hook or event lets another resource give items or money through this script.
Everything here is server-side. All of it is read-only or narrowing: no export, hook or event lets another resource give items or money through this script.
Exports
local dumpster = exports.cc_dumpster| Export | Arguments | Returns | Notes |
|---|---|---|---|
getLevel(src) | player server id | integer | Scavenger level. 1 when the player is unknown or offline |
getStats(src) | player server id | table | nil | { level, xp, searches, finds, rares, injuries, earned, best, perks }, the same snapshot the panel shows |
isHidden(src) | player server id | boolean | Is the player hiding in a dumpster right now? |
isSearching(src) | player server id | boolean | Is the player mid-search? |
forceOut(src) | player server id | nothing | Puts a hidden player out. Use it from your own police search or jail script |
countPicked() | none | integer | How many dumpsters are picked (empty) right now |
getVersion() | none | string | Resource version, published through cc_lib |
getApi() | none | table | Description of the exports and hooks, published through cc_lib |
registerHook(name, fn) | hook name, function | handle | See Hooks |
The 1.0 names still work: GetScavengerLevel(src), IsHidden(src) and ForceOutOfDumpster(src).
-- example: block searching for on-duty police
if exports.cc_dumpster:isSearching(src) then return end
local level = exports.cc_dumpster:getLevel(src)State bag
Player(src).state.cc_dumpster_hidden is true while the player is hiding. Only the server writes it, so your MDT, HUD or anticheat can read it on either side.
Hooks
Register a hook from your own resource. Your handler runs inside pcall, so a bug in it can never break a search. Hooks narrow what the server was going to do and never widen it. The server re-caps every value after your hook runs: finds can be removed or reduced but not added, and prices and payouts can only go down.
exports.cc_dumpster:registerHook('canSearch', function(p)
if exports.my_jobs:isOnDuty(p.source) then
return false -- refuse this search
end
end)
exports.cc_dumpster:registerHook('filterFinds', function(p)
for i = #p.finds, 1, -1 do
if p.finds[i].item == 'rolex' then table.remove(p.finds, i) end -- remove
end
end)| Hook | Can cancel | Can change | Payload |
|---|---|---|---|
canSearch | yes | source, kind, coords, level | |
filterFinds | finds (remove or reduce only) | source, kind, area, level, finds[{ item, count, tier }] | |
afterSearch | source, kind, area, level, xp, hazard, finds, dropped | ||
canHide | yes | source, coords | |
beforeSell | yes | multiplier (0 to 1) | source, multiplier |
afterSell | source, paid, sold[{ item, count, total }] | ||
beforeBuy | yes | price (down only) | source, index, item, count, price |
beforeWallet | yes | cash (down only) | source, cash |
afterWallet | source, cash, bonus |
Return false from a cancellable hook to refuse the action. The player sees a short "not right now" message.
Events (server, outbound)
Listen with AddEventHandler (not RegisterNetEvent: these never come from a client):
AddEventHandler('cc_dumpster:server:searchCompleted', function(src, data) end)| Event | data |
|---|---|
cc_dumpster:server:searchCompleted | kind, finds, dropped, hazard, level, xp, area, coords |
cc_dumpster:server:junkSold | paid, sold |
cc_dumpster:server:itemBought | item, count, price |
cc_dumpster:server:walletOpened | cash, bonus |
cc_dumpster:server:hidden | coords |
cc_dumpster:server:hiderFound | by, coords |
cc_dumpster:ready | version (no src) |
custom/server.lua
If you would rather not write a second resource, use custom/server.lua. It is not escrowed and loads last:
function Custom.onSearch(src, result)
-- result = { kind, finds, dropped, hazard, level, xp, area, coords }
endAdmin command
/dumpsteradmin needs the ACE cc_dumpster.admin:
| Command | What it does |
|---|---|
/dumpsteradmin | Status: how many dumpsters are picked right now |
/dumpsteradmin refill | Refill every dumpster now |
/dumpsteradmin xp <id> <amount> | Add XP to a player |
/dumpsteradmin setxp <id> <xp> | Set a player's XP |
Net events (for reference)
These are the only events a client can send. Each one goes through cc_lib's CC.security.event, which checks the argument types, a cooldown, one request in flight, and whether the player is alive, uncuffed and on foot. You never call them yourself.
| Event | Arguments | Checked |
|---|---|---|
cc_dumpster:search:start | pos, model | Reach from the server's own player position, model is a configured dumpster or bin, cooldown, hourly, new-spot and density caps, shared claim |
cc_dumpster:search:finish | ticket, careful | Single-use ticket, server time floor, finish reach |
cc_dumpster:search:cancel | ticket | The ticket must be the player's own |
cc_dumpster:hide:enter / hide:exit | pos / none | Reach, one hider, the canHide hook |
cc_dumpster:hide:check | pos | Police job, reach |
cc_dumpster:recycler:sell | none | Distance to the recycler, hourly cash cap |
cc_dumpster:recycler:buy | shop line index | Index range, distance, canCarry before charging, refund on failure |