From 379262cd1ce166ee190367b93181a363491baa1c Mon Sep 17 00:00:00 2001 From: ArkSeyonet <31637812+ArkSeyonet@users.noreply.github.com> Date: Tue, 19 Sep 2017 12:24:25 -0500 Subject: [PATCH] Update server.lua --- server.lua | 112 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 44 deletions(-) diff --git a/server.lua b/server.lua index 8cedd197..8d0edba1 100644 --- a/server.lua +++ b/server.lua @@ -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)