Refactoring, added shared functions

- Added ESX.ShowHelpNotification
- Added misc shared functions
This commit is contained in:
ElPumpo
2018-07-07 13:31:40 +02:00
parent a9a0dedeed
commit 985f2a81fb
5 changed files with 99 additions and 27 deletions
+18 -21
View File
@@ -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