This repository has been archived by the owner on Oct 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.lua
78 lines (63 loc) · 1.75 KB
/
utils.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- Taken from fivem-vehicleshop
-- https://github.com/esx-framework/esx-legacy/blob/main/%5Besx_addons%5D/fivem-vehicleshop/client/utils.lua
local Config = {
PlateLetters = 3,
PlateNumbers = 3,
PlateUseSpace = true
}
local NumberCharset = {}
local Charset = {}
for i = 48, 57 do table.insert(NumberCharset, 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
function GeneratePlate()
local generatedPlate
local doBreak = false
while true do
Wait(2)
math.randomseed(GetGameTimer())
if Config.PlateUseSpace then
generatedPlate = string.upper(GetRandomLetter(Config.PlateLetters) .. ' ' .. GetRandomNumber(Config.PlateNumbers))
else
generatedPlate = string.upper(GetRandomLetter(Config.PlateLetters) .. GetRandomNumber(Config.PlateNumbers))
end
ESX.TriggerServerCallback('fivem-vehicleshop:isPlateTaken', function(isPlateTaken)
if not isPlateTaken then
doBreak = true
end
end, generatedPlate)
if doBreak then
break
end
end
return generatedPlate
end
-- mixing async with sync tasks
function IsPlateTaken(plate)
local callback = 'waiting'
ESX.TriggerServerCallback('fivem-vehicleshop:isPlateTaken', function(isPlateTaken)
callback = isPlateTaken
end, plate)
while type(callback) == 'string' do
Wait(0)
end
return callback
end
function GetRandomNumber(length)
Wait(0)
math.randomseed(GetGameTimer())
if length > 0 then
return GetRandomNumber(length - 1) .. NumberCharset[math.random(1, #NumberCharset)]
else
return ''
end
end
function GetRandomLetter(length)
Wait(0)
math.randomseed(GetGameTimer())
if length > 0 then
return GetRandomLetter(length - 1) .. Charset[math.random(1, #Charset)]
else
return ''
end
end