mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-30 17:58:54 +00:00
Refactoring, added shared functions
- Added ESX.ShowHelpNotification - Added misc shared functions
This commit is contained in:
+11
-2
@@ -7,6 +7,7 @@ version '1.0.14'
|
||||
server_scripts {
|
||||
'@async/async.lua',
|
||||
'@mysql-async/lib/MySQL.lua',
|
||||
|
||||
'locale.lua',
|
||||
'locales/de.lua',
|
||||
'locales/br.lua',
|
||||
@@ -14,14 +15,18 @@ server_scripts {
|
||||
'locales/en.lua',
|
||||
'locales/fi.lua',
|
||||
'locales/sv.lua',
|
||||
|
||||
'config.lua',
|
||||
'config.weapons.lua',
|
||||
|
||||
'server/common.lua',
|
||||
'server/classes/player.lua',
|
||||
'server/functions.lua',
|
||||
'server/paycheck.lua',
|
||||
'server/main.lua',
|
||||
'server/commands.lua'
|
||||
'server/commands.lua',
|
||||
|
||||
'shared/functions.lua'
|
||||
}
|
||||
|
||||
client_scripts {
|
||||
@@ -32,13 +37,17 @@ client_scripts {
|
||||
'locales/en.lua',
|
||||
'locales/fi.lua',
|
||||
'locales/sv.lua',
|
||||
|
||||
'config.lua',
|
||||
'config.weapons.lua',
|
||||
|
||||
'client/common.lua',
|
||||
'client/entityiter.lua',
|
||||
'client/functions.lua',
|
||||
'client/wrapper.lua',
|
||||
'client/main.lua'
|
||||
'client/main.lua',
|
||||
|
||||
'shared/functions.lua'
|
||||
}
|
||||
|
||||
ui_page {
|
||||
|
||||
+18
-21
@@ -1,21 +1,17 @@
|
||||
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 = {}
|
||||
ESX.PlayerData = {}
|
||||
ESX.PlayerLoaded = false
|
||||
ESX.CurrentRequestId = 0
|
||||
ESX.ServerCallbacks = {}
|
||||
ESX.TimeoutCallbacks = {}
|
||||
|
||||
ESX.UI = {}
|
||||
ESX.UI.HUD = {}
|
||||
ESX.UI.HUD.RegisteredElements = {}
|
||||
ESX.UI.Menu = {}
|
||||
ESX.UI.Menu.RegisteredTypes = {}
|
||||
ESX.UI.Menu.Opened = {}
|
||||
|
||||
ESX.Game = {}
|
||||
ESX.Game.Utils = {}
|
||||
|
||||
@@ -23,18 +19,6 @@ ESX.GetConfig = function()
|
||||
return Config
|
||||
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.SetTimeout = function(msec, cb)
|
||||
table.insert(ESX.TimeoutCallbacks, {
|
||||
time = GetGameTimer() + msec,
|
||||
@@ -60,9 +44,9 @@ ESX.SetPlayerData = function(key, val)
|
||||
end
|
||||
|
||||
ESX.ShowNotification = function(msg)
|
||||
SetNotificationTextEntry('STRING')
|
||||
AddTextComponentString(msg)
|
||||
DrawNotification(0,1)
|
||||
SetNotificationTextEntry('STRING')
|
||||
AddTextComponentString(msg)
|
||||
DrawNotification(false, true)
|
||||
end
|
||||
|
||||
ESX.ShowAdvancedNotification = function(title, subject, msg, icon, iconType)
|
||||
@@ -72,6 +56,14 @@ ESX.ShowAdvancedNotification = function(title, subject, msg, icon, iconType)
|
||||
DrawNotification(false, false)
|
||||
end
|
||||
|
||||
ESX.ShowHelpNotification = function(msg)
|
||||
if not IsHelpMessageOnScreen() then
|
||||
SetTextComponentFormat('STRING')
|
||||
AddTextComponentString(msg)
|
||||
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
|
||||
end
|
||||
end
|
||||
|
||||
ESX.TriggerServerCallback = function(name, cb, ...)
|
||||
|
||||
ESX.ServerCallbacks[ESX.CurrentRequestId] = cb
|
||||
@@ -1379,6 +1371,11 @@ AddEventHandler('esx:showAdvancedNotification', function(title, subject, msg, ic
|
||||
ESX.ShowAdvancedNotification(title, subject, msg, icon, iconType)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx:showHelpNotification')
|
||||
AddEventHandler('esx:showHelpNotification', function(msg)
|
||||
ESX.ShowHelpNotification(msg)
|
||||
end)
|
||||
|
||||
-- SetTimeout
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ function getSharedObject()
|
||||
return ESX
|
||||
end
|
||||
|
||||
AddEventHandler('onMySQLReady', function ()
|
||||
AddEventHandler('onMySQLReady', function()
|
||||
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM items',
|
||||
|
||||
@@ -59,7 +59,7 @@ ESX.TriggerServerCallback = function(name, requestId, source, cb, ...)
|
||||
if ESX.ServerCallbacks[name] ~= nil then
|
||||
ESX.ServerCallbacks[name](source, cb, ...)
|
||||
else
|
||||
print('TriggerServerCallback => [' .. name .. '] does not exists')
|
||||
print('TriggerServerCallback => [' .. name .. '] does not exist')
|
||||
end
|
||||
|
||||
end
|
||||
@@ -223,6 +223,12 @@ ESX.UseItem = function(source, item)
|
||||
ESX.UsableItemsCallbacks[item](source)
|
||||
end
|
||||
|
||||
ESX.GetItemLabel = function(item)
|
||||
if ESX.Items[item] ~= nil then
|
||||
return ESX.Items[item].label
|
||||
end
|
||||
end
|
||||
|
||||
ESX.GetWeaponList = function()
|
||||
return Config.Weapons
|
||||
end
|
||||
@@ -254,5 +260,4 @@ ESX.CreatePickup = function(type, name, count, label, player)
|
||||
|
||||
ESX.PickupId = pickupId
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -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