mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 08:13:21 +00:00
refactor(rewrite/server): Modified events and data being sent to client
This commit is contained in:
+13
-13
@@ -1,20 +1,22 @@
|
||||
ESX = exports['es_extended']:getSharedObject()
|
||||
if ESX.GetConfig().Multichar then
|
||||
local IdentifierTables = {}
|
||||
Config.databaseName = 'es_extended'
|
||||
Config.prefix = 'char'
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
MySQL.ready(function ()
|
||||
MySQL.Async.fetchAll('SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = @id AND TABLE_SCHEMA = @db', { ['@id'] = "owner", ["@db"] = Config.databaseName}, function(result)
|
||||
if result then
|
||||
for k, v in pairs(result) do
|
||||
IdentifierTables[#IdentifierTables+1] = {table = v.TABLE_NAME, column = "owner"}
|
||||
IdentifierTables[#IdentifierTables+1] = {table = v.TABLE_NAME, column = 'owner'}
|
||||
end
|
||||
end
|
||||
end)
|
||||
MySQL.Async.fetchAll('SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = @id AND TABLE_SCHEMA = @db', { ['@id'] = "identifier", ["@db"] = Config.databaseName}, function(result)
|
||||
if result then
|
||||
for k, v in pairs(result) do
|
||||
IdentifierTables[#IdentifierTables+1] = {table = v.TABLE_NAME, column = "identifier"}
|
||||
IdentifierTables[#IdentifierTables+1] = {table = v.TABLE_NAME, column = 'identifier'}
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -28,7 +30,7 @@ if ESX.GetConfig().Multichar then
|
||||
RegisterServerEvent("esx_multicharacter:SetupCharacters")
|
||||
AddEventHandler('esx_multicharacter:SetupCharacters', function()
|
||||
local playerId = source
|
||||
local identifier = 'char%:'..ESX.GetIdentifier(playerId)
|
||||
local identifier = Config.prefix..'%:'..ESX.GetIdentifier(playerId)
|
||||
MySQL.Async.fetchAll("SELECT `identifier`, `accounts`, `job`, `job_grade`, `firstname`, `lastname`, `dateofbirth`, `sex`, `skin` FROM `users` WHERE `identifier` LIKE @identifier", {
|
||||
['@identifier'] = identifier
|
||||
}, function(result)
|
||||
@@ -38,7 +40,9 @@ if ESX.GetConfig().Multichar then
|
||||
local grade = ESX.Jobs[job.name].grades[tostring(result[i].job_grade)].label
|
||||
local accounts = json.decode(result[i].accounts)
|
||||
if grade == 'Unemployed' then grade = '' end
|
||||
characters[i] = {
|
||||
local id = tonumber(string.sub(result[i].identifier, #Config.prefix+1, string.find(result[i].identifier, ':')-1))
|
||||
characters[id] = {
|
||||
id = id,
|
||||
bank = accounts.bank,
|
||||
money = accounts.money,
|
||||
job = job.label,
|
||||
@@ -46,22 +50,18 @@ if ESX.GetConfig().Multichar then
|
||||
firstname = result[i].firstname,
|
||||
lastname = result[i].lastname,
|
||||
dateofbirth = result[i].dateofbirth,
|
||||
identifier = result[i].identifier,
|
||||
skin = json.decode(result[i].skin)
|
||||
}
|
||||
if result[i].sex == 'm' then characters[i].sex = 'Male' else characters[i].sex = 'Female' end
|
||||
if result[i].sex == 'm' then characters[id].sex = 'Male' else characters[id].sex = 'Female' end
|
||||
end
|
||||
TriggerClientEvent('esx_multicharacter:SetupUI', playerId, characters)
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterServerEvent("esx_multicharacter:CharacterChosen")
|
||||
AddEventHandler('esx_multicharacter:CharacterChosen', function(charid, ischar)
|
||||
AddEventHandler('esx_multicharacter:CharacterChosen', function(charid, isNew)
|
||||
local src = source
|
||||
local isNew = true
|
||||
if ischar then isNew = false end
|
||||
local spawn = {}
|
||||
if type(charid) == "number" and string.len(charid) == 1 and type(ischar) == "boolean" then
|
||||
if type(charid) == 'number' and string.len(charid) == 1 and type(isNew) == 'boolean' then
|
||||
TriggerEvent('esx:onPlayerJoined', src, charid, isNew)
|
||||
else
|
||||
-- Trigger Ban Event here to ban individuals trying to use SQL Injections
|
||||
@@ -73,7 +73,7 @@ if ESX.GetConfig().Multichar then
|
||||
local src = source
|
||||
if type(charid) == "number" and string.len(charid) == 1 then
|
||||
DeleteCharacter(src, charid)
|
||||
TriggerClientEvent("esx_multicharacter:ReloadCharacters", src)
|
||||
--TriggerClientEvent("esx_multicharacter:ReloadCharacters", src)
|
||||
else
|
||||
-- Trigger Ban Event here to ban individuals trying to use SQL Injections
|
||||
end
|
||||
@@ -91,4 +91,4 @@ end
|
||||
|
||||
RegisterCommand('relog', function(source, args, rawCommand)
|
||||
TriggerEvent('esx:playerLogout', source)
|
||||
end, true) -- Still experimental and requires proper setup; don't use this
|
||||
end, true) -- Still experimental! Requires proper setup and modifications to other resources to properly support relogging
|
||||
|
||||
Reference in New Issue
Block a user