mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 10:18:54 +00:00
Implemented plate generation from esx_migrate
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
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
|
||||
Citizen.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('esx_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('esx_vehicleshop:isPlateTaken', function (isPlateTaken)
|
||||
callback = isPlateTaken
|
||||
end, plate)
|
||||
|
||||
while type(callback) == 'string' do
|
||||
Citizen.Wait(0)
|
||||
end
|
||||
|
||||
return callback
|
||||
end
|
||||
|
||||
function GetRandomNumber(length)
|
||||
Citizen.Wait(1)
|
||||
math.randomseed(GetGameTimer())
|
||||
if length > 0 then
|
||||
return GetRandomNumber(length - 1) .. NumberCharset[math.random(1, #NumberCharset)]
|
||||
else
|
||||
return ''
|
||||
end
|
||||
end
|
||||
|
||||
function GetRandomLetter(length)
|
||||
Citizen.Wait(1)
|
||||
math.randomseed(GetGameTimer())
|
||||
if length > 0 then
|
||||
return GetRandomLetter(length - 1) .. Charset[math.random(1, #Charset)]
|
||||
else
|
||||
return ''
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user