diff --git a/[core]/es_extended/client/functions.lua b/[core]/es_extended/client/functions.lua index 1094ef87..77c01ae3 100644 --- a/[core]/es_extended/client/functions.lua +++ b/[core]/es_extended/client/functions.lua @@ -4,7 +4,6 @@ ESX.PlayerData = {} ESX.PlayerLoaded = false Core.CurrentRequestId = 0 Core.ServerCallbacks = {} -Core.TimeoutCallbacks = {} Core.Input = {} ESX.UI = {} ESX.UI.HUD = {} @@ -21,18 +20,6 @@ ESX.Scaleform.Utils = {} ESX.Streaming = {} -function ESX.SetTimeout(msec, cb) - table.insert(Core.TimeoutCallbacks, { - time = GetGameTimer() + msec, - cb = cb - }) - return #Core.TimeoutCallbacks -end - -function ESX.ClearTimeout(i) - Core.TimeoutCallbacks[i] = nil -end - function ESX.IsPlayerLoaded() return ESX.PlayerLoaded end @@ -1392,22 +1379,4 @@ AddEventHandler('esx:showAdvancedNotification', RegisterNetEvent('esx:showHelpNotification') AddEventHandler('esx:showHelpNotification', function(msg, thisFrame, beep, duration) ESX.ShowHelpNotification(msg, thisFrame, beep, duration) -end) - --- SetTimeout -CreateThread(function() - while true do - local sleep = 100 - if #Core.TimeoutCallbacks > 0 then - local currTime = GetGameTimer() - sleep = 0 - for i = 1, #Core.TimeoutCallbacks, 1 do - if currTime >= Core.TimeoutCallbacks[i].time then - Core.TimeoutCallbacks[i].cb() - Core.TimeoutCallbacks[i] = nil - end - end - end - Wait(sleep) - end -end) +end) \ No newline at end of file diff --git a/[core]/es_extended/common/modules/timeout.lua b/[core]/es_extended/common/modules/timeout.lua new file mode 100644 index 00000000..cb56de7b --- /dev/null +++ b/[core]/es_extended/common/modules/timeout.lua @@ -0,0 +1,23 @@ +local TimeoutCount = 0 +local CancelledTimeouts = {} + +ESX.SetTimeout = function(msec, cb) + local id = TimeoutCount + 1 + + SetTimeout(msec, function() + if CancelledTimeouts[id] then + CancelledTimeouts[id] = nil + return + end + + cb() + end) + + TimeoutCount = id + + return id +end + +ESX.ClearTimeout = function(id) + CancelledTimeouts[id] = true +end \ No newline at end of file diff --git a/[core]/es_extended/fxmanifest.lua b/[core]/es_extended/fxmanifest.lua index 1c9c63be..ffc21344 100644 --- a/[core]/es_extended/fxmanifest.lua +++ b/[core]/es_extended/fxmanifest.lua @@ -27,8 +27,7 @@ server_scripts { 'server/main.lua', 'server/commands.lua', - 'common/modules/math.lua', - 'common/modules/table.lua', + 'common/modules/*.lua', 'common/functions.lua' } @@ -42,8 +41,7 @@ client_scripts { 'client/modules/scaleform.lua', 'client/modules/streaming.lua', - 'common/modules/math.lua', - 'common/modules/table.lua', + 'common/modules/*.lua', 'common/functions.lua' } diff --git a/[core]/es_extended/server/common.lua b/[core]/es_extended/server/common.lua index 8cbff655..e59e0243 100644 --- a/[core]/es_extended/server/common.lua +++ b/[core]/es_extended/server/common.lua @@ -7,8 +7,6 @@ Core.UsableItemsCallbacks = {} Core.ServerCallbacks = {} Core.ClientCallbacks = {} Core.CurrentRequestId = 0 -Core.TimeoutCount = -1 -Core.CancelledTimeouts = {} Core.RegisteredCommands = {} Core.Pickups = {} Core.PickupId = 0 diff --git a/[core]/es_extended/server/functions.lua b/[core]/es_extended/server/functions.lua index d46184d6..3e10f922 100644 --- a/[core]/es_extended/server/functions.lua +++ b/[core]/es_extended/server/functions.lua @@ -4,22 +4,6 @@ function ESX.Trace(msg) end end -function ESX.SetTimeout(msec, cb) - local id = Core.TimeoutCount + 1 - - SetTimeout(msec, function() - if Core.CancelledTimeouts[id] then - Core.CancelledTimeouts[id] = nil - else - cb() - end - end) - - Core.TimeoutCount = id - - return id -end - function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion) if type(name) == 'table' then for k, v in ipairs(name) do @@ -159,10 +143,6 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion) end end -function ESX.ClearTimeout(id) - Core.CancelledTimeouts[id] = true -end - function ESX.RegisterServerCallback(name, cb) Core.ServerCallbacks[name] = cb end