Files
ND_Core/server/functions.lua

100 lines
3.0 KiB
Lua
Raw Normal View History

2023-07-10 03:17:32 +02:00
---@param src number
---@return table
2023-07-09 21:19:35 +02:00
function NDCore.getPlayer(src)
return NDCore.players[src]
2023-07-09 21:19:35 +02:00
end
2023-07-10 03:17:32 +02:00
---@param metadata string
---@param data any
---@return table
function NDCore.getPlayers(key, value, returnArray)
if not key or not value then return NDCore.players end
2023-07-09 21:19:35 +02:00
local players = {}
local keyTypes = {id = "id", firstname = "firstname", lastname = "lastname", gender = "gender", groups = "groups"}
local findBy = keyTypes[key] or "metadata"
if findBy then
for src, info in pairs(NDCore.players) do
if findBy == "metadata" and info["metadata"][key] == value or info[findBy] == value then
if returnArray then
players[#players+1] = info
else
players[src] = info
end
end
2023-07-09 21:19:35 +02:00
end
end
return players
end
2023-07-22 23:59:11 +02:00
---@param source number
---@return table
function NDCore.getPlayerServerInfo(source)
return PlayersInfo[source]
end
2023-07-16 12:31:02 +02:00
---@param fileLocation string|tabale
---@return boolean
function NDCore.loadSQL(fileLocation, resource)
local resourceName = resource or GetInvokingResource() or GetCurrentResourceName()
if type(fileLocation) == "string" then
local file = LoadResourceFile(resourceName, fileLocation)
if not file then return end
MySQL.query(file)
return true
end
for i=1, #fileLocation do
local file = LoadResourceFile(resourceName, fileLocation[i])
if file then
MySQL.query(file)
Wait(100)
end
end
return true
end
function NDCore.getDiscordInfo(discordUserId)
2023-10-25 21:17:37 +02:00
if not discordUserId or not Config.discordBotToken or not Config.discordGuildId then return end
local done = false
local data
local discordErrors = {
[400] = "Improper HTTP request",
[401] = "Discord bot token might be missing or incorrect",
[404] = "User might not be in the server",
[429] = "Discord bot rate limited"
}
if type(discordUserId) == "string" and discordUserId:find("discord:") then discordUserId:gsub("discord:", "") end
PerformHttpRequest(("https://discordapp.com/api/guilds/%s/members/%s"):format(Config.discordGuildId, discordUserId), function(errorCode, resultData, resultHeaders)
if errorCode ~= 200 then
done = true
return print(("^3Warning: %d %s"):format(errorCode, discordErrors[errorCode]))
end
local result = json.decode(resultData)
data = {
nickname = result.nick or result.user.username,
user = result.user,
roles = result.roles
}
done = true
end, "GET", "", {["Content-Type"] = "application/json", ["Authorization"] = ("Bot %s"):format(Config.discordBotToken)})
while not done do Wait(50) end
return data
end
function NDCore.enableMultiCharacter(enable)
Config.multiCharacter = enable
end
2023-07-09 21:19:35 +02:00
for name, func in pairs(NDCore) do
if type(func) == "function" then
exports(name, func)
end
end