From cf2606866a1bfce1e2f6841faeacabc1653203e7 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 9 May 2021 01:59:46 +1000 Subject: [PATCH 01/11] Trigger an event on server once xPlayer is created --- server/main.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/server/main.lua b/server/main.lua index 12e74141..59dde37b 100644 --- a/server/main.lua +++ b/server/main.lua @@ -225,6 +225,7 @@ function loadESXPlayer(identifier, playerId, isNew) Async.parallel(tasks, function(results) local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job, userData.loadout, userData.playerName, userData.coords) ESX.Players[playerId] = xPlayer + TriggerEvent('esx:playerLoaded', playerId, xPlayer, isNew) xPlayer.triggerEvent('esx:playerLoaded', { accounts = xPlayer.getAccounts(), From c60eaa1315abd1caba03f5fb6ea023036ae69b3c Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 9 May 2021 02:46:00 +1000 Subject: [PATCH 02/11] Allow a function to be triggered when PlayerData is changed --- imports.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imports.lua b/imports.lua index 884eb4b5..9c5421ea 100644 --- a/imports.lua +++ b/imports.lua @@ -3,5 +3,6 @@ ESX = exports['es_extended']:getSharedObject() AddEventHandler('esx:setPlayerData', function(key, val) if GetInvokingResource() == 'es_extended' then ESX.PlayerData[key] = val + if OnPlayerData ~= nil then OnPlayerData(key, val) end end -end) \ No newline at end of file +end) From 9cca834880eb0be938934629df82ea5c2f8e9003 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 9 May 2021 03:41:28 +1000 Subject: [PATCH 03/11] Update main.lua --- server/main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/main.lua b/server/main.lua index 59dde37b..cf4e90b5 100644 --- a/server/main.lua +++ b/server/main.lua @@ -540,7 +540,7 @@ Citizen.CreateThread( ([[ ^1---------------------------------------------------------------------- -^1URGENT: YOUR ES-EXTENDED IS OUTDATATED!!! +^1URGENT: YOUR ES-EXTENDED IS OUTDATED! ^1COMMIT UPDATE: ^5%s AVAILABLE ^1DOWNLOAD:^5 https://github.com/esx-framework/es_extended/tree/legacy ^1CHANGELOG:^5 %s From 5df4e3e76d8e78099a901a3da50bee865c0a94f9 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 9 May 2021 04:07:10 +1000 Subject: [PATCH 04/11] Config.PrimaryIdentifier --- config.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/config.lua b/config.lua index 89fbb379..ea90361c 100644 --- a/config.lua +++ b/config.lua @@ -8,6 +8,7 @@ Config.Accounts = { } Config.StartingAccountMoney = {bank = 50000} +Config.PrimaryIdentifier = 'license' -- recommended Config.EnableSocietyPayouts = false -- pay from the society account that the player is employed at? Requirement: esx_society Config.EnableHud = true -- enable the default hud? Display current job and accounts (black, bank & cash) From 6232541cfb0bc8fc0f6632c6bdec5524ecceb709 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 9 May 2021 04:53:57 +1000 Subject: [PATCH 05/11] Use PrimaryIdentifier --- server/main.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/main.lua b/server/main.lua index cf4e90b5..57ff5640 100644 --- a/server/main.lua +++ b/server/main.lua @@ -14,8 +14,8 @@ function onPlayerJoined(playerId) local identifier for k,v in ipairs(GetPlayerIdentifiers(playerId)) do - if string.match(v, 'license:') then - identifier = string.sub(v, 9) + if string.match(v, Config.PrimaryIdentifier) then + identifier = string.gsub(v, Config.PrimaryIdentifier..':', '') break end end @@ -65,8 +65,8 @@ AddEventHandler('playerConnecting', function(name, setCallback, deferrals) Citizen.Wait(100) for k,v in ipairs(GetPlayerIdentifiers(playerId)) do - if string.match(v, 'license:') then - identifier = string.sub(v, 9) + if string.match(v, Config.PrimaryIdentifier) then + identifier = string.gsub(v, Config.PrimaryIdentifier..':', '') break end end From 787daaf8d31855cc9d14284148ed88003de6ba5f Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 9 May 2021 04:54:51 +1000 Subject: [PATCH 06/11] Use PrimaryIdentifier --- server/classes/player.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/classes/player.lua b/server/classes/player.lua index 64d6c1f9..23863447 100644 --- a/server/classes/player.lua +++ b/server/classes/player.lua @@ -15,7 +15,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, self.weight = weight self.maxWeight = Config.MaxWeight - ExecuteCommand(('add_principal identifier.license:%s group.%s'):format(self.identifier, self.group)) + ExecuteCommand(('add_principal identifier.%s:%s group.%s'):format(Config.PrimaryIdentifier, self.identifier, self.group)) self.triggerEvent = function(eventName, ...) TriggerClientEvent(eventName, self.source, ...) @@ -66,9 +66,9 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, end self.setGroup = function(newGroup) - ExecuteCommand(('remove_principal identifier.license:%s group.%s'):format(self.identifier, self.group)) + ExecuteCommand(('remove_principal identifier.%s:%s group.%s'):format(Config.PrimaryIdentifier, self.identifier, self.group)) self.group = newGroup - ExecuteCommand(('add_principal identifier.license:%s group.%s'):format(self.identifier, self.group)) + ExecuteCommand(('add_principal identifier.%s:%s group.%s'):format(Config.PrimaryIdentifier, self.identifier, self.group)) end self.getGroup = function() From eff2c7cbd9661a26047a28469f013ba8e6b4dda9 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 9 May 2021 14:43:13 +1000 Subject: [PATCH 07/11] Remove config for PrimaryIdentifier --- config.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/config.lua b/config.lua index ea90361c..89fbb379 100644 --- a/config.lua +++ b/config.lua @@ -8,7 +8,6 @@ Config.Accounts = { } Config.StartingAccountMoney = {bank = 50000} -Config.PrimaryIdentifier = 'license' -- recommended Config.EnableSocietyPayouts = false -- pay from the society account that the player is employed at? Requirement: esx_society Config.EnableHud = true -- enable the default hud? Display current job and accounts (black, bank & cash) From b705d75404431bfb667eac5192ce72020255b52f Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 9 May 2021 14:44:44 +1000 Subject: [PATCH 08/11] Create a function for retrieving a players identifier --- server/functions.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/functions.lua b/server/functions.lua index b3fe38a9..a87a5a70 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -239,6 +239,15 @@ ESX.GetPlayerFromIdentifier = function(identifier) end end +ESX.GetIdentifier = function(playerId) + for k,v in ipairs(GetPlayerIdentifiers(playerId)) do + if string.match(v, 'license') then + local identifier = string.gsub(v, 'license:', '') + return identifier + end + end +end + ESX.RegisterUsableItem = function(item, cb) ESX.UsableItemsCallbacks[item] = cb end From b6b48319f0fb838ac456f93762daf6f5d87c9365 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 9 May 2021 14:49:27 +1000 Subject: [PATCH 09/11] Use the new ESX.GetIdentifier function --- server/main.lua | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/server/main.lua b/server/main.lua index 57ff5640..e3911cde 100644 --- a/server/main.lua +++ b/server/main.lua @@ -11,15 +11,7 @@ AddEventHandler('esx:onPlayerJoined', function() end) function onPlayerJoined(playerId) - local identifier - - for k,v in ipairs(GetPlayerIdentifiers(playerId)) do - if string.match(v, Config.PrimaryIdentifier) then - identifier = string.gsub(v, Config.PrimaryIdentifier..':', '') - break - end - end - + local identifier = ESX.GetIdentifier(playerId) if identifier then if ESX.GetPlayerFromIdentifier(identifier) then @@ -61,20 +53,13 @@ end AddEventHandler('playerConnecting', function(name, setCallback, deferrals) deferrals.defer() - local playerId, identifier = source + local playerId = source + local identifier = ESX.GetIdentifier(playerId) Citizen.Wait(100) - for k,v in ipairs(GetPlayerIdentifiers(playerId)) do - if string.match(v, Config.PrimaryIdentifier) then - identifier = string.gsub(v, Config.PrimaryIdentifier..':', '') - break - end - end - - if identifier then if ESX.GetPlayerFromIdentifier(identifier) then - deferrals.done(('There was an error loading your character!\nError code: identifier-active\n\nThis error is caused by a player on this server who has the same identifier as you have. Make sure you are not playing on the same Rockstar account.\n\nYour Rockstar identifier: %s'):format(identifier)) + deferrals.done(('There was an error loading your character!\nError code: identifier-active\n\nThis error is caused by a player on this server who has the same identifier as you have. Make sure you are not playing on the same account.\n\nYour identifier: %s'):format(identifier)) else deferrals.done() end From 1afe919711be6385dfbb575151deb5557aa81804 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 9 May 2021 15:11:02 +1000 Subject: [PATCH 10/11] Remove Config.PrimaryIdentifier --- server/classes/player.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/classes/player.lua b/server/classes/player.lua index 23863447..64d6c1f9 100644 --- a/server/classes/player.lua +++ b/server/classes/player.lua @@ -15,7 +15,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, self.weight = weight self.maxWeight = Config.MaxWeight - ExecuteCommand(('add_principal identifier.%s:%s group.%s'):format(Config.PrimaryIdentifier, self.identifier, self.group)) + ExecuteCommand(('add_principal identifier.license:%s group.%s'):format(self.identifier, self.group)) self.triggerEvent = function(eventName, ...) TriggerClientEvent(eventName, self.source, ...) @@ -66,9 +66,9 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, end self.setGroup = function(newGroup) - ExecuteCommand(('remove_principal identifier.%s:%s group.%s'):format(Config.PrimaryIdentifier, self.identifier, self.group)) + ExecuteCommand(('remove_principal identifier.license:%s group.%s'):format(self.identifier, self.group)) self.group = newGroup - ExecuteCommand(('add_principal identifier.%s:%s group.%s'):format(Config.PrimaryIdentifier, self.identifier, self.group)) + ExecuteCommand(('add_principal identifier.license:%s group.%s'):format(self.identifier, self.group)) end self.getGroup = function() From 0a64892ad2d6f80b03eb3860e7cd689088993517 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Mon, 10 May 2021 01:21:13 +1000 Subject: [PATCH 11/11] Update version.json --- version.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.json b/version.json index 3ff5d1a3..507a7710 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { "version": "legacy", - "commit" : "1.1.9", - "changelog": "Fix esx_identity" + "commit" : "1.1.10", + "changelog": "function improvements; new import file and functions" }