mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
refactor(resource/cache): remove getVehicle method
Keep it in the thread for simplicity.
This commit is contained in:
51
resource/cache/client.lua
vendored
51
resource/cache/client.lua
vendored
@@ -2,28 +2,6 @@ local cache = {}
|
||||
cache.playerId = PlayerId()
|
||||
cache.serverId = GetPlayerServerId(cache.playerId)
|
||||
|
||||
local GetVehiclePedIsUsing = GetVehiclePedIsUsing
|
||||
local GetPedInVehicleSeat = GetPedInVehicleSeat
|
||||
local GetVehicleMaxNumberOfPassengers = GetVehicleMaxNumberOfPassengers
|
||||
|
||||
function cache:getVehicle()
|
||||
local vehicle = GetVehiclePedIsUsing(self.ped)
|
||||
if vehicle > 0 then
|
||||
self:set('vehicle', vehicle)
|
||||
|
||||
if not cache.seat or GetPedInVehicleSeat(vehicle, cache.seat) ~= cache.ped then
|
||||
for i = -1, GetVehicleMaxNumberOfPassengers(vehicle) - 1 do
|
||||
if GetPedInVehicleSeat(vehicle, i) == self.ped then
|
||||
return self:set('seat', i)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
self:set('vehicle', false)
|
||||
self:set('seat', false)
|
||||
end
|
||||
end
|
||||
|
||||
function cache:set(key, value)
|
||||
if value ~= self[key] then
|
||||
self[key] = value
|
||||
@@ -32,10 +10,33 @@ function cache:set(key, value)
|
||||
end
|
||||
end
|
||||
|
||||
local GetVehiclePedIsUsing = GetVehiclePedIsUsing
|
||||
local GetPedInVehicleSeat = GetPedInVehicleSeat
|
||||
local GetVehicleMaxNumberOfPassengers = GetVehicleMaxNumberOfPassengers
|
||||
|
||||
CreateThread(function()
|
||||
while true do
|
||||
cache:set('ped', PlayerPedId())
|
||||
cache:getVehicle()
|
||||
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)
|
||||
@@ -44,4 +45,4 @@ function lib.cache(key)
|
||||
return cache[key]
|
||||
end
|
||||
|
||||
_ENV.cache = cache
|
||||
_ENV.cache = cache
|
||||
Reference in New Issue
Block a user