Files
ND_Core/server/events.lua

116 lines
4.3 KiB
Lua
Raw Normal View History

-- For support join my discord: https://discord.gg/Z9Mxu72zZ6
-- Check if discord is connected, and if whitelist is enabled then it will only allow you to join if you have the roles.
AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
local player = source
local discordIdentifier = NDCore.Functions.GetPlayerIdentifierFromType("discord", player)
deferrals.defer()
Wait(0)
deferrals.update("Connecting to discord.")
Wait(0)
if not discordIdentifier then
deferrals.done("Your discord isn't connected to FiveM, make sure discord is open and restart FiveM.")
else
if config.enableDiscordWhitelist then
local discordUserId = discordIdentifier:gsub("discord:", "")
local discordInfo = NDCore.Functions.GetUserDiscordInfo(discordUserId)
for _, whitelistRole in pairs(config.whitelistRoles) do
2022-08-10 00:29:21 +02:00
if whitelistRole == 0 or whitelistRole == "0" or (discordInfo and discordInfo.roles[whitelistRole]) then
deferrals.done()
break
end
end
deferrals.done(config.notWhitelistedMessage)
else
deferrals.done()
end
end
end)
-- Getting all the characters the player has and returning them to the client.
2022-07-16 00:12:02 -04:00
RegisterNetEvent("ND:GetCharacters", function()
local player = source
2022-07-16 00:12:02 -04:00
TriggerClientEvent("ND:returnCharacters", player, NDCore.Functions.GetPlayerCharacters(player))
end)
-- Creating a new character.
2022-07-16 00:12:02 -04:00
RegisterNetEvent("ND:newCharacter", function(newCharacter)
local player = source
2022-11-30 03:37:07 +01:00
NDCore.Functions.CreateCharacter(player, newCharacter.firstName, newCharacter.lastName, newCharacter.dob, newCharacter.gender, newCharacter.cash, newCharacter.bank)
end)
-- Update the character info when edited.
2022-07-16 00:12:02 -04:00
RegisterNetEvent("ND:editCharacter", function(newCharacter)
local player = source
2022-09-19 20:01:47 +02:00
local characters = NDCore.Functions.GetPlayerCharacters(player)
if not characters[newCharacter.id] then return end
2022-11-30 03:37:07 +01:00
NDCore.Functions.UpdateCharacterData(newCharacter.id, newCharacter.firstName, newCharacter.lastName, newCharacter.dob, newCharacter.gender)
end)
-- Delete character from database.
2022-07-16 00:12:02 -04:00
RegisterNetEvent("ND:deleteCharacter", function(characterId)
local player = source
2022-09-14 23:20:37 +02:00
local characters = NDCore.Functions.GetPlayerCharacters(player)
if not characters[characterId] then return end
2022-07-16 00:12:02 -04:00
NDCore.Functions.DeleteCharacter(characterId)
end)
-- add a player to the table.
2022-07-16 00:12:02 -04:00
RegisterNetEvent("ND:setCharacterOnline", function(id)
local player = source
2022-09-19 20:01:47 +02:00
local characters = NDCore.Functions.GetPlayerCharacters(player)
if not characters[id] then return end
2022-07-16 00:12:02 -04:00
NDCore.Functions.SetActiveCharacter(player, id)
end)
2022-11-30 03:37:07 +01:00
-- Update the characters clothes.
RegisterNetEvent("ND:updateClothes", function(clothing)
local player = source
2022-12-25 16:46:25 +01:00
local character = NDCore.Players[player]
NDCore.Functions.SetPlayerData(character.id, "clothing", clothing)
2022-11-30 03:37:07 +01:00
end)
-- Disconnecting a player
2022-07-16 00:12:02 -04:00
RegisterNetEvent("ND:exitGame", function()
local player = source
DropPlayer(player, "Disconnected.")
end)
2022-07-16 00:12:02 -04:00
-- Remove player from NDCore.Players table when they leave.
AddEventHandler("playerDropped", function()
local player = source
2022-08-09 00:53:35 +02:00
local character = NDCore.Players[player]
if character then
NDCore.Functions.UpdateLastLocation(character.id, character.lastLocation)
end
2022-11-14 00:52:57 +01:00
TriggerEvent("ND:characterUnloaded", player, character)
2022-08-09 00:53:35 +02:00
character = nil
end)
2022-08-05 00:04:03 +02:00
2022-11-30 03:36:38 +01:00
-- 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
2022-08-11 20:17:31 -06:00
end)
2022-11-30 03:36:38 +01:00
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)