mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
Updated 2.1.0
Updated everything to new format, N1K0 is about to work on some more stuff.
This commit is contained in:
67
ND_CharacterSelection/source/server.lua
Normal file
67
ND_CharacterSelection/source/server.lua
Normal file
@@ -0,0 +1,67 @@
|
||||
-- For support join my discord: https://discord.gg/Z9Mxu72zZ6
|
||||
|
||||
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
|
||||
|
||||
-- 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
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Creating a new character.
|
||||
RegisterNetEvent("ND_CharacterSelection:newCharacter")
|
||||
AddEventHandler("ND_CharacterSelection:newCharacter", function(newCharacter)
|
||||
local player = source
|
||||
|
||||
-- validate that the person has permission to use the department.
|
||||
local departmentCheck = validateDepartment(player, newCharacter.job)
|
||||
if not departmentCheck then return end
|
||||
|
||||
-- Create the character if the player has permission to the department.
|
||||
NDCore.functions:createCharacter(player, newCharacter.firstName, newCharacter.lastName, newCharacter.dob, newCharacter.gender, newCharacter.twt, newCharacter.job, newCharacter.cash, newCharacter.bank)
|
||||
end)
|
||||
|
||||
-- Update the character info when edited.
|
||||
RegisterNetEvent("ND_CharacterSelection:editCharacter")
|
||||
AddEventHandler("ND_CharacterSelection:editCharacter", function(newCharacter)
|
||||
local player = source
|
||||
|
||||
-- validate that the person has permission to use the department.
|
||||
local departmentCheck = validateDepartment(player, newCharacter.job)
|
||||
if not departmentCheck then return end
|
||||
|
||||
-- Updating the character information in the database.
|
||||
NDCore.functions:updateCharacterData(newCharacter.id, newCharacter.firstName, newCharacter.lastName, newCharacter.dob, newCharacter.gender, newCharacter.twt, newCharacter.job)
|
||||
|
||||
-- Updating characters on the client.
|
||||
TriggerClientEvent("ND:returnCharacters", player, NDCore.functions:getPlayerCharacters(player))
|
||||
end)
|
||||
|
||||
RegisterNetEvent("ND_CharacterSelection:checkPerms")
|
||||
AddEventHandler("ND_CharacterSelection:checkPerms", function()
|
||||
local player = source
|
||||
local discordUserId = string.gsub(NDCore.functions:GetPlayerIdentifierFromType("discord", player), "discord:", "")
|
||||
local allowedRoles = {}
|
||||
local roles = NDCore.functions:getUserDiscordInfo(discordUserId).roles
|
||||
|
||||
-- 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
|
||||
if roles[roleId] or roleId == 0 or roleId == "0" then
|
||||
table.insert(allowedRoles, dept)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
TriggerClientEvent("ND_CharacterSelection:permsChecked", player, allowedRoles)
|
||||
end)
|
||||
Reference in New Issue
Block a user