mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-29 20:01:28 +00:00
0f137e3814
This is a breaking change.
77 lines
2.3 KiB
Lua
77 lines
2.3 KiB
Lua
QBShared = {}
|
|
|
|
local StringCharset = {}
|
|
local NumberCharset = {}
|
|
|
|
for i = 48, 57 do NumberCharset[#NumberCharset+1] = string.char(i) end
|
|
for i = 65, 90 do StringCharset[#StringCharset+1] = string.char(i) end
|
|
for i = 97, 122 do StringCharset[#StringCharset+1] = string.char(i) end
|
|
|
|
QBShared.RandomStr = function(length)
|
|
if length <= 0 then return '' end
|
|
return QBShared.RandomStr(length - 1) .. StringCharset[math.random(1, #StringCharset)]
|
|
end
|
|
|
|
QBShared.RandomInt = function(length)
|
|
if length <= 0 then return '' end
|
|
return QBShared.RandomInt(length - 1) .. NumberCharset[math.random(1, #NumberCharset)]
|
|
end
|
|
|
|
QBShared.SplitStr = function(str, delimiter)
|
|
local result = { }
|
|
local from = 1
|
|
local delim_from, delim_to = string.find(str, delimiter, from)
|
|
while delim_from do
|
|
result[#result+1] = string.sub(str, from, delim_from - 1)
|
|
from = delim_to + 1
|
|
delim_from, delim_to = string.find(str, delimiter, from)
|
|
end
|
|
result[#result+1] = string.sub(str, from)
|
|
return result
|
|
end
|
|
|
|
QBShared.Trim = function(value)
|
|
if not value then return nil end
|
|
return (string.gsub(value, '^%s*(.-)%s*$', '%1'))
|
|
end
|
|
|
|
QBShared.Round = function(value, numDecimalPlaces)
|
|
if not numDecimalPlaces then return math.floor(value + 0.5) end
|
|
local power = 10 ^ numDecimalPlaces
|
|
return math.floor((value * power) + 0.5) / (power)
|
|
end
|
|
|
|
QBShared.ChangeVehicleExtra = function (vehicle, extra, enable)
|
|
if DoesExtraExist(vehicle, extra) then
|
|
if enable then
|
|
SetVehicleExtra(vehicle, extra, false)
|
|
if not IsVehicleExtraTurnedOn(vehicle, extra) then
|
|
QBShared.ChangeVehicleExtra(vehicle, extra, enable)
|
|
end
|
|
else
|
|
SetVehicleExtra(vehicle, extra, true)
|
|
if IsVehicleExtraTurnedOn(vehicle, extra) then
|
|
QBShared.ChangeVehicleExtra(vehicle, extra, enable)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
QBShared.SetDefaultVehicleExtras = function (vehicle, config)
|
|
-- Clear Extras
|
|
for i=1,20 do
|
|
if DoesExtraExist(vehicle, i) then
|
|
SetVehicleExtra(vehicle, i, 1)
|
|
end
|
|
end
|
|
|
|
for id, enabled in pairs(config) do
|
|
QBShared.ChangeVehicleExtra(vehicle, tonumber(id), true)
|
|
end
|
|
end
|
|
|
|
QBShared.StarterItems = {
|
|
['phone'] = { amount = 1, item = 'phone' },
|
|
['id_card'] = { amount = 1, item = 'id_card' },
|
|
['driver_license'] = { amount = 1, item = 'driver_license' },
|
|
} |