2022-02-28 00:49:44 +00:00
|
|
|
local cache = {}
|
|
|
|
|
|
|
|
|
|
function cache:getPed()
|
|
|
|
|
local ped = PlayerPedId()
|
|
|
|
|
if ped ~= self.ped then
|
|
|
|
|
self.ped = ped
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function cache:getVehicle()
|
|
|
|
|
local vehicle = GetVehiclePedIsIn(self.ped, false)
|
|
|
|
|
if vehicle > 0 then
|
2022-03-01 12:28:04 +00:00
|
|
|
if self:set('vehicle', vehicle) then
|
2022-03-01 13:22:52 +00:00
|
|
|
local seats = GetVehicleMaxNumberOfPassengers(vehicle) - 1
|
|
|
|
|
local GetPedInVehicleSeat = GetPedInVehicleSeat
|
|
|
|
|
for i = -1, seats do
|
|
|
|
|
if GetPedInVehicleSeat(vehicle, i) == self.ped then
|
|
|
|
|
return self:set('seat', i)
|
|
|
|
|
end
|
2022-02-28 00:49:44 +00:00
|
|
|
end
|
|
|
|
|
end
|
2022-03-01 13:22:52 +00:00
|
|
|
else
|
|
|
|
|
self:set('vehicle', false)
|
|
|
|
|
self:set('seat', false)
|
|
|
|
|
end
|
2022-02-28 00:49:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function cache:onFoot()
|
2022-03-01 12:28:04 +00:00
|
|
|
-- todo
|
2022-02-28 00:49:44 +00:00
|
|
|
-- print('on foot')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function cache:inVehicle()
|
2022-03-01 12:28:04 +00:00
|
|
|
-- todo
|
2022-02-28 00:49:44 +00:00
|
|
|
if self.driver then
|
|
|
|
|
-- print('driving vehicle')
|
|
|
|
|
else
|
|
|
|
|
-- print('in vehicle')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-01 12:28:04 +00:00
|
|
|
local update = {}
|
|
|
|
|
|
|
|
|
|
function cache:set(key, value)
|
|
|
|
|
if value ~= self[key] then
|
|
|
|
|
self[key] = value
|
|
|
|
|
update[key] = value
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-02-28 00:49:44 +00:00
|
|
|
CreateThread(function()
|
|
|
|
|
while true do
|
|
|
|
|
cache:getPed()
|
|
|
|
|
cache:getVehicle()
|
|
|
|
|
|
2022-03-01 12:28:04 +00:00
|
|
|
-- if not cache.vehicle then
|
|
|
|
|
-- cache:onFoot()
|
|
|
|
|
-- else
|
|
|
|
|
-- cache:inVehicle()
|
|
|
|
|
-- end
|
|
|
|
|
|
2022-03-01 13:22:52 +00:00
|
|
|
if next(update) then
|
2022-03-01 12:28:04 +00:00
|
|
|
TriggerEvent('lualib:updateCache', update)
|
|
|
|
|
table.wipe(update)
|
2022-02-28 00:49:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Wait(100)
|
|
|
|
|
end
|
|
|
|
|
end)
|
2022-03-01 12:28:04 +00:00
|
|
|
|
|
|
|
|
function lib.cache(key)
|
|
|
|
|
return cache[key]
|
|
|
|
|
end
|