DirkScripts
Docs
Cache
dirk_lib keeps a client-side cache for frequently accessed values and emits change events when values update.
#Accessing Cache
#cache.<key>
lualocal ped = cache.ped local vehicle = cache.vehicle local loaded = cache.playerLoaded
#lib.cache(key)
lualocal job = lib.cache('job')
#lib.onCache(key, cb)
Registers a change listener and immediately invokes the callback with the current value.
lualib.onCache('cuffed', function(isCuffed, oldValue) print(('Now cuffed: %s (was %s)'):format(isCuffed, oldValue)) end)
Equivalent low-level event:
luaAddEventHandler('dirk_lib:cache:cuffed', function(newValue, oldValue) -- ... end)
#Cache Keys (Client)
| Key | Type | Description |
|---|---|---|
resource | string | Current resource name |
game | string | Game name (fivem / redm) |
playerId | number | Result of PlayerId() |
serverId | number | Current player server ID |
ped | number | Current player ped entity |
vehicle | number | false | Vehicle entity if in vehicle; otherwise false |
seat | number | false | Current seat index; otherwise false |
driver | boolean | true when seat is -1 |
weapon | number | false | Current weapon hash when armed; otherwise false |
mount | number | false | RedM only: current mount entity or false |
dead | boolean | Framework/game state death flag |
cuffed | boolean | nil | Framework-specific cuff state |
job | table | Parsed framework job object (see formats below) |
gang | table | nil | QB/QBX gang payload |
citizenId | string | nil | Character identifier (citizenid or identifier) |
charName | string | nil | Character full name |
playerLoaded | boolean | Whether character/player has loaded |
⚠️ cache.playerData is not a cache key in current dirk_lib source.
#Job Object Format
The job cache shape is built in framework cache adapters (not from dirk_lib/types/job).
#QB / QBX job shape
lua{ name = string, type = string, label = string, grade = number, -- job.grade.level isBoss = boolean, bankAuth = any, gradeLabel = string, -- job.grade.name duty = boolean, -- job.onduty }
#ESX job shape
lua{ name = string, type = string, label = string, grade = number, -- job.grade isBoss = boolean, bankAuth = any, gradeLabel = string, -- job.grade_label duty = boolean, -- job.onduty }
#Logged-out QB/QBX fallback
On player unload, job is set to:
lua{ name = 'logged_off', grade = 2, onduty = false }
#Framework-Dependent Notes
dead,cuffed,job,citizenId,charName, andplayerLoadedare framework-populated.gangis currently populated in QB/QBX adapters.mountis populated only on RedM.
#Change Semantics
Cache writes use deep comparison for tables and emit dirk_lib:cache:<key> only when values actually change.
