mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-18 22:36:03 +01:00
perf(server/vehicle): getting vehicle types
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
local ox_inventory
|
local ox_inventory
|
||||||
local inventoryStarted = false
|
local inventoryStarted = false
|
||||||
local spawnedPlayerVehicles = {}
|
local spawnedPlayerVehicles = {}
|
||||||
|
local vehicleTypes = json.decode(GetResourceKvpString("ND_Core:vehTypes") or "[]")
|
||||||
|
|
||||||
NDCore.isResourceStarted("ox_inventory", function(started)
|
NDCore.isResourceStarted("ox_inventory", function(started)
|
||||||
inventoryStarted = started
|
inventoryStarted = started
|
||||||
@@ -8,16 +9,24 @@ NDCore.isResourceStarted("ox_inventory", function(started)
|
|||||||
ox_inventory = exports.ox_inventory
|
ox_inventory = exports.ox_inventory
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function getVehicleType(model)
|
local function getVehicleType(coords, model)
|
||||||
local tempVehicle = CreateVehicle(model, 0, 0, 0, 0, true, true)
|
if vehicleTypes[model] then
|
||||||
|
return vehicleTypes[model]
|
||||||
|
end
|
||||||
|
|
||||||
|
local tempVehicle = CreateVehicle(model, coords.x, coords.y, coords.z-5.0, coords.w, true, false)
|
||||||
local time = os.time()
|
local time = os.time()
|
||||||
while not DoesEntityExist(tempVehicle) and os.time()-time < 5 do Wait(5) end
|
|
||||||
|
while not DoesEntityExist(tempVehicle) and os.time()-time < 5 do Wait(0) end
|
||||||
if not DoesEntityExist(tempVehicle) then return end
|
if not DoesEntityExist(tempVehicle) then return end
|
||||||
local entityType = GetVehicleType(tempVehicle)
|
|
||||||
|
local vehType = GetVehicleType(tempVehicle)
|
||||||
DeleteEntity(tempVehicle)
|
DeleteEntity(tempVehicle)
|
||||||
return entityType
|
|
||||||
|
vehicleTypes[model] = vehType
|
||||||
|
SetResourceKvp("ND_Core:vehTypes", json.encode(vehicleTypes))
|
||||||
|
|
||||||
|
return vehType
|
||||||
end
|
end
|
||||||
|
|
||||||
local function generatePlate()
|
local function generatePlate()
|
||||||
@@ -253,7 +262,7 @@ function NDCore.createVehicle(info)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local model = info.model or properties.model
|
local model = info.model or properties.model
|
||||||
local vehType = getVehicleType(model)
|
local vehType = getVehicleType(spawnCoords, model)
|
||||||
if not vehType then
|
if not vehType then
|
||||||
return Citizen.Trace("NDCore.createVehicle", "vehType not found")
|
return Citizen.Trace("NDCore.createVehicle", "vehType not found")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user