DirkScripts Logo

Login With FiveM

Login

Cache

dirk_lib keeps a client-side cache for frequently accessed values and emits change events when values update.

Accessing Cache

cache.<key>

lua
local ped = cache.ped
local vehicle = cache.vehicle
local loaded = cache.playerLoaded

lib.cache(key)

lua
local job = lib.cache('job')

lib.onCache(key, cb)

Registers a change listener and immediately invokes the callback with the current value.

lua
lib.onCache('cuffed', function(isCuffed, oldValue)
  print(('Now cuffed: %s (was %s)'):format(isCuffed, oldValue))
end)

Equivalent low-level event:

lua
AddEventHandler('dirk_lib:cache:cuffed', function(newValue, oldValue)
  -- ...
end)

Cache Keys (Client)

KeyTypeDescription
resourcestringCurrent resource name
gamestringGame name (fivem / redm)
playerIdnumberResult of PlayerId()
serverIdnumberCurrent player server ID
pednumberCurrent player ped entity
vehiclenumber | falseVehicle entity if in vehicle; otherwise false
seatnumber | falseCurrent seat index; otherwise false
driverbooleantrue when seat is -1
weaponnumber | falseCurrent weapon hash when armed; otherwise false
mountnumber | falseRedM only: current mount entity or false
deadbooleanFramework/game state death flag
cuffedboolean | nilFramework-specific cuff state
jobtableParsed framework job object (see formats below)
gangtable | nilQB/QBX gang payload
citizenIdstring | nilCharacter identifier (citizenid or identifier)
charNamestring | nilCharacter full name
playerLoadedbooleanWhether 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, and playerLoaded are framework-populated.
  • gang is currently populated in QB/QBX adapters.
  • mount is populated only on RedM.

Change Semantics

Cache writes use deep comparison for tables and emit dirk_lib:cache:<key> only when values actually change.

Copyright © 2026 DirkScripts.

Not affiliated with or endorsed by Rockstar North, Take-Two Interactive, or any other rights holders. FiveM is a copyright and registered trademark of Take-Two Interactive Software, Inc.
Our checkout system is provided by Tebex Limited, who manage payment processing, product delivery, and billing support. Prices shown in currencies other than GBP are approximate conversions updated daily. All purchases are processed in GBP, so the final amount charged may vary depending on your bank or payment provider’s exchange rate.