Files
ND_Core/ND_Jailing/source/server.lua

79 lines
3.2 KiB
Lua
Raw Normal View History

NDCore = exports["ND_Core"]:GetCoreObject()
2022-07-16 00:12:02 -04:00
NDCore.Functions.VersionChecker("ND_Jailing", GetCurrentResourceName(), "https://github.com/Andyyy7666/ND_Framework", "https://raw.githubusercontent.com/Andyyy7666/ND_Framework/main/ND_Jailing/fxmanifest.lua")
2022-07-08 23:18:25 +02:00
local jailedPlayers = {}
-- Get player any identifier, available types: steam, license, xbl, ip, discord, live.
function GetPlayerIdentifierFromType(type, source)
local identifierCount = GetNumPlayerIdentifiers(source)
for count = 0, identifierCount do
local identifier = GetPlayerIdentifier(source, count)
if identifier and string.find(identifier, type) then
return identifier
end
end
return nil
end
-- send discord embed with webhook.
2022-03-10 18:25:57 +01:00
function sendToDiscord(name, message, color)
local embed = {
{
title = name,
description = message,
footer = {
icon_url = "https://i.imgur.com/notBtrZ.png",
text = "Created by Andyyy#7666"
},
color = color
}
}
2022-03-10 23:12:39 +01:00
PerformHttpRequest(server_config.discordWebhook, function(err, text, headers) end, 'POST', json.encode({username = "ND Jailing", embeds = embed}), {["Content-Type"] = "application/json"})
2022-03-10 18:25:57 +01:00
end
-- Jail player discord log, trigger the even on the players client and send a message to everyone.
2022-09-01 04:11:48 -04:00
RegisterNetEvent("ND_Jailing:jailPlayer", function(id, time, fine, reason)
2022-03-10 23:12:39 +01:00
local player = source
2022-07-16 00:12:02 -04:00
local players = NDCore.Functions.GetPlayers()
local dept = players[player].job
2022-03-17 22:17:27 +01:00
for _, department in pairs(config.accessDepartments) do
2022-03-10 23:12:39 +01:00
if department == dept then
2022-07-08 23:18:25 +02:00
jailedPlayers[GetPlayerIdentifierFromType("license", id)] = time
2022-07-16 00:12:02 -04:00
NDCore.Functions.DeductMoney(fine, id, "bank")
2022-03-10 23:12:39 +01:00
TriggerClientEvent("ND_Jailing:jailPlayer", id, time)
2022-07-08 23:18:25 +02:00
sendToDiscord("Jail Logs", "**" .. GetPlayerName(player) .. "** Jailed **" .. GetPlayerName(id) .. "** for **" .. time .. " seconds** with the reason: **" .. reason .. "**.", 1595381)
2022-03-10 23:12:39 +01:00
TriggerClientEvent('chat:addMessage', -1, {
color = { 255, 0, 0},
multiline = true,
2022-07-08 23:18:25 +02:00
args = {"[Judge]", GetPlayerName(id) .. " was charaged with " .. reason .. " and will be spending " .. time .. " months in jail."}
2022-03-10 23:12:39 +01:00
})
break
end
end
2022-03-10 18:25:57 +01:00
end)
2022-09-01 04:11:48 -04:00
RegisterNetEvent("ND_Jailing:updateJailing", function(time)
2022-07-08 23:18:25 +02:00
local player = source
if time == 0 then
jailedPlayers[GetPlayerIdentifierFromType("license", player)] = nil
else
jailedPlayers[GetPlayerIdentifierFromType("license", player)] = time
end
end)
2022-03-10 18:25:57 +01:00
-- Gets all players on the server and adds them to a table.
2022-09-01 04:11:48 -04:00
RegisterNetEvent("ND_Jailing:getPlayers", function()
2022-03-10 18:25:57 +01:00
local players = {}
for _, id in pairs(GetPlayers()) do
players[id] = "(" .. id .. ") " .. GetPlayerName(id)
end
TriggerClientEvent("ND_Jailing:returnPlayers", source, players)
2022-03-10 23:12:39 +01:00
end)
2022-07-08 23:18:25 +02:00
2022-09-01 04:11:48 -04:00
RegisterNetEvent("ND_Jailing:getJailTime", function()
2022-07-08 23:18:25 +02:00
local player = source
local time = jailedPlayers[GetPlayerIdentifierFromType("license", player)]
if time then
TriggerClientEvent("ND_Jailing:jailPlayer", player, time)
end
end)