Version 2
This commit is contained in:
parent
e3185fe35f
commit
9b9b7645db
@ -1,6 +1,6 @@
|
|||||||
# ngd-pdduty
|
# ngd-pdduty
|
||||||
|
|
||||||
ngd-pdduty is a simple system that uses Discord webhooks to notify when a police officer goes on and off duty. It also tracks the time someone was on duty, and enables the ability to use a slash command to toggle duty on and off.
|
ngd-jobduty is a simple system that uses Discord webhooks to notify when a player with a configured job goes on and off duty. It also enables the use of a / command to toggle duty if required. This script supports multiple jobs, with multiple webhooks.
|
||||||
|
|
||||||
Created by Nemesis Gaming Development:
|
Created by Nemesis Gaming Development:
|
||||||
https://discord.gg/AnXx2GVGcM
|
https://discord.gg/AnXx2GVGcM
|
||||||
|
@ -1,23 +1,29 @@
|
|||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
local PlayerData = {}
|
local PlayerData = {}
|
||||||
|
|
||||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
||||||
PlayerData = QBCore.Functions.GetPlayerData()
|
PlayerData = QBCore.Functions.GetPlayerData()
|
||||||
|
local isOnDuty = PlayerData.job and PlayerData.job.onduty
|
||||||
|
TriggerServerEvent('SetInitialDutyStatus', isOnDuty)
|
||||||
|
if isOnDuty then
|
||||||
|
TriggerServerEvent('SendOnDutyWebhook', PlayerData.job.name)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
|
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
|
||||||
PlayerData = {}
|
PlayerData = {}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if Config.UseCommand then
|
for _, jobConfig in pairs(Config.Jobs) do
|
||||||
RegisterCommand(Config.Command, function()
|
if jobConfig.UseCommand and jobConfig.UseCommand.Enabled then
|
||||||
if PlayerData.job and PlayerData.job.name == Config.PoliceJob or PlayerData.job and PlayerData.job.type == Config.PoliceJobType then
|
RegisterCommand(jobConfig.UseCommand.Command, function()
|
||||||
|
if PlayerData.job and (PlayerData.job.name == jobConfig.JobName) then
|
||||||
TriggerServerEvent('QBCore:ToggleDuty')
|
TriggerServerEvent('QBCore:ToggleDuty')
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
TriggerEvent('chat:addSuggestion', Config.ChatSuggestion, Config.ChatSuggestionM, {})
|
TriggerEvent('chat:addSuggestion', jobConfig.UseCommand.ChatSuggestion, jobConfig.UseCommand.ChatSuggestionM,
|
||||||
|
{})
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
40
config.lua
40
config.lua
@ -1,9 +1,35 @@
|
|||||||
Config = {}
|
Config = {}
|
||||||
|
|
||||||
--You can either use police job or the type below.
|
Config.Jobs = {
|
||||||
Config.PoliceJob = 'police' --Police job qbcore>shared>jobs.lua
|
police = { --Name you must put in server.lua for webhook
|
||||||
Config.PoliceJobType = 'leo' --Police job type in qbcore>shared>jobs.lua type =
|
JobName = 'police', --Name of job in qb-core>shared>jobs.lua
|
||||||
Config.UseCommand = true --Enables a / command for police to toggle duty.
|
SendCallsign = true, --Send callsign to webhook (This requires a job setup for the qbcore /callsign command)
|
||||||
Config.Command = "pdduty" --Name of / command for duty toggle
|
UseCommand = {
|
||||||
Config.ChatSuggestion = "/pdduty" --Chat suggestion
|
Enabled = true, --Enable the use of a / command
|
||||||
Config.ChatSuggestionM = "Duty Toggle For Police" --Chat suggestion
|
Command = "pdduty", --Command to toggle duty
|
||||||
|
ChatSuggestion = "/pdduty", --Shows the / command suggestion
|
||||||
|
ChatSuggestionM = "Duty Toggle For Police", --Shows the / command suggestion description
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ambulance = {
|
||||||
|
JobName = 'ambulance',
|
||||||
|
SendCallsign = true,
|
||||||
|
UseCommand = {
|
||||||
|
Enabled = true,
|
||||||
|
Command = "emsduty",
|
||||||
|
ChatSuggestion = "/emsduty",
|
||||||
|
ChatSuggestionM = "Duty Toggle For EMS",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tobacco = {
|
||||||
|
JobName = 'tobacco',
|
||||||
|
SendCallsign = false,
|
||||||
|
UseCommand = {
|
||||||
|
Enabled = false,
|
||||||
|
Command = "tobaccoduty",
|
||||||
|
ChatSuggestion = "/tobaccoduty",
|
||||||
|
ChatSuggestionM = "Duty Toggle For Tobacco Farmer",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
-- Add more jobs following the format above.
|
||||||
|
}
|
||||||
|
@ -1,78 +1,144 @@
|
|||||||
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
local onDutyTimes = {}
|
||||||
-- ██ ██ ███████ ██████ ██ ██ ██████ ██████ ██ ██
|
-- ██ ██ ███████ ██████ ██ ██ ██████ ██████ ██ ██
|
||||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
-- ██ █ ██ █████ ██████ ███████ ██ ██ ██ ██ █████
|
-- ██ █ ██ █████ ██████ ███████ ██ ██ ██ ██ █████
|
||||||
-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
-- ███ ███ ███████ ██████ ██ ██ ██████ ██████ ██ ██
|
-- ███ ███ ███████ ██████ ██ ██ ██████ ██████ ██ ██
|
||||||
|
local JobWebhooks = {
|
||||||
|
police = 'CHANGEME',
|
||||||
|
ambulance = 'CHANGEME',
|
||||||
|
tobacco = 'CHANGEME',
|
||||||
|
--Add more to match config.
|
||||||
|
}
|
||||||
|
|
||||||
Config.Webhook = 'CHANGEME'
|
function sendDutyTimeWebhook(src, playerName, jobName, jobLabel, playerDropped)
|
||||||
---------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
|
||||||
local onDutyTimes = {}
|
|
||||||
|
|
||||||
AddEventHandler('playerDropped', function(reason)
|
|
||||||
local src = source
|
|
||||||
if onDutyTimes[src] then
|
|
||||||
local xPlayer = QBCore.Functions.GetPlayer(src)
|
|
||||||
local playerName = xPlayer.PlayerData.charinfo.firstname .. " " .. xPlayer.PlayerData.charinfo.lastname
|
|
||||||
sendDutyTimeWebhook(src, playerName)
|
|
||||||
onDutyTimes[src] = nil
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
function sendDutyTimeWebhook(src, playerName)
|
|
||||||
local endTime = os.time()
|
local endTime = os.time()
|
||||||
local timeOnDuty = os.difftime(endTime, onDutyTimes[src])
|
local timeOnDuty = os.difftime(endTime, onDutyTimes[src])
|
||||||
local hours = math.floor(timeOnDuty / 3600)
|
local xPlayer = QBCore.Functions.GetPlayer(src)
|
||||||
local minutes = math.floor((timeOnDuty % 3600) / 60)
|
local metadata = xPlayer.PlayerData.metadata
|
||||||
local seconds = timeOnDuty % 60
|
local callsign = ""
|
||||||
sendToDiscord(playerName ..
|
if Config.Jobs[jobName] and Config.Jobs[jobName].SendCallsign and metadata and metadata.callsign then
|
||||||
" went off duty. Total time on duty: " .. hours .. "H " .. minutes .. "M " .. seconds .. "S")
|
callsign = metadata.callsign
|
||||||
|
end
|
||||||
|
local dutyStatus = "Off Duty"
|
||||||
|
if playerDropped then
|
||||||
|
dutyStatus = "Off Duty - Player Dropped"
|
||||||
|
end
|
||||||
|
sendToDiscord(jobName, playerName, callsign, timeOnDuty, nil, dutyStatus, 16711680, jobLabel)
|
||||||
end
|
end
|
||||||
|
|
||||||
RegisterNetEvent('QBCore:ToggleDuty')
|
RegisterNetEvent('QBCore:ToggleDuty')
|
||||||
AddEventHandler('QBCore:ToggleDuty', function()
|
AddEventHandler('QBCore:ToggleDuty', function()
|
||||||
local src = source
|
local src = source
|
||||||
local xPlayer = QBCore.Functions.GetPlayer(src)
|
local xPlayer = QBCore.Functions.GetPlayer(src)
|
||||||
|
local jobName = xPlayer.PlayerData.job.name
|
||||||
|
local jobLabel = QBCore.Shared.Jobs[jobName] and QBCore.Shared.Jobs[jobName].label or jobName
|
||||||
|
local jobConfig = Config.Jobs[jobName]
|
||||||
|
if jobConfig and JobWebhooks[jobName] then
|
||||||
local playerName = xPlayer.PlayerData.charinfo.firstname .. " " .. xPlayer.PlayerData.charinfo.lastname
|
local playerName = xPlayer.PlayerData.charinfo.firstname .. " " .. xPlayer.PlayerData.charinfo.lastname
|
||||||
local metadata = xPlayer.PlayerData.metadata
|
local metadata = xPlayer.PlayerData.metadata
|
||||||
if metadata and metadata.callsign then
|
local callsign = ""
|
||||||
playerName = playerName .. " (Callsign: " .. metadata.callsign .. ")"
|
if jobConfig.SendCallsign and metadata and metadata.callsign then
|
||||||
|
callsign = metadata.callsign
|
||||||
end
|
end
|
||||||
if xPlayer.PlayerData.job and xPlayer.PlayerData.job.name == Config.PoliceJob or xPlayer.PlayerData.job and xPlayer.PlayerData.job.type == Config.PoliceJobType then
|
if onDutyTimes[src] then --Off duty
|
||||||
if onDutyTimes[src] then
|
sendDutyTimeWebhook(src, playerName, jobName, jobLabel)
|
||||||
sendDutyTimeWebhook(src, playerName)
|
|
||||||
onDutyTimes[src] = nil
|
onDutyTimes[src] = nil
|
||||||
else
|
else
|
||||||
onDutyTimes[src] = os.time()
|
onDutyTimes[src] = os.time() -- On duty
|
||||||
sendToDiscord(playerName .. " went on duty.")
|
sendToDiscord(jobName, playerName, callsign, nil, nil, "On Duty", 65280, jobLabel)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
RegisterNetEvent('SendOnDutyWebhook')
|
||||||
|
AddEventHandler('SendOnDutyWebhook', function(jobName)
|
||||||
|
local src = source
|
||||||
|
local xPlayer = QBCore.Functions.GetPlayer(src)
|
||||||
|
local playerName = xPlayer.PlayerData.charinfo.firstname .. " " .. xPlayer.PlayerData.charinfo.lastname
|
||||||
|
local jobLabel = QBCore.Shared.Jobs[jobName] and QBCore.Shared.Jobs[jobName].label or jobName
|
||||||
|
local metadata = xPlayer.PlayerData.metadata
|
||||||
|
local callsign = ""
|
||||||
|
if Config.Jobs[jobName].SendCallsign and metadata and metadata.callsign then
|
||||||
|
callsign = metadata.callsign
|
||||||
|
end
|
||||||
|
if JobWebhooks[jobName] then
|
||||||
|
local customMessage = "**Player Name:**\n`" .. playerName .. "`\n"
|
||||||
|
customMessage = customMessage .. "**Job:**\n`" .. jobLabel .. "`\n"
|
||||||
|
if callsign and callsign ~= "" then
|
||||||
|
customMessage = customMessage .. "**Callsign:**\n`" .. callsign .. "`\n"
|
||||||
|
end
|
||||||
|
customMessage = customMessage .. "\n" .. playerName .. " has loaded into the server and was put on duty."
|
||||||
|
sendToDiscord(jobName, playerName, callsign, nil, customMessage, "Player Logged In", 65280)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
function sendToDiscord(message)
|
RegisterNetEvent('SetInitialDutyStatus')
|
||||||
local webhook = Config.Webhook
|
AddEventHandler('SetInitialDutyStatus', function(isOnDuty)
|
||||||
if webhook == '' or webhook == 'CHANGEME' then
|
local src = source
|
||||||
print('Please put webhook into editableserver.lua')
|
if isOnDuty then
|
||||||
|
onDutyTimes[src] = os.time()
|
||||||
|
else
|
||||||
|
onDutyTimes[src] = nil
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
AddEventHandler('playerDropped', function(reason)
|
||||||
|
local src = source
|
||||||
|
if onDutyTimes[src] then
|
||||||
|
local xPlayer = QBCore.Functions.GetPlayer(src)
|
||||||
|
local playerName = xPlayer.PlayerData.charinfo.firstname .. " " .. xPlayer.PlayerData.charinfo.lastname
|
||||||
|
local jobName = xPlayer.PlayerData.job.name
|
||||||
|
local jobLabel = QBCore.Shared.Jobs[jobName] and QBCore.Shared.Jobs[jobName].label or jobName
|
||||||
|
sendDutyTimeWebhook(src, playerName, jobName, jobLabel, true)
|
||||||
|
onDutyTimes[src] = nil
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
function sendToDiscord(jobName, playerName, callsign, timeOnDuty, customMessage, dutyStatus, color, jobLabel)
|
||||||
|
local webhook = JobWebhooks[jobName]
|
||||||
|
if not webhook or webhook == 'CHANGEME' then
|
||||||
|
print('Webhook URL is not set for job: ' .. jobName)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local title = "Duty Status Update"
|
||||||
|
if dutyStatus then
|
||||||
|
title = title .. " (" .. dutyStatus .. ")"
|
||||||
|
end
|
||||||
|
local message
|
||||||
|
if customMessage then
|
||||||
|
message = customMessage
|
||||||
|
else
|
||||||
|
message = "**Player Name:**\n`" .. playerName .. "`\n"
|
||||||
|
message = message .. "**Job:**\n`" .. (jobLabel or jobName) .. "`\n"
|
||||||
|
if callsign and callsign ~= "" then
|
||||||
|
message = message .. "**Callsign:**\n`" .. callsign .. "`\n"
|
||||||
|
end
|
||||||
|
if timeOnDuty then
|
||||||
|
local hours = math.floor(timeOnDuty / 3600)
|
||||||
|
local minutes = math.floor((timeOnDuty % 3600) / 60)
|
||||||
|
local seconds = timeOnDuty % 60
|
||||||
|
message = message .. "**Time on Duty:**\n`" .. hours .. "H " .. minutes .. "M " .. seconds .. "S`"
|
||||||
|
end
|
||||||
|
end
|
||||||
local currentDateTime = os.date("%m-%d-%Y %H:%M:%S")
|
local currentDateTime = os.date("%m-%d-%Y %H:%M:%S")
|
||||||
local connect = {
|
local connect = {
|
||||||
{
|
{
|
||||||
["color"] = 255,
|
["color"] = color or 255, -- Default color if none is provided
|
||||||
["title"] = "Police Duty Log",
|
["title"] = title,
|
||||||
["description"] = message,
|
["description"] = message,
|
||||||
["footer"] = {
|
["footer"] = {
|
||||||
["icon_url"] = "https://media.discordapp.net/attachments/1077462714902917171/1077462755625418862/96Logo.png",
|
["icon_url"] =
|
||||||
|
"https://media.discordapp.net/attachments/1077462714902917171/1077462755625418862/96Logo.png",
|
||||||
["text"] = "www.nemesisGD.com | " .. currentDateTime,
|
["text"] = "www.nemesisGD.com | " .. currentDateTime,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PerformHttpRequest(webhook, function(err, text, headers) end, 'POST',
|
PerformHttpRequest(webhook, function(err, text, headers) end, 'POST',
|
||||||
json.encode({
|
json.encode({
|
||||||
username = 'Nemesis Gaming Development | Police Duty',
|
username = 'Nemesis Gaming Development | Duty Status',
|
||||||
embeds = connect,
|
embeds = connect,
|
||||||
avatar_url = 'https://media.discordapp.net/attachments/1077462714902917171/1077462755625418862/96Logo.png'
|
avatar_url = 'https://media.discordapp.net/attachments/1077462714902917171/1077462755625418862/96Logo.png'
|
||||||
}),
|
}),
|
||||||
|
Loading…
Reference in New Issue
Block a user