mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 23:16:03 +01:00
48 lines
1.0 KiB
Lua
48 lines
1.0 KiB
Lua
local cache = {}
|
|
cache.playerId = PlayerId()
|
|
cache.serverId = GetPlayerServerId(cache.playerId)
|
|
|
|
function cache:set(key, value)
|
|
if value ~= self[key] then
|
|
self[key] = value
|
|
TriggerEvent(('ox_lib:cache:%s'):format(key), value)
|
|
return true
|
|
end
|
|
end
|
|
|
|
local GetVehiclePedIsUsing = GetVehiclePedIsUsing
|
|
local GetPedInVehicleSeat = GetPedInVehicleSeat
|
|
local GetVehicleMaxNumberOfPassengers = GetVehicleMaxNumberOfPassengers
|
|
|
|
CreateThread(function()
|
|
while true do
|
|
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
|
|
|
|
Wait(100)
|
|
end
|
|
end)
|
|
|
|
function lib.cache(key)
|
|
return cache[key]
|
|
end
|
|
|
|
_ENV.cache = cache |