Merge pull request #3 from ArkSeyonet/master

Update ESX Identity and Change SQL Queries To Async
This commit is contained in:
Jérémie N'gadi
2017-09-19 20:15:59 +02:00
committed by GitHub
6 changed files with 89 additions and 62 deletions
+7 -3
View File
@@ -4,11 +4,12 @@ FXServer ESX Identity
[REQUIREMENTS]
* Dependencies For Full Functionality
* esx_policejob => https://github.com/FXServer-ESX/fxserver-esx_policejob
* esx_policejob => https://github.com/ESX-Org/esx_policejob
* esx_society => https://github.com/ESX-Org/esx_society
[INSTALLATION]
1) Install To resources/esx_identity
1) Install To resources/[esx]/esx_identity
`<< MUST BE INSTALLED HERE`
2) Import esx_identity.sql in your database
@@ -17,9 +18,12 @@ FXServer ESX Identity
```
start esx_identity
```
4) If you are using esx_policejob, you need to change Config.EnableESXIdentity = true in esx_policejob/config.lua
4) If you are using esx_policejob or esx_society, you need to enable the following in the files config.lua:
```Config.EnableESXIdentity = true```
Notice:
`Drop the characters table, it is no longer used`
Credits:
`Script Created By: ArkSeyonet @Ark`
+2 -3
View File
@@ -1,8 +1,7 @@
--==================================================================================
--====== ESX_IDENTITY BY ARKSEYONET @Ark ======
--====== ESX_IDENTITY BY ARKSEYONET @Ark ======
--====== YOU CAN FIND ME ON MY DISCORD @Ark - https://discord.gg/cGHHxPX ======
--====== IF YOU ALTER THIS VERSION OF THE SCRIPT, PLEASE GIVE ME CREDIT ======
--====== Special Thanks To COSHAREK FOR THE UI Design ======
--====== Special Thanks To Alphakush and CMD.Telhada For Help Testing ======
--==================================================================================
@@ -46,7 +45,7 @@ end)
--===============================================
RegisterNUICallback('register', function(data, cb)
myIdentity = data
TriggerServerEvent('esx_identity:createIdentity', data)
TriggerServerEvent('esx_identity:setIdentity', data)
EnableGui(false)
Wait (500)
TriggerEvent('esx_skin:openSaveableMenu')
+7 -9
View File
@@ -1,11 +1,9 @@
USE `essentialmode`;
CREATE TABLE `characters` (
`identifier` varchar(255) NOT NULL,
`firstname` varchar(255) NOT NULL,
`lastname` varchar(255) NOT NULL,
`dateofbirth` varchar(255) NOT NULL,
`sex` varchar(1) NOT NULL DEFAULT 'f',
`height` varchar(128) NOT NULL
);
ALTER TABLE `users`
ADD COLUMN `firstname` VARCHAR(50) NULL DEFAULT '',
ADD COLUMN `lastname` VARCHAR(50) NULL DEFAULT '',
ADD COLUMN `dateofbirth` VARCHAR(25) NULL DEFAULT '',
ADD COLUMN `sex` VARCHAR(10) NULL DEFAULT '',
ADD COLUMN `height` VARCHAR(5) NULL DEFAULT ''
;
+2 -1
View File
@@ -7,6 +7,7 @@
<img id="cursor" src="cursor.png">
<div class="dialog">
<form id="register">
<h1 id="" type="">Registration</h1>
<input id="firstname" type="text" placeholder="First Name (Start With Capital Letter)"><br>
<input id="lastname" type="text" placeholder="Last Name (Start With Capital Letter)"><br>
<input id="dateofbirth" type="text" placeholder="Date Of Birth (MM/DD/YYYY)"><br>
@@ -18,4 +19,4 @@
<script src="script.js" type="text/javascript"></script>
</body>
</html>
</html>
+3 -2
View File
@@ -47,5 +47,6 @@ h1 {
background-color: Blue;
border: 0;
color: #fff;
width: 100%;
}
width: 93%;
text-align: center;
}
+68 -44
View File
@@ -1,73 +1,97 @@
--==================================================================================
--====== ESX_IDENTITY BY ARKSEYONET @Ark ======
--====== ESX_IDENTITY BY ARKSEYONET @Ark ======
--====== YOU CAN FIND ME ON MY DISCORD @Ark - https://discord.gg/cGHHxPX ======
--====== IF YOU ALTER THIS VERSION OF THE SCRIPT, PLEASE GIVE ME CREDIT ======
--====== Special Thanks To COSHAREK FOR THE UI Design ======
--====== Special Thanks To Alphakush and CMD.Telhada For Help Testing ======
--==================================================================================
--===============================================
--== Get The Player's Identification ==
--===============================================
function getIdentity(source)
local identifier = GetPlayerIdentifiers(source)[1]
local result = MySQL.Sync.fetchAll("SELECT * FROM characters WHERE identifier = @identifier", {
['@identifier'] = identifier
})
if result[1] ~= nil then
local identity = result[1]
return {
firstname = identity['firstname'],
lastname = identity['lastname'],
dateofbirth = identity['dateofbirth'],
sex = identity['sex'],
height = identity['height']
}
else
return {
firstname = '',
lastname = '',
dateofbirth = '',
sex = '',
height = ''
}
end
function getIdentity(source, callback)
local identifier = GetPlayerIdentifiers(source)[1]
MySQL.Async.fetchAll("SELECT * FROM `users` WHERE `identifier` = @identifier",
{
['@identifier'] = identifier
},
function(result)
if result[1]['firstname'] ~= nil then
local data = {
identifier = result[1]['identifier'],
firstname = result[1]['firstname'],
lastname = result[1]['lastname'],
dateofbirth = result[1]['dateofbirth'],
sex = result[1]['sex'],
height = result[1]['height']
}
callback(data)
else
local data = {
identifier = '',
firstname = '',
lastname = '',
dateofbirth = '',
sex = '',
height = ''
}
callback(data)
end
end)
end
--===============================================
--== Create The Player's Identification ==
--== Set The Player's Identification ==
--===============================================
function createIdentity(identifier, data)
MySQL.Sync.execute(
'INSERT INTO characters (identifier, firstname, lastname, dateofbirth, sex, height) VALUES (@identifier, @firstname, @lastname, @dateofbirth, @sex, @height)',
function setIdentity(identifier, data, callback)
MySQL.Async.execute("UPDATE `users` SET `firstname` = @firstname, `lastname` = @lastname, `dateofbirth` = @dateofbirth, `sex` = @sex, `height` = @height WHERE identifier = @identifier",
{
['@identifier'] = identifier,
['@firstname'] = data.firstname,
['@lastname'] = data.lastname,
['@dateofbirth'] = data.dateofbirth,
['@sex'] = data.sex,
['@height'] = data.height
})
['@sex'] = data.sex,
['@height'] = data.height
},
function(done)
if callback then
callback(true)
end
end)
end
--===============================================
--== Server Event Create Identity ==
--== Server Event Set Identity ==
--===============================================
RegisterServerEvent('esx_identity:createIdentity')
AddEventHandler('esx_identity:createIdentity', function(data)
createIdentity(GetPlayerIdentifiers(source)[1], data)
RegisterServerEvent('esx_identity:setIdentity')
AddEventHandler('esx_identity:setIdentity', function(data)
local identifier = GetPlayerIdentifiers(source)[1]
setIdentity(GetPlayerIdentifiers(source)[1], data, function(callback)
if callback == true then
print('Successfully Set Identity For ' .. identifier)
else
print('Failed To Set Identity.')
end
end)
end)
--===============================================
--== Player Loaded Event Handler ==
--===============================================
AddEventHandler('es:playerLoaded', function(source)
local result = getIdentity(source)
if result.firstname == '' then
Wait(500)
TriggerClientEvent('esx_identity:showRegisterIdentity', source)
else
print('Player Has An Identity. Continuing.')
end
getIdentity(source, function(data)
if data.firstname == '' then
TriggerClientEvent('esx_identity:showRegisterIdentity', source)
else
print('Successfully Loaded Identity For ' .. data.firstname .. ' ' .. data.lastname)
end
end)
end)
--===============================================
--== /register - Open Registration ==
--===============================================
TriggerEvent('es:addCommand', 'register', function(source, args, user)
TriggerClientEvent('esx_identity:showRegisterIdentity', source, {})
end)