mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
perf(client/vehicle): hasVehicleKeys
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user