fix(CharacterSelection/js): Removed duplicated code

This commit is contained in:
Andyyy7666
2022-08-10 00:18:14 +02:00
parent 8681f824b6
commit efcadd4734
3 changed files with 6 additions and 235 deletions

View File

@@ -5,12 +5,12 @@ NDCore = exports["ND_Core"]:GetCoreObject()
function validateDepartment(player, department)
local departmentExists = config.departments[department]
if departmentExists then
local discordUserId = string.gsub(NDCore.Functions.GetPlayerIdentifierFromType("discord", player), "discord:", "")
local roles = NDCore.Functions.GetUserDiscordInfo(discordUserId).roles
local discordUserId = NDCore.Functions.GetPlayerIdentifierFromType("discord", player):gsub("discord:", "")
local discordInfo = NDCore.Functions.GetUserDiscordInfo(discordUserId)
-- validate that the player actually has the role that they selected on the client.
for _, roleId in pairs(departmentExists) do
if roles[roleId] or roleId == 0 or roleId == "0" then
if roleId == 0 or roleId == "0" or (discordInfo and discordInfo.roles[roleId]) then
return true
end
end
@@ -53,6 +53,7 @@ AddEventHandler("ND_CharacterSelection:checkPerms", function()
local discordUserId = NDCore.Functions.GetPlayerIdentifierFromType("discord", player):gsub("discord:", "")
local allowedRoles = {}
local discordInfo = NDCore.Functions.GetUserDiscordInfo(discordUserId)
-- Check if the players discord roles will grant them permission to the department.
for dept, roleTable in pairs(config.departments) do
for _, roleId in pairs(roleTable) do
@@ -61,6 +62,5 @@ AddEventHandler("ND_CharacterSelection:checkPerms", function()
end
end
end
TriggerClientEvent("ND_CharacterSelection:permsChecked", player, allowedRoles)
end)
end)