Files
ox_lib/resource/cache/client.lua
T

60 lines
1.4 KiB
Lua
Raw Normal View History

2022-09-14 00:50:27 +10:00
local cache = _ENV.cache
cache.playerId = PlayerId()
cache.serverId = GetPlayerServerId(cache.playerId)
2022-03-01 12:28:04 +00:00
function cache:set(key, value)
if value ~= self[key] then
self[key] = value
2022-07-28 23:09:23 +10:00
TriggerEvent(('ox_lib:cache:%s'):format(key), value)
2022-03-01 12:28:04 +00:00
return true
end
end
2022-10-28 00:32:18 +11:00
local GetVehiclePedIsIn = GetVehiclePedIsIn
local GetPedInVehicleSeat = GetPedInVehicleSeat
local GetVehicleMaxNumberOfPassengers = GetVehicleMaxNumberOfPassengers
2022-11-25 18:05:55 -08:00
local GetMount = GetMount
local IsPedOnMount = IsPedOnMount
2022-11-08 21:49:51 +01:00
local GetCurrentPedWeapon = GetCurrentPedWeapon
CreateThread(function()
while true do
local ped = PlayerPedId()
cache:set('ped', ped)
2022-10-28 00:32:18 +11:00
local vehicle = GetVehiclePedIsIn(ped, false)
if vehicle > 0 then
cache:set('vehicle', vehicle)
if not cache.seat or GetPedInVehicleSeat(vehicle, cache.seat) ~= ped then
for i = -1, GetVehicleMaxNumberOfPassengers(vehicle) - 1 do
if GetPedInVehicleSeat(vehicle, i) == ped then
cache:set('seat', i)
break
end
end
end
else
cache:set('vehicle', false)
cache:set('seat', false)
end
2022-11-25 18:05:55 -08:00
if cache.game == 'redm' then
local mount = GetMount(ped)
local onMount = IsPedOnMount(ped)
cache:set('mount', onMount and mount or false)
end
2022-11-08 21:49:51 +01:00
local hasWeapon, currentWeapon = GetCurrentPedWeapon(ped, true)
cache:set('weapon', hasWeapon and currentWeapon or false)
Wait(100)
end
end)
2022-03-01 12:28:04 +00:00
function lib.cache(key)
return cache[key]
end