-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnectqueue.lua
62 lines (51 loc) · 1.48 KB
/
connectqueue.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Queue = {}
Queue.Ready = false
Queue.Exports = nil
Queue.ReadyCbs = {}
Queue.CurResource = GetCurrentResourceName()
if Queue.CurResource == "connectqueue" then return end
function Queue.OnReady(cb)
if not cb then return end
if Queue.IsReady() then cb() return end
table.insert(Queue.ReadyCbs, cb)
end
function Queue.OnJoin(cb)
if not cb then return end
Queue.Exports:OnJoin(cb, Queue.CurResource)
end
function Queue.AddPriority(id, power, temp)
if not Queue.IsReady() then return end
Queue.Exports:AddPriority(id, power, temp)
end
function Queue.RemovePriority(id)
if not Queue.IsReady() then return end
Queue.Exports:RemovePriority(id)
end
function Queue.IsReady()
return Queue.Ready
end
function Queue.LoadExports()
Queue.Exports = exports.connectqueue:GetQueueExports()
Queue.Ready = true
Queue.ReadyCallbacks()
end
function Queue.ReadyCallbacks()
if not Queue.IsReady() then return end
for _, cb in ipairs(Queue.ReadyCbs) do
cb()
end
end
AddEventHandler("onResourceStart", function(resource)
if resource == "connectqueue" then
while GetResourceState(resource) ~= "started" do Wait(0) end
Wait(1)
Queue.LoadExports()
end
end)
AddEventHandler("onResourceStop", function(resource)
if resource == "connectqueue" then
Queue.Ready = false
Queue.Exports = nil
end
end)
SetTimeout(1, function() Queue.LoadExports() end)