mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-09-04 17:23:31 +00:00
Merge pull request #311 from Mojito-Fivem/refactor/shared-functions
Refactor functions
This commit is contained in:
+7
-24
@@ -265,23 +265,6 @@ end
|
|||||||
|
|
||||||
-- Vehicle
|
-- Vehicle
|
||||||
|
|
||||||
local function Round(value, numDecimalPlaces)
|
|
||||||
if numDecimalPlaces then
|
|
||||||
local power = 10 ^ numDecimalPlaces
|
|
||||||
return math.floor((value * power) + 0.5) / (power)
|
|
||||||
else
|
|
||||||
return math.floor(value + 0.5)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function Trim(value)
|
|
||||||
if value then
|
|
||||||
return (string.gsub(value, '^%s*(.-)%s*$', '%1'))
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function QBCore.Functions.SpawnVehicle(model, cb, coords, isnetworked)
|
function QBCore.Functions.SpawnVehicle(model, cb, coords, isnetworked)
|
||||||
local model = GetHashKey(model)
|
local model = GetHashKey(model)
|
||||||
local ped = PlayerPedId()
|
local ped = PlayerPedId()
|
||||||
@@ -317,7 +300,7 @@ end
|
|||||||
|
|
||||||
function QBCore.Functions.GetPlate(vehicle)
|
function QBCore.Functions.GetPlate(vehicle)
|
||||||
if vehicle == 0 then return end
|
if vehicle == 0 then return end
|
||||||
return Trim(GetVehicleNumberPlateText(vehicle))
|
return QBCore.Shared.Trim(GetVehicleNumberPlateText(vehicle))
|
||||||
end
|
end
|
||||||
|
|
||||||
function QBCore.Functions.GetVehicleProperties(vehicle)
|
function QBCore.Functions.GetVehicleProperties(vehicle)
|
||||||
@@ -341,13 +324,13 @@ function QBCore.Functions.GetVehicleProperties(vehicle)
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
model = GetEntityModel(vehicle),
|
model = GetEntityModel(vehicle),
|
||||||
plate = Trim(GetVehicleNumberPlateText(vehicle)),
|
plate = QBCore.Shared.Trim(GetVehicleNumberPlateText(vehicle)),
|
||||||
plateIndex = GetVehicleNumberPlateTextIndex(vehicle),
|
plateIndex = GetVehicleNumberPlateTextIndex(vehicle),
|
||||||
bodyHealth = Round(GetVehicleBodyHealth(vehicle), 1),
|
bodyHealth = QBCore.Shared.Round(GetVehicleBodyHealth(vehicle), 0.1),
|
||||||
engineHealth = Round(GetVehicleEngineHealth(vehicle), 1),
|
engineHealth = QBCore.Shared.Round(GetVehicleEngineHealth(vehicle), 0.1),
|
||||||
tankHealth = Round(GetVehiclePetrolTankHealth(vehicle), 1),
|
tankHealth = QBCore.Shared.Round(GetVehiclePetrolTankHealth(vehicle), 0.1),
|
||||||
fuelLevel = Round(GetVehicleFuelLevel(vehicle), 1),
|
fuelLevel = QBCore.Shared.Round(GetVehicleFuelLevel(vehicle), 0.1),
|
||||||
dirtLevel = Round(GetVehicleDirtLevel(vehicle), 1),
|
dirtLevel = QBCore.Shared.Round(GetVehicleDirtLevel(vehicle), 0.1),
|
||||||
color1 = colorPrimary,
|
color1 = colorPrimary,
|
||||||
color2 = colorSecondary,
|
color2 = colorSecondary,
|
||||||
pearlescentColor = pearlescentColor,
|
pearlescentColor = pearlescentColor,
|
||||||
|
|||||||
@@ -36,6 +36,14 @@ QBShared.SplitStr = function(str, delimiter)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
QBShared.Trim = function(value)
|
||||||
|
if value then
|
||||||
|
return (string.gsub(value, '^%s*(.-)%s*$', '%1'))
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Math Rounding Credits: http://lua-users.org/wiki/SimpleRound
|
-- Math Rounding Credits: http://lua-users.org/wiki/SimpleRound
|
||||||
QBShared.Sign = function(v)
|
QBShared.Sign = function(v)
|
||||||
return (v >= 0 and 1) or -1
|
return (v >= 0 and 1) or -1
|
||||||
@@ -46,6 +54,7 @@ QBShared.Round = function(v, bracket)
|
|||||||
return QBShared.Sign(v/bracket + QBShared.Sign(v) * 0.5) * bracket
|
return QBShared.Sign(v/bracket + QBShared.Sign(v) * 0.5) * bracket
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
QBShared.StarterItems = {
|
QBShared.StarterItems = {
|
||||||
['phone'] = { amount = 1, item = 'phone' },
|
['phone'] = { amount = 1, item = 'phone' },
|
||||||
['id_card'] = { amount = 1, item = 'id_card' },
|
['id_card'] = { amount = 1, item = 'id_card' },
|
||||||
|
|||||||
Reference in New Issue
Block a user