diff --git a/client/client.lua b/client/client.lua index e06ec63..5662aa8 100644 --- a/client/client.lua +++ b/client/client.lua @@ -10,13 +10,15 @@ RegisterNetEvent('QBCore:Client:OnPlayerUnload', function() PlayerData = {} end) -RegisterCommand(Config.Command, function() - if PlayerData.job and PlayerData.job.name == Config.PoliceJob then - TriggerServerEvent('QBCore:ToggleDuty') - TriggerServerEvent('ngd-policeduty:Server:Log') - end -end) +if Config.UseCommand then + RegisterCommand(Config.Command, function() + if PlayerData.job and PlayerData.job.name == Config.PoliceJob or PlayerData.job and PlayerData.job.type == Config.PoliceJobType then + TriggerServerEvent('QBCore:ToggleDuty') + TriggerServerEvent('ngd-policeduty:Server:Log') + end + end) -CreateThread(function() - TriggerEvent('chat:addSuggestion', Config.ChatSuggestion, Config.ChatSuggestionM, {}) -end) \ No newline at end of file + CreateThread(function() + TriggerEvent('chat:addSuggestion', Config.ChatSuggestion, Config.ChatSuggestionM, {}) + end) +end diff --git a/config.lua b/config.lua index e2bfb40..7240517 100644 --- a/config.lua +++ b/config.lua @@ -1,6 +1,9 @@ Config = {} -Config.PoliceJob = 'police' -Config.Command = "pdduty" -Config.ChatSuggestion = "/pdduty" -Config.ChatSuggestionM = "Duty Toggle For Police" +--You can either use police job or the type below. +Config.PoliceJob = 'police' --Police job qbcore>shared>jobs.lua +Config.PoliceJobType = 'leo' --Police job type in qbcore>shared>jobs.lua type = +Config.UseCommand = true --Enables a / command for police to toggle duty. +Config.Command = "pdduty" --Name of / command for duty toggle +Config.ChatSuggestion = "/pdduty" --Chat suggestion +Config.ChatSuggestionM = "Duty Toggle For Police" --Chat suggestion diff --git a/server/server.lua b/server/server.lua index 48f788d..c92c778 100644 --- a/server/server.lua +++ b/server/server.lua @@ -1,25 +1,16 @@ +-- ██ ██ ███████ ██████ ██ ██ ██████ ██████ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ █ ██ █████ ██████ ███████ ██ ██ ██ ██ █████ +-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███ ███ ███████ ██████ ██ ██ ██████ ██████ ██ ██ + Config.Webhook = 'CHANGEME' +--------------------------------------------------------------------------------------------------------------------------------------------- + local QBCore = exports['qb-core']:GetCoreObject() local onDutyTimes = {} -RegisterNetEvent('ngd-policeduty:Server:Log', function() - local src = source - local xPlayer = QBCore.Functions.GetPlayer(src) - local playerName = xPlayer.PlayerData.charinfo.firstname .. " " .. xPlayer.PlayerData.charinfo.lastname - local metadata = xPlayer.PlayerData.metadata - if metadata and metadata.callsign then - playerName = playerName .. " (Callsign: " .. metadata.callsign .. ")" - end - if onDutyTimes[src] then - sendDutyTimeWebhook(src, playerName) - onDutyTimes[src] = nil - else - onDutyTimes[src] = os.time() - sendToDiscord(playerName .. " went on duty.") - end -end) - AddEventHandler('playerDropped', function(reason) local src = source if onDutyTimes[src] then @@ -37,7 +28,7 @@ function sendDutyTimeWebhook(src, playerName) local minutes = math.floor((timeOnDuty % 3600) / 60) local seconds = timeOnDuty % 60 sendToDiscord(playerName .. - " went off duty. Total time on duty: " .. hours .. "H " .. minutes .. "M " .. seconds .. "S") + " went off duty. Total time on duty: " .. hours .. "H " .. minutes .. "M " .. seconds .. "S") end RegisterNetEvent('QBCore:ToggleDuty') @@ -49,7 +40,7 @@ AddEventHandler('QBCore:ToggleDuty', function() if metadata and metadata.callsign then playerName = playerName .. " (Callsign: " .. metadata.callsign .. ")" end - if xPlayer.PlayerData.job and xPlayer.PlayerData.job.name == Config.PoliceJob then + 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 sendDutyTimeWebhook(src, playerName) onDutyTimes[src] = nil @@ -60,12 +51,14 @@ AddEventHandler('QBCore:ToggleDuty', function() end end) + function sendToDiscord(message) local webhook = Config.Webhook if webhook == '' or webhook == 'CHANGEME' then print('Please put webhook into editableserver.lua') return end + local currentDateTime = os.date("%m-%d-%Y %H:%M:%S") local connect = { { ["color"] = 255, @@ -73,7 +66,7 @@ function sendToDiscord(message) ["description"] = message, ["footer"] = { ["icon_url"] = "https://media.discordapp.net/attachments/1077462714902917171/1077462755625418862/96Logo.png", - ["text"] = "www.nemesisGD.com", + ["text"] = "www.nemesisGD.com | " .. currentDateTime, }, } }