remove code duplication

This commit is contained in:
Csoki
2022-11-26 21:08:30 +01:00
parent 4eefe97270
commit 30546999a8
+21 -42
View File
@@ -374,33 +374,33 @@ else
ESX.RegisterServerCallback('esx_identity:registerIdentity', function(source, cb, data)
local xPlayer = ESX.GetPlayerFromId(source)
if not checkNameFormat(data.firstname) then
xPlayer.showNotification(TranslateCap('invalid_firstname_format'), "error")
return cb(false)
end
if not checkNameFormat(data.lastname) then
xPlayer.showNotification(TranslateCap('invalid_lastname_format'), "error")
return cb(false)
end
if not checkSexFormat(data.sex) then
xPlayer.showNotification(TranslateCap('invalid_sex_format'), "error")
return cb(false)
end
if not checkDOBFormat(data.dateofbirth) then
xPlayer.showNotification(TranslateCap('invalid_dob_format'), "error")
return cb(false)
end
if not checkHeightFormat(data.height) then
xPlayer.showNotification(TranslateCap('invalid_height_format'), "error")
return cb(false)
end
if xPlayer then
if alreadyRegistered[xPlayer.identifier] then
xPlayer.showNotification(TranslateCap('already_registered'), "error")
return cb(false)
end
if not checkNameFormat(data.firstname) then
xPlayer.showNotification(TranslateCap('invalid_firstname_format'), "error")
return cb(false)
end
if not checkNameFormat(data.lastname) then
xPlayer.showNotification(TranslateCap('invalid_lastname_format'), "error")
return cb(false)
end
if not checkSexFormat(data.sex) then
xPlayer.showNotification(TranslateCap('invalid_sex_format'), "error")
return cb(false)
end
if not checkDOBFormat(data.dateofbirth) then
xPlayer.showNotification(TranslateCap('invalid_dob_format'), "error")
return cb(false)
end
if not checkHeightFormat(data.height) then
xPlayer.showNotification(TranslateCap('invalid_height_format'), "error")
return cb(false)
end
playerIdentity[xPlayer.identifier] = {
firstName = formatName(data.firstname),
lastName = formatName(data.lastname),
@@ -428,27 +428,6 @@ else
TriggerClientEvent("esx:showNotification", source, TranslateCap('data_incorrect'), "error")
return cb(false)
end
if not checkNameFormat(data.firstname) then
TriggerClientEvent("esx:showNotification", source, TranslateCap('invalid_firstname_format'), "error")
return cb(false)
end
if not checkNameFormat(data.lastname) then
TriggerClientEvent("esx:showNotification", source, TranslateCap('invalid_lastname_format'), "error")
return cb(false)
end
if not checkSexFormat(data.sex) then
TriggerClientEvent("esx:showNotification", source, TranslateCap('invalid_sex_format'), "error")
return cb(false)
end
if not checkDOBFormat(data.dateofbirth) then
TriggerClientEvent("esx:showNotification", source, TranslateCap('invalid_dob_format'), "error")
return cb(false)
end
if not checkHeightFormat(data.height) then
TriggerClientEvent("esx:showNotification", source, TranslateCap('invalid_height_format'), "error")
return cb(false)
end
local formattedFirstName = formatName(data.firstname)
local formattedLastName = formatName(data.lastname)