From 008fea4de681432efb809f391907b649b5d3c729 Mon Sep 17 00:00:00 2001 From: Cocodrulo Date: Sat, 20 Jul 2024 21:17:34 +0100 Subject: [PATCH 1/4] feat: Add discord field to players table --- server/player.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/player.lua b/server/player.lua index a8963e0b9..2a7e7c939 100644 --- a/server/player.lua +++ b/server/player.lua @@ -97,6 +97,7 @@ function QBCore.Player.CheckPlayerData(source, PlayerData) if source then PlayerData.source = source PlayerData.license = PlayerData.license or QBCore.Functions.GetIdentifier(source, 'license') + PlayerData.discord = PlayerData.discord or QBCore.Functions.GetIdentifier(source, 'discord'):sub(9) PlayerData.name = GetPlayerName(source) end @@ -437,10 +438,11 @@ function QBCore.Player.Save(source) local pcoords = GetEntityCoords(ped) local PlayerData = QBCore.Players[source].PlayerData if PlayerData then - MySQL.insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', { + MySQL.insert('INSERT INTO players (citizenid, cid, license, discord, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :discord, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', { citizenid = PlayerData.citizenid, cid = tonumber(PlayerData.cid), license = PlayerData.license, + discord = PlayerData.discord, name = PlayerData.name, money = json.encode(PlayerData.money), charinfo = json.encode(PlayerData.charinfo), @@ -458,10 +460,11 @@ end function QBCore.Player.SaveOffline(PlayerData) if PlayerData then - MySQL.insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', { + MySQL.insert('INSERT INTO players (citizenid, cid, license, discord, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :discord, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', { citizenid = PlayerData.citizenid, cid = tonumber(PlayerData.cid), license = PlayerData.license, + discord = PlayerData.discord, name = PlayerData.name, money = json.encode(PlayerData.money), charinfo = json.encode(PlayerData.charinfo), From ef75798927b18fed5e9d48b167cf66c98bf5b37f Mon Sep 17 00:00:00 2001 From: Cocodrulo <142546774+Cocodrulo@users.noreply.github.com> Date: Fri, 26 Jul 2024 14:37:02 +0100 Subject: [PATCH 2/4] Added discord field to players table --- qbcore.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/qbcore.sql b/qbcore.sql index ee0d6d81a..a0d62ed6d 100644 --- a/qbcore.sql +++ b/qbcore.sql @@ -3,6 +3,7 @@ CREATE TABLE IF NOT EXISTS `players` ( `citizenid` varchar(50) NOT NULL, `cid` int(11) DEFAULT NULL, `license` varchar(255) NOT NULL, + `discord` varchar(255) NOT NULL, `name` varchar(255) NOT NULL, `money` text NOT NULL, `charinfo` text DEFAULT NULL, From db29bfe168d84c30f5b7c40a8337f62bdaf276be Mon Sep 17 00:00:00 2001 From: Cocodrulo <142546774+Cocodrulo@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:03:28 +0100 Subject: [PATCH 3/4] fix: Remove NOT NULL constraint for discord field in players table --- qbcore.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qbcore.sql b/qbcore.sql index a0d62ed6d..f13934341 100644 --- a/qbcore.sql +++ b/qbcore.sql @@ -3,7 +3,7 @@ CREATE TABLE IF NOT EXISTS `players` ( `citizenid` varchar(50) NOT NULL, `cid` int(11) DEFAULT NULL, `license` varchar(255) NOT NULL, - `discord` varchar(255) NOT NULL, + `discord` varchar(255), `name` varchar(255) NOT NULL, `money` text NOT NULL, `charinfo` text DEFAULT NULL, From 419e94db159600f035ccf1d69ba5295fcfea6aae Mon Sep 17 00:00:00 2001 From: Cocodrulo <142546774+Cocodrulo@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:03:53 +0100 Subject: [PATCH 4/4] feat: Update player data retrieval logic --- server/player.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/player.lua b/server/player.lua index 2a7e7c939..e6d903739 100644 --- a/server/player.lua +++ b/server/player.lua @@ -97,7 +97,12 @@ function QBCore.Player.CheckPlayerData(source, PlayerData) if source then PlayerData.source = source PlayerData.license = PlayerData.license or QBCore.Functions.GetIdentifier(source, 'license') - PlayerData.discord = PlayerData.discord or QBCore.Functions.GetIdentifier(source, 'discord'):sub(9) + PlayerData.discord = PlayerData.discord + + if not PlayerData.discord and QBCore.Functions.GetIdentifier(source, 'discord') then + PlayerData.discord = QBCore.Functions.GetIdentifier(source, 'discord'):sub(9) + end + PlayerData.name = GetPlayerName(source) end