refactor: esx Identity, fix blur, remove unused code, formatting, Readme

![Preview](https://cdn.discordapp.com/attachments/714118962568364106/997871502798094426/Screenshot_51.png)
This commit is contained in:
Mycroft
2022-07-16 15:28:40 +01:00
parent b3580bc10b
commit e563756d45
13 changed files with 524 additions and 1233 deletions
-9
View File
@@ -1,9 +0,0 @@
root = true
[*]
indent_size = 4
indent_style = tab
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
+13 -36
View File
@@ -1,48 +1,25 @@
# esx_identity
<h1 align='center'>[ESX] Identity</a></h1><p align='center'><b><a href='https://discord.esx-framework.org/'>Discord</a> - <a href='https://esx-framework.org/'>Website</a> - <a href='https://docs.esx-framework.org/legacy/installation'>Documentation</a></b></h5>
A Core Resource that Allows the player to Pick their characters, Name, Gender, Hight and Date-of-birth.
![Preview](https://cdn.discordapp.com/attachments/714118962568364106/997871502798094426/Screenshot_51.png)
# Infomation
## Requirements
* Dependencies For Full Functionality
* [esx_skin](https://github.com/ESX-Org/esx_skin)
* [esx_policejob](https://github.com/ESX-Org/esx_policejob)
* [esx_society](https://github.com/ESX-Org/esx_society)
## Download & Installation
[esx_skin](./../esx_skin/README.md)
### Using [fvm](https://github.com/qlaffont/fvm-installer)
```
fvm install --save --folder=esx esx-org/esx_identity
```
## Commands
### Using Git
```
cd resources
git clone https://github.com/ESX-Org/esx_identity [esx]/esx_identity
```
### Manually
- Download https://github.com/ESX-Org/esx_identity/archive/master.zip
- Put it in the `[esx]` directory
## Installation
- Import `esx_identity.sql` in your database
- Add this to your `server.cfg`:
```
start esx_identity
```
- If you are using esx_policejob or esx_society, you need to enable the following in the scripts' `config.lua`:
```Config.EnableESXIdentity = true```
### Commands
```
/char
/chardel
```
# Legal
### License
esx_identity - rp characters
## Legal
esx_identity - Make your Character a Person!
Copyright (C) 2015-2022 Jérémie N'gadi
@@ -50,4 +27,4 @@ This program Is free software: you can redistribute it And/Or modify it under th
This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details.
You should have received a copy Of the GNU General Public License along with this program. If Not, see http://www.gnu.org/licenses/.
You should have received a copy Of the GNU General Public License along with this program. If Not, see <http://www.gnu.org/licenses/>.
+72 -69
View File
@@ -3,89 +3,92 @@ local ready = false
RegisterNetEvent('esx_identity:alreadyRegistered')
AddEventHandler('esx_identity:alreadyRegistered', function()
while not loadingScreenFinished do
Wait(100)
end
while not loadingScreenFinished do
Wait(100)
end
TriggerEvent('esx_skin:playerRegistered')
TriggerEvent('esx_skin:playerRegistered')
end)
AddEventHandler('esx:loadingScreenOff', function()
loadingScreenFinished = true
loadingScreenFinished = true
end)
RegisterNUICallback('ready', function(data, cb)
ready = true
cb(1)
ready = true
cb(1)
end)
if not Config.UseDeferrals then
local guiEnabled = false
local guiEnabled = false
function EnableGui(state)
SetNuiFocus(state, state)
guiEnabled = state
while not ready do
Wait(500)
end
SendNUIMessage({
type = "enableui",
enable = state
})
if state == false then ClearTimecycleModifier() end
end
function EnableGui(state)
SetNuiFocus(state, state)
guiEnabled = state
while not ready do
Wait(500)
end
if state then
SetTimecycleModifier("hud_def_blur")
else
ClearTimecycleModifier()
end
SendNUIMessage({
type = "enableui",
enable = state
})
end
RegisterNetEvent('esx_identity:showRegisterIdentity')
AddEventHandler('esx_identity:showRegisterIdentity', function()
TriggerEvent('esx_skin:resetFirstSpawn')
RegisterNetEvent('esx_identity:showRegisterIdentity')
AddEventHandler('esx_identity:showRegisterIdentity', function()
TriggerEvent('esx_skin:resetFirstSpawn')
if not ESX.PlayerData.dead then
EnableGui(true)
SetTimecycleModifier("hud_def_blur")
SetTimecycleModifierStrength(1)
end
end)
if not ESX.PlayerData.dead then
EnableGui(true)
end
end)
RegisterNUICallback('register', function(data, cb)
ESX.TriggerServerCallback('esx_identity:registerIdentity', function(callback)
if callback then
ESX.ShowNotification(_U('thank_you_for_registering'))
EnableGui(false)
if not ESX.GetConfig().Multichar then
TriggerEvent('esx_skin:playerRegistered')
end
else
ESX.ShowNotification(_U('registration_error'), "error", 5000)
end
end, data)
end)
RegisterNUICallback('register', function(data, cb)
ESX.TriggerServerCallback('esx_identity:registerIdentity', function(callback)
if callback then
ESX.ShowNotification(_U('thank_you_for_registering'))
EnableGui(false)
if not ESX.GetConfig().Multichar then TriggerEvent('esx_skin:playerRegistered') end
else
ESX.ShowNotification(_U('registration_error'), "error",5000)
end
end, data)
end)
CreateThread(function()
while true do
local sleep = 1500
CreateThread(function()
while true do
local sleep = 1500
if guiEnabled then
sleep = 0
DisableControlAction(0, 1, true) -- LookLeftRight
DisableControlAction(0, 2, true) -- LookUpDown
DisableControlAction(0, 106, true) -- VehicleMouseControlOverride
DisableControlAction(0, 142, true) -- MeleeAttackAlternate
DisableControlAction(0, 30, true) -- MoveLeftRight
DisableControlAction(0, 31, true) -- MoveUpDown
DisableControlAction(0, 21, true) -- disable sprint
DisableControlAction(0, 24, true) -- disable attack
DisableControlAction(0, 25, true) -- disable aim
DisableControlAction(0, 47, true) -- disable weapon
DisableControlAction(0, 58, true) -- disable weapon
DisableControlAction(0, 263, true) -- disable melee
DisableControlAction(0, 264, true) -- disable melee
DisableControlAction(0, 257, true) -- disable melee
DisableControlAction(0, 140, true) -- disable melee
DisableControlAction(0, 141, true) -- disable melee
DisableControlAction(0, 143, true) -- disable melee
DisableControlAction(0, 75, true) -- disable exit vehicle
DisableControlAction(27, 75, true) -- disable exit vehicle
end
Wait(sleep)
end
end)
if guiEnabled then
sleep = 0
DisableControlAction(0, 1, true) -- LookLeftRight
DisableControlAction(0, 2, true) -- LookUpDown
DisableControlAction(0, 106, true) -- VehicleMouseControlOverride
DisableControlAction(0, 142, true) -- MeleeAttackAlternate
DisableControlAction(0, 30, true) -- MoveLeftRight
DisableControlAction(0, 31, true) -- MoveUpDown
DisableControlAction(0, 21, true) -- disable sprint
DisableControlAction(0, 24, true) -- disable attack
DisableControlAction(0, 25, true) -- disable aim
DisableControlAction(0, 47, true) -- disable weapon
DisableControlAction(0, 58, true) -- disable weapon
DisableControlAction(0, 263, true) -- disable melee
DisableControlAction(0, 264, true) -- disable melee
DisableControlAction(0, 257, true) -- disable melee
DisableControlAction(0, 140, true) -- disable melee
DisableControlAction(0, 141, true) -- disable melee
DisableControlAction(0, 143, true) -- disable melee
DisableControlAction(0, 75, true) -- disable exit vehicle
DisableControlAction(27, 75, true) -- disable exit vehicle
end
Wait(sleep)
end
end)
end
+7 -7
View File
@@ -9,11 +9,11 @@ Config.UseDeferrals = false -- EXPERIMENTAL Character Registration Method.
-- These values are for the second input validation in server/main.lua
Config.MaxNameLength = 20
Config.MinHeight = 120
Config.MaxHeight = 220
Config.LowestYear = 1900
Config.HighestYear = 2021
Config.MaxNameLength = 20 -- Max Name Length.
Config.MinHeight = 120 -- 120 cm lowest height
Config.MaxHeight = 220 -- 220 cm max height.
Config.LowestYear = 1900 -- 112 years old is the oldest you can be.
Config.HighestYear = 2003 -- 18 years old is the youngest you can be.
Config.FullCharDelete = false
Config.EnableDebugging = false
Config.FullCharDelete = true -- Delete all reference to character.
Config.EnableDebugging = false -- prints for debugging :)
@@ -1,163 +0,0 @@
<html>
<head>
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body onkeydown="TriggeredKey(this)">
<div class="dialog">
<img id="logo" src="img/esx_identity.png" height="110px" width="332px">
<form id="register" name="register" action="#">
<input id="firstname" type="text" class="" name="firstname" placeholder="First Name (Max 16 Characters)" onKeyDown="if(this.value.length==16 && event.keyCode!=8) return false;" onkeypress="if (isNumber(event) == true)"><br>
<input id="lastname" type="text" class="" name="lastname" placeholder="Last Name (Max 16 Characters)" onKeyDown="if(this.value.length==16 && event.keyCode!=8) return false;" onkeypress="if (isNumber(event) == true)"><br>
<input id="dateofbirth" type="text" name="dateofbirth" class="" placeholder="Date of Birth (MM/DD/YYYY)" dateformat="M d y" min="01/01/1900" max="12/31/2020" onfocus="(this.type='date')" onkeypress="if ( isNaN(String.fromCharCode(event.keyCode) ))"><br>
<center>
<div class="radio-toolbar">
<input type="radio" id="radiom" name="sex" value="m" checked>
<label for="radiom">Male</label>
<input type="radio" id="radiof" name="sex" value="f">
<label for="radiof">Female</label>
</div>
</center>
<!-- <div class="range-wrap" style="width: 80%;">
<input type="range" id="height" class="range" min="48" max="96" value="48">
<output class="bubble"></output>
</div> -->
<button id="submit" type="submit"><font size="5px">Submit</font></button>
</form>
<center><font size="1px" color="red">If the submit button doesn't work, please ensure that you've entered the fields correctly.</font></center>
</div>
<script>
const allRanges = document.querySelectorAll(".range-wrap");
allRanges.forEach(wrap => {
const range = wrap.querySelector(".range");
const bubble = wrap.querySelector(".bubble");
range.addEventListener("input", () => {
setBubble(range, bubble);
});
setBubble(range, bubble);
});
function setBubble(range, bubble) {
const val = range.value;
const min = range.min ? range.min : 0;
const max = range.max ? range.max : 100;
const newVal = Number(((val - min) * 100) / (max - min));
bubble.innerHTML = 'Height: ' + val;
bubble.style.left = `calc(${newVal}% + (${8 - newVal * 0.15}px))`;
}
var myFirstName = document.getElementById('firstname');
var myLastName = document.getElementById('lastname');
var myDOB = document.getElementById('dateofbirth');
var myHeight = document.getElementById('height');
function isNumber(e) {
var key=e.which || e.KeyCode;
if ( key >=48 && key <= 57) {
return true;
}
else {
return false;
}
}
function checkFirstName() {
var value = myFirstName.value;
if(value.trim().match(/^[a-zA-Z][0-9a-zA-Z .,'-]*$/) == null) {
myFirstName.style.backgroundColor = '#E06666';
myFirstName.style.color = 'black';
}
else {
if(value.length > 0 && value.length < 17) {
myFirstName.style.backgroundColor = '#B6D7A8';
myFirstName.style.color = 'black';
}
else {
myFirstName.style.backgroundColor = '#E06666';
myFirstName.style.color = 'black';
}
}
}
function checkLastName() {
var value = myLastName.value;
if(value.trim().match(/^[a-zA-Z][0-9a-zA-Z .,'-]*$/) == null) {
myLastName.style.backgroundColor = '#E06666';
myLastName.style.color = 'black';
}
else {
if(value.length > 0 && value.length < 17) {
myLastName.style.backgroundColor = '#B6D7A8';
myLastName.style.color = 'black';
}
else {
myLastName.style.backgroundColor = '#E06666';
myLastName.style.color = 'black';
}
}
}
function checkDOB() {
var date = new Date($('#dateofbirth').val());
day = date.getDate();
month = date.getMonth() + 1;
year = date.getFullYear();
if (isNaN(month) || isNaN(day) || isNaN(year)) {
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else {
var dateInput = [month, day, year].join('/');
var regExp = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var dateArray = dateInput.match(regExp);
if (dateArray == null){
return false;
}
month = dateArray[1];
day= dateArray[3];
year = dateArray[5];
if (month < 1 || month > 12){
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else if (day < 1 || day> 31) {
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else if ((month==4 || month==6 || month==9 || month==11) && day ==31) {
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else if (month == 2) {
var isLeapYear = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day> 29 || (day ==29 && !isLeapYear)){
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
}
else {
myDOB.style.backgroundColor = '#B6D7A8';
myDOB.style.color = 'black';
}
}
}
function TriggeredKey(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
if (window.event.keyCode == 13 || window.event.keyCode == 27) return false;
}
</script>
<script src="js/script.js" type="text/javascript"></script>
</body>
</html>
@@ -1,150 +0,0 @@
<html>
<head>
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body onkeydown="TriggeredKey(this)">
<div class="dialog">
<img id="logo" src="img/esx_identity.png" height="110px" width="332px">
<form id="register" name="register" action="#">
<input id="firstname" type="text" class="" name="firstname" placeholder="First Name (Max 16 Characters)" onKeyDown="if(this.value.length==16 && event.keyCode!=8) return false;" onkeypress="if (isNumber(event) == true) return false;" onKeyUp="checkFirstName()" onmouseup="checkFirstName()"><br>
<input id="lastname" type="text" class="" name="lastname" placeholder="Last Name (Max 16 Characters)" onKeyDown="if(this.value.length==16 && event.keyCode!=8) return false;" onkeypress="if (isNumber(event) == true) return false;" onKeyUp="checkLastName()" onmouseup="checkLastName()"><br>
<input id="dateofbirth" type="text" name="dateofbirth" class="" placeholder="Date of Birth (MM/DD/YYYY)" dateformat="M d y" min="01/01/1900" max="12/31/2020" onfocus="(this.type='date')" onkeypress="if ( isNaN(String.fromCharCode(event.keyCode) )) return false;" onchange="checkDOB()" onKeyUp="checkDOB()" onmouseup="checkDOB()"><br>
<input id="height" type="number" class="" name="height" min="48" max="96" placeholder="Height In Inches (48-96)" onKeyDown="if(this.value.length==2 && event.keyCode!=8) return false;" onkeypress="if ( isNaN(String.fromCharCode(event.keyCode) )) return false;" onKeyUp="checkHeight()" onmouseup="checkHeight()"><br>
<center>
<div class="radio-toolbar">
<input type="radio" id="radiom" name="sex" value="m" checked>
<label for="radiom">Male</label>
<input type="radio" id="radiof" name="sex" value="f">
<label for="radiof">Female</label>
</div>
</center>
<button id="submit" type="submit"><font size="5px">Submit</font></button>
</form>
<center><font size="1px" color="red">If the submit button doesn't work, please ensure that you've entered the fields correctly.</font></center>
</div>
<script>
var myFirstName = document.getElementById('firstname');
var myLastName = document.getElementById('lastname');
var myDOB = document.getElementById('dateofbirth');
var myHeight = document.getElementById('height');
function isNumber(e) {
var key=e.which || e.KeyCode;
if ( key >=48 && key <= 57) {
return true;
}
else {
return false;
}
}
function checkFirstName() {
var value = myFirstName.value;
if(value.trim().match(/^[a-zA-Z][0-9a-zA-Z .,'-]*$/) == null) {
myFirstName.style.backgroundColor = '#E06666';
myFirstName.style.color = 'black';
}
else {
if(value.length > 0 && value.length < 17) {
myFirstName.style.backgroundColor = '#B6D7A8';
myFirstName.style.color = 'black';
}
else {
myFirstName.style.backgroundColor = '#E06666';
myFirstName.style.color = 'black';
}
}
}
function checkLastName() {
var value = myLastName.value;
if(value.trim().match(/^[a-zA-Z][0-9a-zA-Z .,'-]*$/) == null) {
myLastName.style.backgroundColor = '#E06666';
myLastName.style.color = 'black';
}
else {
if(value.length > 0 && value.length < 17) {
myLastName.style.backgroundColor = '#B6D7A8';
myLastName.style.color = 'black';
}
else {
myLastName.style.backgroundColor = '#E06666';
myLastName.style.color = 'black';
}
}
}
function checkDOB() {
var date = new Date($('#dateofbirth').val());
day = date.getDate();
month = date.getMonth() + 1;
year = date.getFullYear();
if (isNaN(month) || isNaN(day) || isNaN(year)) {
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else {
var dateInput = [month, day, year].join('/');
var regExp = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var dateArray = dateInput.match(regExp);
if (dateArray == null){
return false;
}
month = dateArray[1];
day= dateArray[3];
year = dateArray[5];
if (month < 1 || month > 12){
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else if (day < 1 || day> 31) {
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else if ((month==4 || month==6 || month==9 || month==11) && day ==31) {
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else if (month == 2) {
var isLeapYear = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day> 29 || (day ==29 && !isLeapYear)){
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
}
else {
myDOB.style.backgroundColor = '#B6D7A8';
myDOB.style.color = 'black';
}
}
}
function checkHeight() {
var value = myHeight.value;
if (!value || isNaN(value) || parseInt(value, 10) < 48 || parseInt(value, 10) > 96) {
myHeight.style.backgroundColor = '#E06666';
myHeight.style.color = 'black';
} else {
myHeight.style.backgroundColor = '#B6D7A8';
myHeight.style.color = 'black';
}
}
function TriggeredKey(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
if (window.event.keyCode == 13 || window.event.keyCode == 27) return false;
}
</script>
<script src="js/script.js" type="text/javascript"></script>
</body>
</html>
@@ -1,163 +0,0 @@
<html>
<head>
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body onkeydown="TriggeredKey(this)">
<div class="dialog">
<img id="logo" src="img/esx_identity.png" height="110px" width="332px">
<form id="register" name="register" action="#">
<input id="firstname" type="text" class="" name="firstname" placeholder="First Name (Max 16 Characters)" onKeyDown="if(this.value.length==16 && event.keyCode!=8) return false;" onkeypress="if (isNumber(event) == true) return false;" onKeyUp="checkFirstName()" onmouseup="checkFirstName()"><br>
<input id="lastname" type="text" class="" name="lastname" placeholder="Last Name (Max 16 Characters)" onKeyDown="if(this.value.length==16 && event.keyCode!=8) return false;" onkeypress="if (isNumber(event) == true) return false;" onKeyUp="checkLastName()" onmouseup="checkLastName()"><br>
<input id="dateofbirth" type="text" name="dateofbirth" class="" placeholder="Date of Birth (MM/DD/YYYY)" dateformat="M d y" min="01/01/1900" max="12/31/2020" onfocus="(this.type='date')" onkeypress="if ( isNaN(String.fromCharCode(event.keyCode) )) return false;" onchange="checkDOB()" onKeyUp="checkDOB()" onmouseup="checkDOB()"><br>
<center>
<div class="radio-toolbar">
<input type="radio" id="radiom" name="sex" value="m" checked>
<label for="radiom">Male</label>
<input type="radio" id="radiof" name="sex" value="f">
<label for="radiof">Female</label>
</div>
</center>
<div class="range-wrap" style="width: 80%;">
<input type="range" id="height" class="range" min="48" max="96" value="48">
<output class="bubble"></output>
</div>
<button id="submit" type="submit"><font size="5px">Submit</font></button>
</form>
<center><font size="1px" color="red">If the submit button doesn't work, please ensure that you've entered the fields correctly.</font></center>
</div>
<script>
const allRanges = document.querySelectorAll(".range-wrap");
allRanges.forEach(wrap => {
const range = wrap.querySelector(".range");
const bubble = wrap.querySelector(".bubble");
range.addEventListener("input", () => {
setBubble(range, bubble);
});
setBubble(range, bubble);
});
function setBubble(range, bubble) {
const val = range.value;
const min = range.min ? range.min : 0;
const max = range.max ? range.max : 100;
const newVal = Number(((val - min) * 100) / (max - min));
bubble.innerHTML = 'Height: ' + val;
bubble.style.left = `calc(${newVal}% + (${8 - newVal * 0.15}px))`;
}
var myFirstName = document.getElementById('firstname');
var myLastName = document.getElementById('lastname');
var myDOB = document.getElementById('dateofbirth');
var myHeight = document.getElementById('height');
function isNumber(e) {
var key=e.which || e.KeyCode;
if ( key >=48 && key <= 57) {
return true;
}
else {
return false;
}
}
function checkFirstName() {
var value = myFirstName.value;
if(value.trim().match(/^[a-zA-Z][0-9a-zA-Z .,'-]*$/) == null) {
myFirstName.style.backgroundColor = '#E06666';
myFirstName.style.color = 'black';
}
else {
if(value.length > 0 && value.length < 17) {
myFirstName.style.backgroundColor = '#B6D7A8';
myFirstName.style.color = 'black';
}
else {
myFirstName.style.backgroundColor = '#E06666';
myFirstName.style.color = 'black';
}
}
}
function checkLastName() {
var value = myLastName.value;
if(value.trim().match(/^[a-zA-Z][0-9a-zA-Z .,'-]*$/) == null) {
myLastName.style.backgroundColor = '#E06666';
myLastName.style.color = 'black';
}
else {
if(value.length > 0 && value.length < 17) {
myLastName.style.backgroundColor = '#B6D7A8';
myLastName.style.color = 'black';
}
else {
myLastName.style.backgroundColor = '#E06666';
myLastName.style.color = 'black';
}
}
}
function checkDOB() {
var date = new Date($('#dateofbirth').val());
day = date.getDate();
month = date.getMonth() + 1;
year = date.getFullYear();
if (isNaN(month) || isNaN(day) || isNaN(year)) {
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else {
var dateInput = [month, day, year].join('/');
var regExp = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var dateArray = dateInput.match(regExp);
if (dateArray == null){
return false;
}
month = dateArray[1];
day= dateArray[3];
year = dateArray[5];
if (month < 1 || month > 12){
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else if (day < 1 || day> 31) {
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else if ((month==4 || month==6 || month==9 || month==11) && day ==31) {
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else if (month == 2) {
var isLeapYear = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day> 29 || (day ==29 && !isLeapYear)){
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
}
else {
myDOB.style.backgroundColor = '#B6D7A8';
myDOB.style.color = 'black';
}
}
}
function TriggeredKey(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
if (window.event.keyCode == 13 || window.event.keyCode == 27) return false;
}
</script>
<script src="js/script.js" type="text/javascript"></script>
</body>
</html>
@@ -1,150 +0,0 @@
<html>
<head>
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body onkeydown="TriggeredKey(this)">
<div class="dialog">
<img id="logo" src="img/esx_identity.png" height="110px" width="332px">
<form id="register" name="register" action="#">
<input id="firstname" type="text" class="" name="firstname" placeholder="First Name (Max 16 Characters)" onKeyDown="if(this.value.length==16 && event.keyCode!=8) return false;" onkeypress="if (isNumber(event) == true) return false;" onKeyUp="checkFirstName()" onmouseup="checkFirstName()"><br>
<input id="lastname" type="text" class="" name="lastname" placeholder="Last Name (Max 16 Characters)" onKeyDown="if(this.value.length==16 && event.keyCode!=8) return false;" onkeypress="if (isNumber(event) == true) return false;" onKeyUp="checkLastName()" onmouseup="checkLastName()"><br>
<input id="dateofbirth" type="text" name="dateofbirth" class="" placeholder="Date of Birth (MM/DD/YYYY)" dateformat="M d y" min="01/01/1900" max="12/31/2020" onfocus="(this.type='date')" onkeypress="if ( isNaN(String.fromCharCode(event.keyCode) )) return false;" onchange="checkDOB()" onKeyUp="checkDOB()" onmouseup="checkDOB()"><br>
<input id="height" type="number" class="" name="height" min="48" max="96" placeholder="Height In Inches (48-96)" onKeyDown="if(this.value.length==2 && event.keyCode!=8) return false;" onkeypress="if ( isNaN(String.fromCharCode(event.keyCode) )) return false;" onKeyUp="checkHeight()" onmouseup="checkHeight()"><br>
<center>
<div class="radio-toolbar">
<input type="radio" id="radiom" name="sex" value="m" checked>
<label for="radiom">Male</label>
<input type="radio" id="radiof" name="sex" value="f">
<label for="radiof">Female</label>
</div>
</center>
<button id="submit" type="submit"><font size="5px">Submit</font></button>
</form>
<center><font size="1px" color="red">If the submit button doesn't work, please ensure that you've entered the fields correctly.</font></center>
</div>
<script>
var myFirstName = document.getElementById('firstname');
var myLastName = document.getElementById('lastname');
var myDOB = document.getElementById('dateofbirth');
var myHeight = document.getElementById('height');
function isNumber(e) {
var key=e.which || e.KeyCode;
if ( key >=48 && key <= 57) {
return true;
}
else {
return false;
}
}
function checkFirstName() {
var value = myFirstName.value;
if(value.trim().match(/^[a-zA-Z][0-9a-zA-Z .,'-]*$/) == null) {
myFirstName.style.backgroundColor = '#E06666';
myFirstName.style.color = 'black';
}
else {
if(value.length > 0 && value.length < 17) {
myFirstName.style.backgroundColor = '#B6D7A8';
myFirstName.style.color = 'black';
}
else {
myFirstName.style.backgroundColor = '#E06666';
myFirstName.style.color = 'black';
}
}
}
function checkLastName() {
var value = myLastName.value;
if(value.trim().match(/^[a-zA-Z][0-9a-zA-Z .,'-]*$/) == null) {
myLastName.style.backgroundColor = '#E06666';
myLastName.style.color = 'black';
}
else {
if(value.length > 0 && value.length < 17) {
myLastName.style.backgroundColor = '#B6D7A8';
myLastName.style.color = 'black';
}
else {
myLastName.style.backgroundColor = '#E06666';
myLastName.style.color = 'black';
}
}
}
function checkDOB() {
var date = new Date($('#dateofbirth').val());
day = date.getDate();
month = date.getMonth() + 1;
year = date.getFullYear();
if (isNaN(month) || isNaN(day) || isNaN(year)) {
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else {
var dateInput = [month, day, year].join('/');
var regExp = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var dateArray = dateInput.match(regExp);
if (dateArray == null){
return false;
}
month = dateArray[1];
day= dateArray[3];
year = dateArray[5];
if (month < 1 || month > 12){
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else if (day < 1 || day> 31) {
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else if ((month==4 || month==6 || month==9 || month==11) && day ==31) {
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
else if (month == 2) {
var isLeapYear = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day> 29 || (day ==29 && !isLeapYear)){
myDOB.style.backgroundColor = '#E06666';
myDOB.style.color = 'black';
}
}
else {
myDOB.style.backgroundColor = '#B6D7A8';
myDOB.style.color = 'black';
}
}
}
function checkHeight() {
var value = myHeight.value;
if (!value || isNaN(value) || parseInt(value, 10) < 48 || parseInt(value, 10) > 96) {
myHeight.style.backgroundColor = '#E06666';
myHeight.style.color = 'black';
} else {
myHeight.style.backgroundColor = '#B6D7A8';
myHeight.style.color = 'black';
}
}
function TriggeredKey(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
if (window.event.keyCode == 13 || window.event.keyCode == 27) return false;
}
</script>
<script src="js/script.js" type="text/javascript"></script>
</body>
</html>
@@ -1,22 +0,0 @@
<html>
<head>
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="dialog">
<form id="register">
<h1>Register</h1>
<input id="firstname" type="text" placeholder="Křestní jméno"><br>
<input id="lastname" type="text" placeholder="Příjmení"><br>
<input id="dateofbirth" type="text" placeholder="Datum narození (YYYY-MM-DD)"><br>
<input id="height" type="text" placeholder="Výška (140-200 cm)"><br><center>
<input type="radio" name="sex" value="m" checked>Male
<input type="radio" name="sex" value="ž">Female<br></center>
<button id="submit" type="submit">Vytvořit</button>
</form>
</div>
<script src="script.js" type="text/javascript"></script>
</body>
</html>
@@ -1,22 +0,0 @@
<html>
<head>
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="dialog">
<form id="register">
<h1>Rekistöröinti</h1>
<input id="firstname" type="text" placeholder="Etunimi"><br>
<input id="lastname" type="text" placeholder="Sukunimi"><br>
<input id="dateofbirth" type="text" placeholder="Syntymäaika (PP.KK.VVVV)"><br>
<input id="height" type="text" placeholder="Pituus (140-200 cm)"><br><center>
<input type="radio" name="sex" value="m" checked>Mies
<input type="radio" name="sex" value="f">Nainen<br></center>
<button id="submit" type="submit">Luo</button>
</form>
</div>
<script src="script.js" type="text/javascript"></script>
</body>
</html>
@@ -1,22 +0,0 @@
<html>
<head>
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="dialog">
<form id="register">
<h1>등록</h1>
<input id="firstname" type="text" placeholder="이름"><br>
<input id="lastname" type="text" placeholder="성"><br>
<input id="dateofbirth" type="text" placeholder="생일 (YYYY-MM-DD)"><br>
<input id="height" type="text" placeholder="키 (140-200 cm)"><br><center>
<input type="radio" name="sex" value="m" checked>남자
<input type="radio" name="sex" value="f">여자<br></center>
<button id="submit" type="submit">생성</button>
</form>
</div>
<script src="script.js" type="text/javascript"></script>
</body>
</html>
@@ -1,22 +0,0 @@
<html>
<head>
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="dialog">
<form id="register">
<h1>Registrera</h1>
<input id="firstname" type="text" placeholder="Förnamn"><br>
<input id="lastname" type="text" placeholder="Efternamn"><br>
<input id="dateofbirth" type="text" placeholder="Födelsedatum (YYYY-MM-DD)"><br>
<input id="height" type="text" placeholder="Längd (140-200 cm)"><br><center>
<input type="radio" name="sex" value="m" checked>Man
<input type="radio" name="sex" value="f">Kvinna<br></center>
<button id="submit" type="submit">Skapa</button>
</form>
</div>
<script src="script.js" type="text/javascript"></script>
</body>
</html>
+432 -398
View File
@@ -3,481 +3,515 @@ local alreadyRegistered = {}
local multichar = ESX.GetConfig().Multichar
if Config.UseDeferrals then
AddEventHandler('playerConnecting', function(playerName, setKickReason, deferrals)
deferrals.defer()
local playerId, identifier = source, ESX.GetIdentifier(source)
Wait(100)
if identifier then
MySQL.single('SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = ?', {identifier},
function(result)
if result then
if result.firstname then
playerIdentity[identifier] = {
firstName = result.firstname,
lastName = result.lastname,
dateOfBirth = result.dateofbirth,
sex = result.sex,
height = result.height
}
deferrals.done()
else
deferrals.presentCard([==[{"type": "AdaptiveCard","body":[{"type":"Container","items":[{"type":"ColumnSet","columns":[{"type":"Column","items":[{"type":"Input.Text","placeholder":"First Name","id":"firstname","maxLength":15},{"type":"Input.Text","placeholder":"Date of Birth (MM/DD/YYYY)","id":"dateofbirth","maxLength":10}],"width":"stretch"},{"type":"Column","width":"stretch","items":[{"type":"Input.Text","placeholder":"Last Name","id":"lastname","maxLength":15},{"type":"Input.Text","placeholder":"Height (48-96 inches)","id":"height","maxLength":2}]}]},{"type":"Input.ChoiceSet","placeholder":"Sex","choices":[{"title":"Male","value":"m"},{"title":"Female","value":"f"}],"style":"expanded","id":"sex"}]},{"type": "ActionSet","actions": [{"type":"Action.Submit","title":"Submit"}]}],"$schema": "http://adaptivecards.io/schemas/adaptive-card.json","version":"1.0"}]==], function(data, rawData)
if data.firstname == '' or data.lastname == '' or data.dateofbirth == '' or data.sex == '' or data.height == '' then
deferrals.done(_U('data_incorrect'))
else
if checkNameFormat(data.firstname) and checkNameFormat(data.lastname) and checkDOBFormat(data.dateofbirth) and checkSexFormat(data.sex) and checkHeightFormat(data.height) then
playerIdentity[identifier] = {
firstName = formatName(data.firstname),
lastName = formatName(data.lastname),
dateOfBirth = data.dateofbirth,
sex = data.sex,
height = tonumber(data.height),
saveToDatabase = true
}
deferrals.done()
else
deferrals.done(_U('invalid_format'))
end
end
end)
end
else
deferrals.presentCard([==[{"type": "AdaptiveCard","body":[{"type":"Container","items":[{"type":"ColumnSet","columns":[{"type":"Column","items":[{"type":"Input.Text","placeholder":"First Name","id":"firstname","maxLength":15},{"type":"Input.Text","placeholder":"Date of Birth (MM/DD/YYYY)","id":"dateofbirth","maxLength":10}],"width":"stretch"},{"type":"Column","width":"stretch","items":[{"type":"Input.Text","placeholder":"Last Name","id":"lastname","maxLength":15},{"type":"Input.Text","placeholder":"Height (48-96 inches)","id":"height","maxLength":2}]}]},{"type":"Input.ChoiceSet","placeholder":"Sex","choices":[{"title":"Male","value":"m"},{"title":"Female","value":"f"}],"style":"expanded","id":"sex"}]},{"type": "ActionSet","actions": [{"type":"Action.Submit","title":"Submit"}]}],"$schema": "http://adaptivecards.io/schemas/adaptive-card.json","version":"1.0"}]==], function(data, rawData)
if data.firstname == '' or data.lastname == '' or data.dateofbirth == '' or data.sex == '' or data.height == '' then
deferrals.done(_U('data_incorrect'))
else
if checkNameFormat(data.firstname) and checkNameFormat(data.lastname) and checkDOBFormat(data.dateofbirth) and checkSexFormat(data.sex) and checkHeightFormat(data.height) then
playerIdentity[identifier] = {
firstName = formatName(data.firstname),
lastName = formatName(data.lastname),
dateOfBirth = data.dateofbirth,
sex = data.sex,
height = tonumber(data.height),
saveToDatabase = true
}
deferrals.done()
else
deferrals.done(_U('invalid_format'))
end
end
end)
end
end)
else
deferrals.done(_U('no_identifier'))
end
end)
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
if playerIdentity[xPlayer.identifier] then
local currentIdentity = playerIdentity[xPlayer.identifier]
xPlayer.setName(('%s %s'):format(currentIdentity.firstName, currentIdentity.lastName))
xPlayer.set('firstName', currentIdentity.firstName)
xPlayer.set('lastName', currentIdentity.lastName)
xPlayer.set('dateofbirth', currentIdentity.dateOfBirth)
xPlayer.set('sex', currentIdentity.sex)
xPlayer.set('height', currentIdentity.height)
if currentIdentity.saveToDatabase then
saveIdentityToDatabase(xPlayer.identifier, currentIdentity)
end
AddEventHandler('playerConnecting', function(playerName, setKickReason, deferrals)
deferrals.defer()
local playerId, identifier = source, ESX.GetIdentifier(source)
Wait(100)
Wait(0)
alreadyRegistered[xPlayer.identifier] = true
TriggerClientEvent('esx_identity:alreadyRegistered', xPlayer.source)
playerIdentity[xPlayer.identifier] = nil
else
xPlayer.kick(_('missing_identity'))
end
end)
if identifier then
MySQL.single('SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = ?',
{identifier}, function(result)
if result then
if result.firstname then
playerIdentity[identifier] = {
firstName = result.firstname,
lastName = result.lastname,
dateOfBirth = result.dateofbirth,
sex = result.sex,
height = result.height
}
deferrals.done()
else
deferrals.presentCard(
[==[{"type": "AdaptiveCard","body":[{"type":"Container","items":[{"type":"ColumnSet","columns":[{"type":"Column","items":[{"type":"Input.Text","placeholder":"First Name","id":"firstname","maxLength":15},{"type":"Input.Text","placeholder":"Date of Birth (MM/DD/YYYY)","id":"dateofbirth","maxLength":10}],"width":"stretch"},{"type":"Column","width":"stretch","items":[{"type":"Input.Text","placeholder":"Last Name","id":"lastname","maxLength":15},{"type":"Input.Text","placeholder":"Height (48-96 inches)","id":"height","maxLength":2}]}]},{"type":"Input.ChoiceSet","placeholder":"Sex","choices":[{"title":"Male","value":"m"},{"title":"Female","value":"f"}],"style":"expanded","id":"sex"}]},{"type": "ActionSet","actions": [{"type":"Action.Submit","title":"Submit"}]}],"$schema": "http://adaptivecards.io/schemas/adaptive-card.json","version":"1.0"}]==],
function(data, rawData)
if data.firstname == '' or data.lastname == '' or data.dateofbirth == '' or data.sex ==
'' or data.height == '' then
deferrals.done(_U('data_incorrect'))
else
if checkNameFormat(data.firstname) and checkNameFormat(data.lastname) and
checkDOBFormat(data.dateofbirth) and checkSexFormat(data.sex) and
checkHeightFormat(data.height) then
playerIdentity[identifier] = {
firstName = formatName(data.firstname),
lastName = formatName(data.lastname),
dateOfBirth = data.dateofbirth,
sex = data.sex,
height = tonumber(data.height),
saveToDatabase = true
}
deferrals.done()
else
deferrals.done(_U('invalid_format'))
end
end
end)
end
else
deferrals.presentCard(
[==[{"type": "AdaptiveCard","body":[{"type":"Container","items":[{"type":"ColumnSet","columns":[{"type":"Column","items":[{"type":"Input.Text","placeholder":"First Name","id":"firstname","maxLength":15},{"type":"Input.Text","placeholder":"Date of Birth (MM/DD/YYYY)","id":"dateofbirth","maxLength":10}],"width":"stretch"},{"type":"Column","width":"stretch","items":[{"type":"Input.Text","placeholder":"Last Name","id":"lastname","maxLength":15},{"type":"Input.Text","placeholder":"Height (48-96 inches)","id":"height","maxLength":2}]}]},{"type":"Input.ChoiceSet","placeholder":"Sex","choices":[{"title":"Male","value":"m"},{"title":"Female","value":"f"}],"style":"expanded","id":"sex"}]},{"type": "ActionSet","actions": [{"type":"Action.Submit","title":"Submit"}]}],"$schema": "http://adaptivecards.io/schemas/adaptive-card.json","version":"1.0"}]==],
function(data, rawData)
if data.firstname == '' or data.lastname == '' or data.dateofbirth == '' or data.sex ==
'' or data.height == '' then
deferrals.done(_U('data_incorrect'))
else
if checkNameFormat(data.firstname) and checkNameFormat(data.lastname) and
checkDOBFormat(data.dateofbirth) and checkSexFormat(data.sex) and
checkHeightFormat(data.height) then
playerIdentity[identifier] = {
firstName = formatName(data.firstname),
lastName = formatName(data.lastname),
dateOfBirth = data.dateofbirth,
sex = data.sex,
height = tonumber(data.height),
saveToDatabase = true
}
deferrals.done()
else
deferrals.done(_U('invalid_format'))
end
end
end)
end
end)
else
deferrals.done(_U('no_identifier'))
end
end)
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
if playerIdentity[xPlayer.identifier] then
local currentIdentity = playerIdentity[xPlayer.identifier]
xPlayer.setName(('%s %s'):format(currentIdentity.firstName, currentIdentity.lastName))
xPlayer.set('firstName', currentIdentity.firstName)
xPlayer.set('lastName', currentIdentity.lastName)
xPlayer.set('dateofbirth', currentIdentity.dateOfBirth)
xPlayer.set('sex', currentIdentity.sex)
xPlayer.set('height', currentIdentity.height)
if currentIdentity.saveToDatabase then
saveIdentityToDatabase(xPlayer.identifier, currentIdentity)
end
Wait(0)
alreadyRegistered[xPlayer.identifier] = true
TriggerClientEvent('esx_identity:alreadyRegistered', xPlayer.source)
playerIdentity[xPlayer.identifier] = nil
else
xPlayer.kick(_('missing_identity'))
end
end)
elseif not Config.UseDeferrals then
if not multichar then
AddEventHandler('playerConnecting', function(playerName, setKickReason, deferrals)
deferrals.defer()
local playerId, identifier = source, ESX.GetIdentifier(source)
Wait(40)
if not multichar then
AddEventHandler('playerConnecting', function(playerName, setKickReason, deferrals)
deferrals.defer()
local playerId, identifier = source, ESX.GetIdentifier(source)
Wait(40)
if identifier then
MySQL.single('SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = ?', {identifier},
function(result)
if result then
if result.firstname then
playerIdentity[identifier] = {
firstName = result.firstname,
lastName = result.lastname,
dateOfBirth = result.dateofbirth,
sex = result.sex,
height = result.height
}
if identifier then
MySQL.single('SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = ?',
{identifier}, function(result)
if result then
if result.firstname then
playerIdentity[identifier] = {
firstName = result.firstname,
lastName = result.lastname,
dateOfBirth = result.dateofbirth,
sex = result.sex,
height = result.height
}
alreadyRegistered[identifier] = true
alreadyRegistered[identifier] = true
deferrals.done()
else
playerIdentity[identifier] = nil
alreadyRegistered[identifier] = false
deferrals.done()
end
else
playerIdentity[identifier] = nil
alreadyRegistered[identifier] = false
deferrals.done()
end
end)
else
deferrals.done(_U('no_identifier'))
end
end)
deferrals.done()
else
playerIdentity[identifier] = nil
alreadyRegistered[identifier] = false
deferrals.done()
end
else
playerIdentity[identifier] = nil
alreadyRegistered[identifier] = false
deferrals.done()
end
end)
else
deferrals.done(_U('no_identifier'))
end
end)
AddEventHandler('onResourceStart', function(resource)
if resource == GetCurrentResourceName() then
Wait(300)
AddEventHandler('onResourceStart', function(resource)
if resource == GetCurrentResourceName() then
Wait(300)
while not ESX do
Wait(0)
end
while not ESX do
Wait(0)
end
local xPlayers = ESX.GetExtendedPlayers()
for _, xPlayer in pairs(xPlayers) do
if xPlayer then
checkIdentity(xPlayer)
end
end
end
end)
local xPlayers = ESX.GetExtendedPlayers()
for _, xPlayer in pairs(xPlayers) do
if xPlayer then
checkIdentity(xPlayer)
end
end
end
end)
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
local currentIdentity = playerIdentity[xPlayer.identifier]
if currentIdentity and alreadyRegistered[xPlayer.identifier] == true then
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
local currentIdentity = playerIdentity[xPlayer.identifier]
if currentIdentity and alreadyRegistered[xPlayer.identifier] == true then
xPlayer.setName(('%s %s'):format(currentIdentity.firstName, currentIdentity.lastName))
xPlayer.set('firstName', currentIdentity.firstName)
xPlayer.set('lastName', currentIdentity.lastName)
xPlayer.set('dateofbirth', currentIdentity.dateOfBirth)
xPlayer.set('sex', currentIdentity.sex)
xPlayer.set('height', currentIdentity.height)
xPlayer.setName(('%s %s'):format(currentIdentity.firstName, currentIdentity.lastName))
xPlayer.set('firstName', currentIdentity.firstName)
xPlayer.set('lastName', currentIdentity.lastName)
xPlayer.set('dateofbirth', currentIdentity.dateOfBirth)
xPlayer.set('sex', currentIdentity.sex)
xPlayer.set('height', currentIdentity.height)
if currentIdentity.saveToDatabase then
saveIdentityToDatabase(xPlayer.identifier, currentIdentity)
end
if currentIdentity.saveToDatabase then
saveIdentityToDatabase(xPlayer.identifier, currentIdentity)
end
Wait(0)
TriggerClientEvent('esx_identity:alreadyRegistered', xPlayer.source)
Wait(0)
TriggerClientEvent('esx_identity:alreadyRegistered', xPlayer.source)
playerIdentity[xPlayer.identifier] = nil
else
TriggerClientEvent('esx_identity:showRegisterIdentity', xPlayer.source)
end
end)
end
playerIdentity[xPlayer.identifier] = nil
else
TriggerClientEvent('esx_identity:showRegisterIdentity', xPlayer.source)
end
end)
end
ESX.RegisterServerCallback('esx_identity:registerIdentity', function(source, cb, data)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
if not alreadyRegistered[xPlayer.identifier] then
if checkNameFormat(data.firstname) and checkNameFormat(data.lastname) and checkSexFormat(data.sex) and checkDOBFormat(data.dateofbirth) and checkHeightFormat(data.height) then
playerIdentity[xPlayer.identifier] = {
firstName = formatName(data.firstname),
lastName = formatName(data.lastname),
dateOfBirth = data.dateofbirth,
sex = data.sex,
height = data.height
}
ESX.RegisterServerCallback('esx_identity:registerIdentity', function(source, cb, data)
local xPlayer = ESX.GetPlayerFromId(source)
local currentIdentity = playerIdentity[xPlayer.identifier]
if xPlayer then
if not alreadyRegistered[xPlayer.identifier] then
if checkNameFormat(data.firstname) and checkNameFormat(data.lastname) and checkSexFormat(data.sex) and
checkDOBFormat(data.dateofbirth) and checkHeightFormat(data.height) then
playerIdentity[xPlayer.identifier] = {
firstName = formatName(data.firstname),
lastName = formatName(data.lastname),
dateOfBirth = data.dateofbirth,
sex = data.sex,
height = data.height
}
xPlayer.setName(('%s %s'):format(currentIdentity.firstName, currentIdentity.lastName))
xPlayer.set('firstName', currentIdentity.firstName)
xPlayer.set('lastName', currentIdentity.lastName)
xPlayer.set('dateofbirth', currentIdentity.dateOfBirth)
xPlayer.set('sex', currentIdentity.sex)
xPlayer.set('height', currentIdentity.height)
local currentIdentity = playerIdentity[xPlayer.identifier]
saveIdentityToDatabase(xPlayer.identifier, currentIdentity)
alreadyRegistered[xPlayer.identifier] = true
playerIdentity[xPlayer.identifier] = nil
cb(true)
else
cb(false)
end
else
cb(false)
end
else
if multichar and checkNameFormat(data.firstname) and checkNameFormat(data.lastname) and checkSexFormat(data.sex) and checkDOBFormat(data.dateofbirth) and checkHeightFormat(data.height) then
TriggerEvent('esx_identity:completedRegistration', source, data)
cb(true)
end
end
end)
xPlayer.setName(('%s %s'):format(currentIdentity.firstName, currentIdentity.lastName))
xPlayer.set('firstName', currentIdentity.firstName)
xPlayer.set('lastName', currentIdentity.lastName)
xPlayer.set('dateofbirth', currentIdentity.dateOfBirth)
xPlayer.set('sex', currentIdentity.sex)
xPlayer.set('height', currentIdentity.height)
function checkIdentity(xPlayer)
MySQL.single('SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = ?', { xPlayer.identifier },
function(result)
if result then
if result.firstname then
playerIdentity[xPlayer.identifier] = {
firstName = result.firstname,
lastName = result.lastname,
dateOfBirth = result.dateofbirth,
sex = result.sex,
height = result.height
}
saveIdentityToDatabase(xPlayer.identifier, currentIdentity)
alreadyRegistered[xPlayer.identifier] = true
alreadyRegistered[xPlayer.identifier] = true
playerIdentity[xPlayer.identifier] = nil
cb(true)
else
cb(false)
end
else
cb(false)
end
else
if multichar and checkNameFormat(data.firstname) and checkNameFormat(data.lastname) and
checkSexFormat(data.sex) and checkDOBFormat(data.dateofbirth) and checkHeightFormat(data.height) then
TriggerEvent('esx_identity:completedRegistration', source, data)
cb(true)
end
end
end)
setIdentity(xPlayer)
else
playerIdentity[xPlayer.identifier] = nil
alreadyRegistered[xPlayer.identifier] = false
TriggerClientEvent('esx_identity:showRegisterIdentity', xPlayer.source)
end
else
TriggerClientEvent('esx_identity:showRegisterIdentity', xPlayer.source)
end
end)
end
function checkIdentity(xPlayer)
MySQL.single('SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = ?',
{xPlayer.identifier}, function(result)
if result then
if result.firstname then
playerIdentity[xPlayer.identifier] = {
firstName = result.firstname,
lastName = result.lastname,
dateOfBirth = result.dateofbirth,
sex = result.sex,
height = result.height
}
function setIdentity(xPlayer)
if alreadyRegistered[xPlayer.identifier] then
local currentIdentity = playerIdentity[xPlayer.identifier]
alreadyRegistered[xPlayer.identifier] = true
xPlayer.setName(('%s %s'):format(currentIdentity.firstName, currentIdentity.lastName))
xPlayer.set('firstName', currentIdentity.firstName)
xPlayer.set('lastName', currentIdentity.lastName)
xPlayer.set('dateofbirth', currentIdentity.dateOfBirth)
xPlayer.set('sex', currentIdentity.sex)
xPlayer.set('height', currentIdentity.height)
setIdentity(xPlayer)
else
playerIdentity[xPlayer.identifier] = nil
alreadyRegistered[xPlayer.identifier] = false
TriggerClientEvent('esx_identity:showRegisterIdentity', xPlayer.source)
end
else
TriggerClientEvent('esx_identity:showRegisterIdentity', xPlayer.source)
end
end)
end
if currentIdentity.saveToDatabase then
saveIdentityToDatabase(xPlayer.identifier, currentIdentity)
end
function setIdentity(xPlayer)
if alreadyRegistered[xPlayer.identifier] then
local currentIdentity = playerIdentity[xPlayer.identifier]
playerIdentity[xPlayer.identifier] = nil
end
end
xPlayer.setName(('%s %s'):format(currentIdentity.firstName, currentIdentity.lastName))
xPlayer.set('firstName', currentIdentity.firstName)
xPlayer.set('lastName', currentIdentity.lastName)
xPlayer.set('dateofbirth', currentIdentity.dateOfBirth)
xPlayer.set('sex', currentIdentity.sex)
xPlayer.set('height', currentIdentity.height)
if currentIdentity.saveToDatabase then
saveIdentityToDatabase(xPlayer.identifier, currentIdentity)
end
playerIdentity[xPlayer.identifier] = nil
end
end
end
if Config.EnableCommands then
ESX.RegisterCommand('char', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.getName() then
xPlayer.showNotification(_U('active_character', xPlayer.getName()))
else
xPlayer.showNotification(_U('error_active_character'))
end
end, false, {help = _U('show_active_character')})
ESX.RegisterCommand('char', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.getName() then
xPlayer.showNotification(_U('active_character', xPlayer.getName()))
else
xPlayer.showNotification(_U('error_active_character'))
end
end, false, {
help = _U('show_active_character')
})
ESX.RegisterCommand('chardel', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.getName() then
if Config.UseDeferrals then
xPlayer.kick(_U('deleted_identity'))
Wait(1500)
deleteIdentity(xPlayer)
xPlayer.showNotification(_U('deleted_character'))
playerIdentity[xPlayer.identifier] = nil
alreadyRegistered[xPlayer.identifier] = false
else
deleteIdentity(xPlayer)
xPlayer.showNotification(_U('deleted_character'))
playerIdentity[xPlayer.identifier] = nil
alreadyRegistered[xPlayer.identifier] = false
TriggerClientEvent('esx_identity:showRegisterIdentity', xPlayer.source)
end
else
xPlayer.showNotification(_U('error_delete_character'))
end
end, false, {help = _U('delete_character')})
ESX.RegisterCommand('chardel', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.getName() then
if Config.UseDeferrals then
xPlayer.kick(_U('deleted_identity'))
Wait(1500)
deleteIdentity(xPlayer)
xPlayer.showNotification(_U('deleted_character'))
playerIdentity[xPlayer.identifier] = nil
alreadyRegistered[xPlayer.identifier] = false
else
deleteIdentity(xPlayer)
xPlayer.showNotification(_U('deleted_character'))
playerIdentity[xPlayer.identifier] = nil
alreadyRegistered[xPlayer.identifier] = false
TriggerClientEvent('esx_identity:showRegisterIdentity', xPlayer.source)
end
else
xPlayer.showNotification(_U('error_delete_character'))
end
end, false, {
help = _U('delete_character')
})
end
if Config.EnableDebugging then
ESX.RegisterCommand('xPlayerGetFirstName', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.get('firstName') then
xPlayer.showNotification(_U('return_debug_xPlayer_get_first_name', xPlayer.get('firstName')))
else
xPlayer.showNotification(_U('error_debug_xPlayer_get_first_name'))
end
end, false, {help = _U('debug_xPlayer_get_first_name')})
ESX.RegisterCommand('xPlayerGetFirstName', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.get('firstName') then
xPlayer.showNotification(_U('return_debug_xPlayer_get_first_name', xPlayer.get('firstName')))
else
xPlayer.showNotification(_U('error_debug_xPlayer_get_first_name'))
end
end, false, {
help = _U('debug_xPlayer_get_first_name')
})
ESX.RegisterCommand('xPlayerGetLastName', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.get('lastName') then
xPlayer.showNotification(_U('return_debug_xPlayer_get_last_name', xPlayer.get('lastName')))
else
xPlayer.showNotification(_U('error_debug_xPlayer_get_last_name'))
end
end, false, {help = _U('debug_xPlayer_get_last_name')})
ESX.RegisterCommand('xPlayerGetLastName', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.get('lastName') then
xPlayer.showNotification(_U('return_debug_xPlayer_get_last_name', xPlayer.get('lastName')))
else
xPlayer.showNotification(_U('error_debug_xPlayer_get_last_name'))
end
end, false, {
help = _U('debug_xPlayer_get_last_name')
})
ESX.RegisterCommand('xPlayerGetFullName', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.getName() then
xPlayer.showNotification(_U('return_debug_xPlayer_get_full_name', xPlayer.getName()))
else
xPlayer.showNotification(_U('error_debug_xPlayer_get_full_name'))
end
end, false, {help = _U('debug_xPlayer_get_full_name')})
ESX.RegisterCommand('xPlayerGetFullName', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.getName() then
xPlayer.showNotification(_U('return_debug_xPlayer_get_full_name', xPlayer.getName()))
else
xPlayer.showNotification(_U('error_debug_xPlayer_get_full_name'))
end
end, false, {
help = _U('debug_xPlayer_get_full_name')
})
ESX.RegisterCommand('xPlayerGetSex', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.get('sex') then
xPlayer.showNotification(_U('return_debug_xPlayer_get_sex', xPlayer.get('sex')))
else
xPlayer.showNotification(_U('error_debug_xPlayer_get_sex'))
end
end, false, {help = _U('debug_xPlayer_get_sex')})
ESX.RegisterCommand('xPlayerGetSex', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.get('sex') then
xPlayer.showNotification(_U('return_debug_xPlayer_get_sex', xPlayer.get('sex')))
else
xPlayer.showNotification(_U('error_debug_xPlayer_get_sex'))
end
end, false, {
help = _U('debug_xPlayer_get_sex')
})
ESX.RegisterCommand('xPlayerGetDOB', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.get('dateofbirth') then
xPlayer.showNotification(_U('return_debug_xPlayer_get_dob', xPlayer.get('dateofbirth')))
else
xPlayer.showNotification(_U('error_debug_xPlayer_get_dob'))
end
end, false, {help = _U('debug_xPlayer_get_dob')})
ESX.RegisterCommand('xPlayerGetDOB', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.get('dateofbirth') then
xPlayer.showNotification(_U('return_debug_xPlayer_get_dob', xPlayer.get('dateofbirth')))
else
xPlayer.showNotification(_U('error_debug_xPlayer_get_dob'))
end
end, false, {
help = _U('debug_xPlayer_get_dob')
})
ESX.RegisterCommand('xPlayerGetHeight', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.get('height') then
xPlayer.showNotification(_U('return_debug_xPlayer_get_height', xPlayer.get('height')))
else
xPlayer.showNotification(_U('error_debug_xPlayer_get_height'))
end
end, false, {help = _U('debug_xPlayer_get_height')})
ESX.RegisterCommand('xPlayerGetHeight', 'user', function(xPlayer, args, showError)
if xPlayer and xPlayer.get('height') then
xPlayer.showNotification(_U('return_debug_xPlayer_get_height', xPlayer.get('height')))
else
xPlayer.showNotification(_U('error_debug_xPlayer_get_height'))
end
end, false, {
help = _U('debug_xPlayer_get_height')
})
end
function deleteIdentity(xPlayer)
if alreadyRegistered[xPlayer.identifier] then
xPlayer.setName(('%s %s'):format(nil, nil))
xPlayer.set('firstName', nil)
xPlayer.set('lastName', nil)
xPlayer.set('dateofbirth', nil)
xPlayer.set('sex', nil)
xPlayer.set('height', nil)
if alreadyRegistered[xPlayer.identifier] then
xPlayer.setName(('%s %s'):format(nil, nil))
xPlayer.set('firstName', nil)
xPlayer.set('lastName', nil)
xPlayer.set('dateofbirth', nil)
xPlayer.set('sex', nil)
xPlayer.set('height', nil)
deleteIdentityFromDatabase(xPlayer)
end
deleteIdentityFromDatabase(xPlayer)
end
end
function saveIdentityToDatabase(identifier, identity)
MySQL.update.await('UPDATE users SET firstname = ?, lastname = ?, dateofbirth = ?, sex = ?, height = ? WHERE identifier = ?', {identity.firstName, identity.lastName, identity.dateOfBirth, identity.sex, identity.height, identifier})
MySQL.update.await(
'UPDATE users SET firstname = ?, lastname = ?, dateofbirth = ?, sex = ?, height = ? WHERE identifier = ?',
{identity.firstName, identity.lastName, identity.dateOfBirth, identity.sex, identity.height, identifier})
end
function deleteIdentityFromDatabase(xPlayer)
MySQL.query.await('UPDATE users SET firstname = ?, lastname = ?, dateofbirth = ?, sex = ?, height = ?, skin = ? WHERE identifier = ?', {nil, nil, nil, nil, nil, nil, xPlayer.identifier})
MySQL.query.await(
'UPDATE users SET firstname = ?, lastname = ?, dateofbirth = ?, sex = ?, height = ?, skin = ? WHERE identifier = ?',
{nil, nil, nil, nil, nil, nil, xPlayer.identifier})
if Config.FullCharDelete then
MySQL.update.await('UPDATE addon_account_data SET money = 0 WHERE account_name IN (?) AND owner = ?', {{'bank_savings', 'caution'}, xPlayer.identifier})
if Config.FullCharDelete then
MySQL.update.await('UPDATE addon_account_data SET money = 0 WHERE account_name IN (?) AND owner = ?',
{{'bank_savings', 'caution'}, xPlayer.identifier})
MySQL.prepare.await('UPDATE datastore_data SET data = ? WHERE name IN (?) AND owner = ?', {'\'{}\'', {'user_ears', 'user_glasses', 'user_helmet', 'user_mask'}, xPlayer.identifier})
end
MySQL.prepare.await('UPDATE datastore_data SET data = ? WHERE name IN (?) AND owner = ?',
{'\'{}\'', {'user_ears', 'user_glasses', 'user_helmet', 'user_mask'}, xPlayer.identifier})
end
end
function checkNameFormat(name)
if not checkAlphanumeric(name) then
if not checkForNumbers(name) then
local stringLength = string.len(name)
if stringLength > 0 and stringLength < Config.MaxNameLength then
return true
else
return false
end
else
return false
end
else
return false
end
if not checkAlphanumeric(name) then
if not checkForNumbers(name) then
local stringLength = string.len(name)
if stringLength > 0 and stringLength < Config.MaxNameLength then
return true
else
return false
end
else
return false
end
else
return false
end
end
function checkDOBFormat(dob)
local date = tostring(dob)
if checkDate(date) then
return true
else
return false
end
local date = tostring(dob)
if checkDate(date) then
return true
else
return false
end
end
function checkSexFormat(sex)
if sex == "m" or sex == "M" or sex == "f" or sex == "F" then
return true
else
return false
end
if sex == "m" or sex == "M" or sex == "f" or sex == "F" then
return true
else
return false
end
end
function checkHeightFormat(height)
local numHeight = tonumber(height)
if numHeight < Config.MinHeight and numHeight > Config.MaxHeight then
return false
else
return true
end
local numHeight = tonumber(height)
if numHeight < Config.MinHeight and numHeight > Config.MaxHeight then
return false
else
return true
end
end
function formatName(name)
local loweredName = convertToLowerCase(name)
local formattedName = convertFirstLetterToUpper(loweredName)
return formattedName
local loweredName = convertToLowerCase(name)
local formattedName = convertFirstLetterToUpper(loweredName)
return formattedName
end
function convertToLowerCase(str)
return string.lower(str)
return string.lower(str)
end
function convertFirstLetterToUpper(str)
return str:gsub("^%l", string.upper)
return str:gsub("^%l", string.upper)
end
function checkAlphanumeric(str)
return (string.match(str, "%W"))
return (string.match(str, "%W"))
end
function checkForNumbers(str)
return (string.match(str,"%d"))
return (string.match(str, "%d"))
end
function checkDate(str)
if string.match(str, '(%d%d)/(%d%d)/(%d%d%d%d)') ~= nil then
local d, m, y = string.match(str, '(%d+)/(%d+)/(%d+)')
m = tonumber(m)
d = tonumber(d)
y = tonumber(y)
if ((d <= 0) or (d > 31)) or ((m <= 0) or (m > 12)) or ((y <= Config.LowestYear) or (y > Config.HighestYear)) then
return false
elseif m == 4 or m == 6 or m == 9 or m == 11 then
if d > 30 then
return false
else
return true
end
elseif m == 2 then
if y%400 == 0 or (y%100 ~= 0 and y%4 == 0) then
if d > 29 then
return false
else
return true
end
else
if d > 28 then
return false
else
return true
end
end
else
if d > 31 then
return false
else
return true
end
end
else
return false
end
if string.match(str, '(%d%d)/(%d%d)/(%d%d%d%d)') ~= nil then
local d, m, y = string.match(str, '(%d+)/(%d+)/(%d+)')
m = tonumber(m)
d = tonumber(d)
y = tonumber(y)
if ((d <= 0) or (d > 31)) or ((m <= 0) or (m > 12)) or ((y <= Config.LowestYear) or (y > Config.HighestYear)) then
return false
elseif m == 4 or m == 6 or m == 9 or m == 11 then
if d > 30 then
return false
else
return true
end
elseif m == 2 then
if y % 400 == 0 or (y % 100 ~= 0 and y % 4 == 0) then
if d > 29 then
return false
else
return true
end
else
if d > 28 then
return false
else
return true
end
end
else
if d > 31 then
return false
else
return true
end
end
else
return false
end
end