-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclient.lua
More file actions
63 lines (51 loc) · 1.52 KB
/
client.lua
File metadata and controls
63 lines (51 loc) · 1.52 KB
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
63
local Cooldowns = {}
RegisterNUICallback("event_handler", function(data)
if data["event"] == "delayed_function_complete" then
if Cooldowns[data["data"]["id"]] then
Cooldowns[data["data"]["id"]]["data"]["cb"]()
Cooldowns[data["data"]["id"]] = nil
end
end
end)
StartDelayedFunction = function(title, time, cb)
local uniqueID = GenerateUniqueId()
Citizen.CreateThread(function()
while TableLength(Cooldowns) > 0 do
Citizen.Wait(0)
end
Cooldowns[uniqueID] = {}
Cooldowns[uniqueID]["data"] = {
["title"] = title,
["time"] = time,
["cb"] = cb,
["id"] = uniqueID
}
SendNUIMessage({
["Action"] = "SHOW_DELAYED_FUNCTION",
["Data"] = {
["title"] = title,
["time"] = time,
["id"] = uniqueID
}
})
end)
end
TableLength = function(table)
local length = 0
for _, _ in pairs(table) do
length = length + 1
end
return length
end
GenerateUniqueId = function()
local template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return string.gsub(template, '[xy]', function (c)
local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb)
return string.format('%x', v)
end)
end
RegisterCommand("example", function()
StartDelayedFunction("This is an example...", 5000, function()
print("The delayed function is now completed.")
end)
end)