From 2534282d2abfb3cafdc77cfe52212a3d4481cef0 Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Wed, 30 Nov 2022 03:36:38 +0100 Subject: [PATCH] tweak: get player discord info --- server/events.lua | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/server/events.lua b/server/events.lua index 9076266..35c4973 100644 --- a/server/events.lua +++ b/server/events.lua @@ -29,15 +29,6 @@ AddEventHandler("playerConnecting", function(name, setKickReason, deferrals) end end) --- Creating database tables -AddEventHandler("onResourceStart", function(resourceName) - if (GetCurrentResourceName() ~= resourceName) then - return - end - MySQL.query("CREATE TABLE IF NOT EXISTS characters ( `character_id` INT(10) NOT NULL AUTO_INCREMENT, `license` VARCHAR(200) NOT NULL DEFAULT '0', `first_name` VARCHAR(50) NULL DEFAULT NULL, `last_name` VARCHAR(50) NULL DEFAULT NULL, `dob` VARCHAR(50) NULL DEFAULT NULL, `gender` VARCHAR(50) NULL DEFAULT NULL,`twt` VARCHAR(50) NULL DEFAULT NULL, `job` VARCHAR(50) NULL DEFAULT NULL, `cash` INT(10) NULL DEFAULT '0', `bank` INT(10) NULL DEFAULT '0', `phone_number` VARCHAR(20) NULL DEFAULT NULL, `groups` LONGTEXT NULL DEFAULT '[]', `last_location` LONGTEXT NULL DEFAULT '[]', `clothing` LONGTEXT NULL DEFAULT '[]', PRIMARY KEY (`character_id`) USING BTREE);") - print('^4ND_Core ^0Database structure validated!') -end) - -- Getting all the characters the player has and returning them to the client. RegisterNetEvent("ND:GetCharacters", function() local player = source @@ -91,8 +82,27 @@ AddEventHandler("playerDropped", function() character = nil end) --- Update the characters clothes. -RegisterNetEvent("ND:updateClothes", function(clothing) - local player = source - NDCore.Functions.UpdateClothes(NDCore.Players[player].id, clothing) +-- Get player discord info on join. +AddEventHandler("playerJoining", function() + local src = source + + local discordUserId = NDCore.Functions.GetPlayerIdentifierFromType("discord", src):gsub("discord:", "") + local discordInfo = NDCore.Functions.GetUserDiscordInfo(discordUserId) + + NDCore.PlayersDiscordInfo[src] = discordInfo end) + +AddEventHandler("onResourceStart", function(resourceName) + if (GetCurrentResourceName() ~= resourceName) then + return + end + Wait(1000) + + if not next(NDCore.PlayersDiscordInfo) then + for _, playerId in ipairs(GetPlayers()) do + local discordUserId = NDCore.Functions.GetPlayerIdentifierFromType("discord", playerId):gsub("discord:", "") + local discordInfo = NDCore.Functions.GetUserDiscordInfo(discordUserId) + NDCore.PlayersDiscordInfo[tonumber(playerId)] = discordInfo + end + end +end) \ No newline at end of file