2022-02-28 00:49:44 +00:00
|
|
|
local cache = {}
|
2022-04-14 06:44:34 +00:00
|
|
|
cache.playerId = PlayerId()
|
|
|
|
|
cache.serverId = GetPlayerServerId(cache.playerId)
|
2022-02-28 00:49:44 +00:00
|
|
|
|
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-07-29 01:08:17 +10:00
|
|
|
local GetVehiclePedIsUsing = GetVehiclePedIsUsing
|
|
|
|
|
local GetPedInVehicleSeat = GetPedInVehicleSeat
|
|
|
|
|
local GetVehicleMaxNumberOfPassengers = GetVehicleMaxNumberOfPassengers
|
|
|
|
|
|
2022-02-28 00:49:44 +00:00
|
|
|
CreateThread(function()
|
|
|
|
|
while true do
|
2022-07-29 01:08:17 +10:00
|
|
|
local ped = PlayerPedId()
|
|
|
|
|
cache:set('ped', ped)
|
|
|
|
|
|
|
|
|
|
local vehicle = GetVehiclePedIsUsing(ped)
|
|
|
|
|
|
|
|
|
|
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-02-28 00:49:44 +00:00
|
|
|
Wait(100)
|
|
|
|
|
end
|
|
|
|
|
end)
|
2022-03-01 12:28:04 +00:00
|
|
|
|
|
|
|
|
function lib.cache(key)
|
|
|
|
|
return cache[key]
|
2022-03-13 03:21:33 +00:00
|
|
|
end
|
|
|
|
|
|
2022-07-29 01:08:17 +10:00
|
|
|
_ENV.cache = cache
|