From 9fd5e75302c3c3dc850bc6ec7dbf72c7fc683364 Mon Sep 17 00:00:00 2001 From: Mojito-Fivem Date: Sun, 31 Oct 2021 21:38:45 +0000 Subject: [PATCH] refactor(maths): move maths function to shared.lua --- client/functions.lua | 22 +--------------------- server/functions.lua | 22 +--------------------- shared.lua | 10 ++++++++++ 3 files changed, 12 insertions(+), 42 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index a911657..f217a62 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -1,5 +1,4 @@ QBCore.Functions = {} -QBCore.Functions.Math = {} QBCore.RequestId = 0 -- Player @@ -629,23 +628,4 @@ function QBCore.Functions.SetVehicleProperties(vehicle, props) SetVehicleLivery(vehicle, props.modLivery) end end -end - --- Extra Math Functions - --- Math Rounding Credits: http://lua-users.org/wiki/SimpleRound -function QBCore.Functions.Math.Sign(v) - return (v >= 0 and 1) or -1 -end - --- Math Rounding Credits: http://lua-users.org/wiki/SimpleRound --- Usage: --- QBCore.Functions.Math.Round(119.68, 0.01) = 119.68 --- QBCore.Functions.Math.Round(119.68, 0.1) = 119.7 --- QBCore.Functions.Math.Round(119.68) = 120 --- QBCore.Functions.Math.Round(119.68, 100) = 100 --- QBCore.Functions.Math.Round(119.68, 1000) = 0 -function QBCore.Functions.Math.Round(v, bracket) - bracket = bracket or 1 - return QBCore.Functions.Math.Sign(v/bracket + QBCore.Functions.Math.Sign(v) * 0.5) * bracket -end +end \ No newline at end of file diff --git a/server/functions.lua b/server/functions.lua index db5656c..bd064be 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -1,5 +1,4 @@ QBCore.Functions = {} -QBCore.Functions.Math = {} -- Getters -- Get your player first and then trigger a function on them @@ -299,23 +298,4 @@ function QBCore.Functions.IsLicenseInUse(license) end end return false -end - --- Extra Math Functions - --- Math Rounding Credits: http://lua-users.org/wiki/SimpleRound -function QBCore.Functions.Math.Sign(v) - return (v >= 0 and 1) or -1 -end - --- Math Rounding Credits: http://lua-users.org/wiki/SimpleRound --- Usage: --- QBCore.Functions.Math.Round(119.68, 0.01) = 119.68 --- QBCore.Functions.Math.Round(119.68, 0.1) = 119.7 --- QBCore.Functions.Math.Round(119.68) = 120 --- QBCore.Functions.Math.Round(119.68, 100) = 100 --- QBCore.Functions.Math.Round(119.68, 1000) = 0 -function QBCore.Functions.Math.Round(v, bracket) - bracket = bracket or 1 - return QBCore.Functions.Math.Sign(v/bracket + QBCore.Functions.Math.Sign(v) * 0.5) * bracket -end +end \ No newline at end of file diff --git a/shared.lua b/shared.lua index bfefd2b..e89f9ba 100644 --- a/shared.lua +++ b/shared.lua @@ -36,6 +36,16 @@ QBShared.SplitStr = function(str, delimiter) return result end +-- Math Rounding Credits: http://lua-users.org/wiki/SimpleRound +QBShared.Sign = function(v) + return (v >= 0 and 1) or -1 +end + +QBShared.Round = function(v, bracket) + bracket = bracket or 1 + return QBShared.Sign(v/bracket + QBCore.Functions.Math.Sign(v) * 0.5) * bracket +end + QBShared.StarterItems = { ['phone'] = { amount = 1, item = 'phone' }, ['id_card'] = { amount = 1, item = 'id_card' },