commit b0aa7258d9cc263e7f69741b5f95dfd65f638b81 Author: delucecc <31872986+delucecc@users.noreply.github.com> Date: Sat Oct 28 19:27:53 2023 -0700 init diff --git a/client/client.lua b/client/client.lua new file mode 100644 index 0000000..8a0c7b5 --- /dev/null +++ b/client/client.lua @@ -0,0 +1,22 @@ +local QBCore = exports['qb-core']:GetCoreObject() + +local PlayerData = {} + +RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() + PlayerData = QBCore.Functions.GetPlayerData() +end) + +RegisterNetEvent('QBCore:Client:OnPlayerUnload', function() + PlayerData = {} +end) + +RegisterCommand(Config.Command, function() + if PlayerData.job and PlayerData.job.name == 'police' 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 diff --git a/config.lua b/config.lua new file mode 100644 index 0000000..7a46708 --- /dev/null +++ b/config.lua @@ -0,0 +1,5 @@ +Config = {} + +Config.Command = "pdduty" +Config.ChatSuggestion = "/pdduty" +Config.ChatSuggestionM = "Duty Toggle For Police" diff --git a/fxmanifest.lua b/fxmanifest.lua new file mode 100644 index 0000000..8dfe265 --- /dev/null +++ b/fxmanifest.lua @@ -0,0 +1,18 @@ +Description 'ngd-pdduty | Nemesis Gaming Development' +author 'deluce#0' +fx_version 'cerulean' +game 'gta5' + +client_scripts { + 'client/*.lua', +} + +server_scripts { + 'server/*.lua', +} + +shared_scripts { + 'config.lua' +} + +lua54 'yes' diff --git a/server/server.lua b/server/server.lua new file mode 100644 index 0000000..254697d --- /dev/null +++ b/server/server.lua @@ -0,0 +1,67 @@ +Config.Webhook = 'https://discord.com/api/webhooks/1119678233198207086/0dGlQPqWMiEWJ6mn7EvMosYDoq5gjZrZZjjVfEDU6ywyH5ShbprV27vgobMzF8WPXCD0' + +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 + 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 timeOnDuty = os.difftime(endTime, onDutyTimes[src]) + local hours = math.floor(timeOnDuty / 3600) + 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") +end + +function sendToDiscord(message) + local webhook = Config.Webhook + if webhook == '' or webhook == 'CHANGEME' then + print('Please put webhook into editableserver.lua') + return + end + local connect = { + { + ["color"] = 255, + ["title"] = "Police Duty", + ["description"] = message, + ["footer"] = { + ["icon_url"] = "https://media.discordapp.net/attachments/1077462714902917171/1077462755625418862/96Logo.png", + ["text"] = "www.nemesisGD.com", + }, + } + } + PerformHttpRequest(webhook, function(err, text, headers) end, 'POST', + json.encode({ + username = 'Nemesis Gaming Development | Police Duty', + embeds = connect, + avatar_url = 'https://media.discordapp.net/attachments/1077462714902917171/1077462755625418862/96Logo.png' + }), + { ['Content-Type'] = 'application/json' }) +end