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 Cachelocal CacheVeh = exports.LGF_Utility:cacheVeh()
RegisterCommand('vehicleCache', function()local CachePed = exports.LGF_Utility:cachePed()if CacheVeh.netID ~=0thenprint('Vehicle Net ID:', CacheVeh.netID)print('Vehicle Plate:', CacheVeh.plate)print('Vehicle Fuel Level:', CacheVeh.fuel)print('Vehicle Cache:', CacheVeh.vehicle)elseprint("Player Not In Vehicle")endend)
Implementing in a Command
-- Delete current vehicle usingRegisterCommand('dv', function()local CacheVeh = exports.LGF_Utility:cacheVeh()local isInVehicle = exports.LGF_Utility:IsPlayerInVehicle(CachePed.ped)if isInVehicle thenDeleteEntity(CacheVeh.vehicle)elseprint('You are not in any vehicle')endend)-- Refuel current vehicle usingRegisterCommand('refuel', function()local CachePed = exports.LGF_Utility:cachePed()local isInVehicle = exports.LGF_Utility:IsPlayerInVehicle(CachePed.ped)if isInVehicle thenSetVehicleFuelLevel(CacheVeh.vehicle, 100.0)print('Vehicle refueled')elseprint('You are not in any vehicle')endend)
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', })endend }, { 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', })endend, },})