Files
esx_core-esx-framework/client/main.lua
T
2018-04-15 18:42:08 +02:00

130 lines
3.0 KiB
Lua

local guiEnabled = false
local myIdentity = {}
ESX = nil
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
function EnableGui(enable)
SetNuiFocus(enable)
guiEnabled = enable
SendNUIMessage({
type = "enableui",
enable = enable
})
end
RegisterNetEvent("esx_identity:showRegisterIdentity")
AddEventHandler("esx_identity:showRegisterIdentity", function()
EnableGui(true)
end)
RegisterNUICallback('escape', function(data, cb)
EnableGui(false)
end)
RegisterNUICallback('register', function(data, cb)
local reason = ""
myIdentity = data
for theData, value in pairs(myIdentity) do
if theData == "firstname" or theData == "lastname" then
reason = verifyName(value)
if reason ~= "" then
break
end
elseif theData == "dateofbirth" then
if value == "invalid" then
reason = "Invalid date of birth!"
break
end
elseif theData == "height" then
local height = tonumber(value)
if height then
if height > 200 or height < 140 then
reason = "Unacceptable player height!"
break
end
else
reason = "Unacceptable player height!"
break
end
end
end
if reason == "" then
--TriggerServerEvent('esx_identity:setIdentity', data)
EnableGui(false)
Citizen.Wait(500)
--TriggerEvent('esx_skin:openSaveableMenu')
else
ESX.ShowNotification(reason)
end
end)
Citizen.CreateThread(function()
while true do
if guiEnabled then
DisableControlAction(0, 1, guiEnabled) -- LookLeftRight
DisableControlAction(0, 2, guiEnabled) -- LookUpDown
DisableControlAction(0, 142, guiEnabled) -- MeleeAttackAlternate
DisableControlAction(0, 106, guiEnabled) -- VehicleMouseControlOverride
if IsDisabledControlJustReleased(0, 142) then -- MeleeAttackAlternate
SendNUIMessage({
type = "click"
})
end
end
Citizen.Wait(10)
end
end)
function verifyName(name)
-- Don't allow short user names
local nameLength = string.len(name)
if nameLength > 25 or nameLength < 5 then
return 'Your player name is either too short or too long.'
end
-- Don't allow special characters (doesn't always work)
local count = 0
for i in name:gmatch('[abcdefghijklmnopqrstuvwxyzåäöABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ0123456789 -]') do
count = count + 1
end
if count ~= nameLength then
return 'Your player name contains special characters that are not allowed on this server.'
end
-- Does the player carry a first and last name?
--
-- Example:
-- Allowed: 'Bob Joe'
-- Not allowed: 'Bob'
-- Not allowed: 'Bob joe'
local spacesInName = 0
local spacesWithUpper = 0
for word in string.gmatch(name, '%S+') do
if string.match(word, '%u') then
spacesWithUpper = spacesWithUpper + 1
end
spacesInName = spacesInName + 1
end
if spacesInName > 2 then
return 'Your name contains more than two spaces'
end
if spacesWithUpper ~= spacesInName then
return 'your name must start with a capital letter.'
end
return ''
end