👩🔬CL CACHE
Explanation of Cache Functions
The provided cache functions work exclusively with exports from LGF_Utility
. Use these functions to retrieve player and vehicle cache data efficiently.
Player Cache:
exports.LGF_Utility:cachePed()
Vehicle Cache:
exports.LGF_Utility:cacheVeh()
These functions ensure that you have access to the most recent and relevant data without manually tracking every change, making your scripts more streamlined and efficient.
Player Cache Variables
| Variable | Type | Description |
|----------------------|--------|---------------------------------------|
| CachePed.id | number | The Ped ID of the player |
| CachePed.serverId | number | The Server ID of the player |
| CachePed.ped | number | The Ped of the player |
| CachePed.name | string | The name of the player (Steam) |
| CachePed.identifier | string | The identifier of the player (Core) |
| CachePed.job | string | The Job of the player (core) |
| CachePed.group | string | The Player Group (Core) |
| CachePed.coords | number | The vec3 coords |
Vehicle Cache Variables
| Variable | Type | Description |
|--------------------|--------|---------------------------------------|
| CacheVeh.vehicle | number | The identifier of the vehicle |
| CacheVeh.plate | string | The plate of the vehicle |
| CacheVeh.netID | number | The Net ID of the vehicle |
| CacheVeh.fuel | number | The Current Vehicle Fuel |
Cache Exports
-- Retrieve Player Cache
local CachePed = exports.LGF_Utility:cachePed()
-- Retrieve Vehicle Cache
local CacheVeh = exports.LGF_Utility:cacheVeh()
Cache Example
Retrieve Personal Cache
RegisterCommand('personalCache', function()
local CachePed = exports.LGF_Utility:cachePed()
print('Player ID:', CachePed.id)
print('Player Server ID:', CachePed.serverId)
print('Player Identifier:', CachePed.identifier)
print('Player Steam Name:', CachePed.name)
print('Player Game Name:', CachePed.rpname)
print('Player Job:', CachePed.job)
print('Player Group:', CachePed.group)
print('Player Ped:', CachePed.ped)
end)
Retrieve Vehicle Cache
RegisterCommand('vehicleCache', function()
local CachePed = exports.LGF_Utility:cachePed()
if CacheVeh.netID ~= 0 then
print('Vehicle Net ID:', CacheVeh.netID)
print('Vehicle Plate:', CacheVeh.plate)
print('Vehicle Fuel Level:', CacheVeh.fuel)
print('Vehicle Cache:', CacheVeh.vehicle)
else
print("Player Not In Vehicle")
end
end)
Implementing in a Command
-- Delete current vehicle using
RegisterCommand('dv', function()
local CacheVeh = exports.LGF_Utility:cacheVeh()
local isInVehicle = exports.LGF_Utility:IsPlayerInVehicle(CachePed.ped)
if isInVehicle then
DeleteEntity(CacheVeh.vehicle)
else
print('You are not in any vehicle')
end
end)
-- Refuel current vehicle using
RegisterCommand('refuel', function()
local CachePed = exports.LGF_Utility:cachePed()
local isInVehicle = exports.LGF_Utility:IsPlayerInVehicle(CachePed.ped)
if isInVehicle then
SetVehicleFuelLevel(CacheVeh.vehicle, 100.0)
print('Vehicle refueled')
else
print('You are not in any vehicle')
end
end)
Implementing Command to Retrieve and Clear Player Cache
The LGF.Command:CreateCommand
function provides two custom commands to retrieve and clear player cache data.
Retrieve Player Cache Data
Command Name:
cache
Functionality: This command retrieves the player cache data for a specific player ID. When triggered, it awaits a callback to get the cached data from
LGF_Utility
. If the data is found, it uses a built-in utility function to print the player cache information. If not, it prints a warning message.Clea Player Cache Data
Command Name:
clearchache
Functionality: This feature gets the player's cache and clears it when needed
LGF.Command:CreateCommand({
{
name = "cache",
description = "Retrieves player cache data.",
permission = 'cache.getPlayerCache',
Data = function(source, args)
local playerID = tonumber(args[1])
local PlayerCache = lib.callback.await('LGF_Utility:RetrievePlayerCache', false, playerID)
if PlayerCache then
exports.LGF_Utility:PrintSelector({
message = PlayerCache,
prefix = '[PLAYER CACHE]',
type = 'info',
table = true,
})
else
exports.LGF_Utility:PrintSelector({
message = string.format("Player cache data not found for ID: %d", playerID),
prefix = '[WARNING]',
type = 'warning',
})
end
end
},
{
name = "clearcache",
description = "Clears player cache data for a specific ID.",
permission = 'cache.clearPlayerCache',
Data = function(source, args)
local playerID = tonumber(args[1])
local success = lib.callback.await('LGF_Utility:ClearPlayerCache', false, playerID)
if success then
exports.LGF_Utility:PrintSelector({
message = string.format("Player cache cleared for ID: %d", playerID),
prefix = '[SUCCESS]',
type = 'success',
})
else
exports.LGF_Utility:PrintSelector({
message = string.format("Failed to clear player cache for ID: %d", playerID),
prefix = '[WARNING]',
type = 'warning',
})
end
end,
},
})
Last updated