mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-30 01:38:52 +00:00
Refactoring, added shared functions
- Added ESX.ShowHelpNotification - Added misc shared functions
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
local Charset = {}
|
||||
|
||||
for i = 48, 57 do table.insert(Charset, string.char(i)) end
|
||||
for i = 65, 90 do table.insert(Charset, string.char(i)) end
|
||||
for i = 97, 122 do table.insert(Charset, string.char(i)) end
|
||||
|
||||
ESX.GetRandomString = function(length)
|
||||
math.randomseed(GetGameTimer())
|
||||
|
||||
if length > 0 then
|
||||
return ESX.GetRandomString(length - 1) .. Charset[math.random(1, #Charset)]
|
||||
else
|
||||
return ''
|
||||
end
|
||||
end
|
||||
|
||||
ESX.TableContainsValue = function(table, value)
|
||||
for k, v in pairs(table) do
|
||||
if v == value then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
ESX.TableToString = function(table, nb)
|
||||
if nb == nil then
|
||||
nb = 0
|
||||
end
|
||||
|
||||
if type(table) == 'table' then
|
||||
local s = ''
|
||||
for i = 1, nb + 1, 1 do
|
||||
s = s .. " "
|
||||
end
|
||||
|
||||
s = '{\n'
|
||||
for k,v in pairs(table) do
|
||||
if type(k) ~= 'number' then k = '"'..k..'"' end
|
||||
for i = 1, nb, 1 do
|
||||
s = s .. " "
|
||||
end
|
||||
s = s .. '['..k..'] = ' .. ESX.TableToString(v, nb + 1) .. ',\n'
|
||||
end
|
||||
|
||||
for i = 1, nb, 1 do
|
||||
s = s .. " "
|
||||
end
|
||||
|
||||
return s .. '}'
|
||||
else
|
||||
return tostring(table)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
ESX.Round = function(value)
|
||||
return value >= 0 and math.floor(value + 0.5) or math.ceil(value - 0.5)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user