perf(client/vehicle): hasVehicleKeys

This commit is contained in:
Andyyy7666
2023-08-26 04:36:07 +02:00
parent 0208f22df5
commit a75a307873

View File

@@ -361,30 +361,35 @@ Config.ox_inventory = NDCore.isResourceStarted("ox_inventory", function(started)
}) })
end) end)
local inventoryKeyCheck = { local keyCheckTime = {
lastCheck = 0, lastCheck = GetCloudTimeAsInt(),
hasKey = false hasKey = false
} }
local function hasVehicleKeys(veh) local function hasVehicleKeys(veh)
if Config.useInventoryForKeys then local time = GetCloudTimeAsInt()
local time = GetCloudTimeAsInt() if time-keyCheckTime.lastCheck < 5 then
if inventoryKeyCheck.lastCheck and (time-inventoryKeyCheck.lastCheck) < 5 then return keyCheckTime.hasKey
return inventoryKeyCheck.hasKey end
end
if Config.ox_inventory and Config.useInventoryForKeys then
local metadata = { local metadata = {
vehPlate = GetVehicleNumberPlateText(veh) vehPlate = GetVehicleNumberPlateText(veh)
} }
local hasKey = exports.ox_inventory:GetItemCount("keys", metadata) > 0 local hasKey = exports.ox_inventory:GetItemCount("keys", metadata) > 0
inventoryKeyCheck.lastCheck = time keyCheckTime.lastCheck = time
inventoryKeyCheck.hasKey = hasKey keyCheckTime.hasKey = hasKey
return hasKey return hasKey
end end
local state = Entity(veh).state local state = Entity(veh).state
local keys = state.keys local keys = state.keys
local player = NDCore.getPlayer() local player = NDCore.getPlayer()
return player and keys[player.id] local hasKey = player and keys and keys[player.id]
keyCheckTime.lastCheck = time
keyCheckTime.hasKey = hasKey
return hasKey
end end
CreateThread(function() CreateThread(function()