-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91588fe
commit 946474d
Showing
7 changed files
with
195 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,59 @@ | ||
local QBCore = exports['qb-core']:GetCoreObject() | ||
lib.locale() | ||
local defconMenu = {} | ||
|
||
-- ===== Armar estructura del menú de alertas | ||
RegisterNetEvent('neko_alertaslspd:client:openMenu') | ||
AddEventHandler('neko_alertaslspd:client:openMenu', function() | ||
exports['qb-menu']:openMenu({ | ||
{ header = '⠀⠀⠀⠀⠀⠀⠀🚓 Estado de Alertas', isMenuHeader = true }, | ||
{ header = '🟢 ⠀Alerta Verde', txt = '', params = { event = 'neko_alertaslspd:client:setAlertaVerde:Parametro' } }, | ||
{ header = '🟡 ⠀Alerta Amarilla', txt = '', params = { event = 'neko_alertaslspd:client:setAlertaAmarilla:Parametro' } }, | ||
{ header = '🔴 ⠀Alerta Roja', txt = '', params = { event = 'neko_alertaslspd:client:setAlertaRoja:Parametro' } }, | ||
-- ===== Armar estructura del menú | ||
defconMenu = { | ||
id = 'defcon_status', | ||
title = locale('menu_title'), | ||
options = { | ||
{ | ||
header = '⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀❌ Cerrar', | ||
params = { event = 'qb-menu:client:closeMenu' } | ||
title = locale('menu_title_green'), | ||
description = locale('menu_description_green'), | ||
icon = 'fas fa-fw fa-circle', | ||
iconColor = '#82ba3d', | ||
serverEvent = 'neko_alertasdefcon:server:change_status', | ||
args = { status = 'g' } | ||
}, | ||
}) | ||
end) | ||
{ | ||
title = locale('menu_title_yellow'), | ||
description = locale('menu_description_yellow'), | ||
icon = 'fas fa-fw fa-circle', | ||
iconColor = '#edcf55', | ||
serverEvent = 'neko_alertasdefcon:server:change_status', | ||
args = { status = 'y' } | ||
}, | ||
{ | ||
title = locale('menu_title_red'), | ||
description = locale('menu_description_red'), | ||
icon = 'fas fa-fw fa-circle', | ||
iconColor = '#e3203d', | ||
serverEvent = 'neko_alertasdefcon:server:change_status', | ||
args = { status = 'r' } | ||
} | ||
} | ||
} | ||
|
||
-- ===== Definir del lado de servidor el estado actual | ||
RegisterNetEvent('neko_alertaslspd:client:setAlertaVerde:Parametro') | ||
AddEventHandler('neko_alertaslspd:client:setAlertaVerde:Parametro', function() | ||
TriggerServerEvent('neko_alertaslspd:server:setAlertaVerde') | ||
end) | ||
lib.registerContext(defconMenu) | ||
|
||
RegisterNetEvent('neko_alertaslspd:client:setAlertaAmarilla:Parametro') | ||
AddEventHandler('neko_alertaslspd:client:setAlertaAmarilla:Parametro', function() | ||
TriggerServerEvent('neko_alertaslspd:server:setAlertaAmarilla') | ||
end) | ||
|
||
RegisterNetEvent('neko_alertaslspd:client:setAlertaRoja:Parametro') | ||
AddEventHandler('neko_alertaslspd:client:setAlertaRoja:Parametro', function() | ||
TriggerServerEvent('neko_alertaslspd:server:setAlertaRoja') | ||
-- ===== Armar estructura del menú de alertas | ||
RegisterNetEvent('neko_alertas_defcon:client:open_menu') | ||
AddEventHandler('neko_alertas_defcon:client:open_menu', function() | ||
QBCore.Functions.GetPlayerData(function(PlayerData) | ||
if PlayerData.job.name ~= 'police' then | ||
lib.notify({ description = locale('player_not_police') , type = 'error' }) | ||
else | ||
if not PlayerData.job.onduty then | ||
lib.notify({ description = locale('player_not_duty') , type = 'error' }) | ||
else | ||
lib.showContext(defconMenu.id) | ||
end | ||
end | ||
end) | ||
end) | ||
|
||
-- ===== Enviar el evento de estado al cliente de los jugadores | ||
RegisterNetEvent('neko_alertaslspd:client:setAlertaVerde:Jugadores') | ||
AddEventHandler('neko_alertaslspd:client:setAlertaVerde:Jugadores', function() | ||
SendNUIMessage({ type = 'logo', display = 'alerta_verde' }) | ||
end) | ||
|
||
RegisterNetEvent('neko_alertaslspd:client:setAlertaAmarilla:Jugadores') | ||
AddEventHandler('neko_alertaslspd:client:setAlertaAmarilla:Jugadores', function() | ||
SendNUIMessage({ type = 'logo', display = 'alerta_amarilla' }) | ||
end) | ||
|
||
RegisterNetEvent('neko_alertaslspd:client:setAlertaRoja:Jugadores') | ||
AddEventHandler('neko_alertaslspd:client:setAlertaRoja:Jugadores', function() | ||
SendNUIMessage({ type = 'logo', display = 'alerta_roja' }) | ||
RegisterNetEvent('neko_alertas_defcon:client:set_current_status') | ||
AddEventHandler('neko_alertas_defcon:client:set_current_status', function(data) | ||
SendNUIMessage({ alert = data.status }) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Config = {} | ||
|
||
Config.Command = 'alertaslspd' | ||
|
||
-- Send public alerts on discord | ||
Config.webhookPublic = '' | ||
|
||
-- Send details of who changed the DEFCON status | ||
Config.webhookLogs = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
fx_version 'cerulean' | ||
game 'gta5' | ||
fx_version 'cerulean' | ||
game 'gta5' | ||
lua54 'yes' | ||
-- =========================================================== | ||
description 'Sistemas de alertas (DEFCON) para la policía' | ||
author 'KuroNeko' | ||
-- =========================================================== | ||
version '1.1.0' | ||
|
||
author 'imkuroneko' | ||
description 'Sistema de notificación (UI) de estado de alertas' | ||
version '1.0.0' | ||
-- =========================================================== | ||
shared_scripts { '@ox_lib/init.lua' } | ||
server_scripts { 'config.lua', 'server.lua' } | ||
client_scripts { 'client.lua' } | ||
|
||
client_scripts { | ||
'client.lua', | ||
} | ||
server_scripts { | ||
'server.lua', | ||
} | ||
|
||
ui_page 'ui/index.html' | ||
|
||
files { | ||
'ui/index.html', | ||
'ui/img/*.png', | ||
'ui/script.js' | ||
} | ||
ui_page 'ui/index.html' | ||
files { 'locales/es.json', 'ui/**' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"menu_title" : "🚓 Alertas DEFCON", | ||
"menu_title_green" : "Alerta Verde", | ||
"menu_description_green" : "Cambiar el estado DEFCON a alerta verde", | ||
"menu_title_yellow" : "Alerta Amarilla", | ||
"menu_description_yellow" : "Cambiar el estado DEFCON a alerta amarilla", | ||
"menu_title_red" : "Alerta Roja", | ||
"menu_description_red" : "Cambiar el estado DEFCON a alerta roja", | ||
|
||
"command_help" : "Abrir menú de estado DEFCON", | ||
|
||
"player_not_duty" : "No te encuentras en servicio", | ||
"player_not_police" : "No perteneces al cuerpo policial", | ||
|
||
"update_status_current" : "Este ya es el estado actual del DEFCON", | ||
"update_status_success" : "Estado DEFCON actualizado exitosamente", | ||
|
||
"webhook_public_title" : "Nuevo estado de Alerta DEFCON", | ||
|
||
"webhook_public_title_green" : "Se ha establecido la alerta verde", | ||
"webhook_public_description_green" : "webhook_public_description_green...", | ||
"webhook_public_title_yellow" : "Se ha establecido la alerta amarilla", | ||
"webhook_public_description_yellow" : "webhook_public_description_yellow...", | ||
"webhook_public_title_red" : "Se ha establecido la alerta roja", | ||
"webhook_public_description_red" : "webhook_public_description_red...", | ||
|
||
"webhook_log_title" : "Actualización de estado DEFCON", | ||
"webhook_log_description" : "El oficial `%s` (CID: `%s`) ha cambiado el estado DEFCON." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,103 @@ | ||
local QBCore = exports['qb-core']:GetCoreObject() | ||
local nivelAlertaActual = 0 | ||
PlayerData = nil | ||
lib.locale() | ||
SendedWebhookRestart = false | ||
DefconCurrentStatus = 'g' | ||
|
||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() | ||
QBCore.Functions.GetPlayerData(function(PlayerData) | ||
PlayerData = PlayerData.job | ||
end) | ||
end) | ||
|
||
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo) | ||
PlayerData = JobInfo | ||
end) | ||
|
||
|
||
RegisterCommand("alertaslspd", function(source) | ||
-- ===== Registrar comando | ||
lib.addCommand(Config.Command, { help = locale('command_help'), params = {} }, function(source, args) | ||
local Player = QBCore.Functions.GetPlayer(source) | ||
|
||
if Player and Player.PlayerData.job.name == 'police' then | ||
if Player.PlayerData.job.onduty then | ||
TriggerClientEvent("neko_alertaslspd:client:openMenu", source) | ||
TriggerClientEvent('neko_alertas_defcon:client:open_menu', source) | ||
else | ||
TriggerClientEvent('QBCore:Notify', source, 'No te encuentras de servicio') | ||
TriggerClientEvent('ox_lib:notify', source, { description = locale('player_not_duty') , type = 'error' }) | ||
end | ||
else | ||
TriggerClientEvent('QBCore:Notify', source, 'No eres del cuerpo policial') | ||
TriggerClientEvent('ox_lib:notify', source, { description = locale('player_not_police') , type = 'error' }) | ||
end | ||
end, false) | ||
|
||
RegisterServerEvent('neko_alertaslspd:server:setAlertaVerde') | ||
AddEventHandler('neko_alertaslspd:server:setAlertaVerde', function() | ||
nivelAlertaActual = 0 | ||
end) | ||
|
||
RegisterServerEvent('neko_alertaslspd:server:setAlertaAmarilla') | ||
AddEventHandler('neko_alertaslspd:server:setAlertaAmarilla', function() | ||
nivelAlertaActual = 1 | ||
end) | ||
-- ===== Evento | ||
RegisterServerEvent('neko_alertasdefcon:server:change_status') | ||
AddEventHandler('neko_alertasdefcon:server:change_status', function(data) | ||
local src = source | ||
if data.status ~= 'g' and data.status ~= 'y' and data.status ~= 'r' then return end | ||
|
||
RegisterServerEvent('neko_alertaslspd:server:setAlertaRoja') | ||
AddEventHandler('neko_alertaslspd:server:setAlertaRoja', function() | ||
nivelAlertaActual = 2 | ||
if data.status == DefconCurrentStatus then | ||
TriggerClientEvent('ox_lib:notify', source, { description = locale('update_status_current') , type = 'info' }) | ||
else | ||
TriggerClientEvent('ox_lib:notify', source, { description = locale('update_status_success') , type = 'success' }) | ||
DefconCurrentStatus = data.status | ||
SendWebhookPublic() | ||
SendWebhookLog(src) | ||
end | ||
end) | ||
|
||
Citizen.CreateThread(function() | ||
if not SendedWebhookRestart then | ||
SendWebhookPublic() | ||
SendedWebhookRestart = true | ||
end | ||
|
||
while true do | ||
Citizen.Wait(0) | ||
if nivelAlertaActual == 0 then | ||
TriggerClientEvent('neko_alertaslspd:client:setAlertaVerde:Jugadores', -1) | ||
elseif nivelAlertaActual == 1 then | ||
TriggerClientEvent('neko_alertaslspd:client:setAlertaAmarilla:Jugadores', -1) | ||
elseif nivelAlertaActual == 2 then | ||
TriggerClientEvent('neko_alertaslspd:client:setAlertaRoja:Jugadores', -1) | ||
end | ||
Citizen.Wait(5000) | ||
TriggerClientEvent('neko_alertas_defcon:client:set_current_status', -1, { status = DefconCurrentStatus }) | ||
end | ||
end) | ||
|
||
-- ===== Funciones | ||
function SendWebhookPublic() | ||
local t, m, c = '', '', 0 | ||
if DefconCurrentStatus == 'r' then | ||
t = 'webhook_public_title_red' | ||
m = 'webhook_public_description_red' | ||
c = 14884925 | ||
elseif DefconCurrentStatus == 'y' then | ||
t = 'webhook_public_title_yellow' | ||
m = 'webhook_public_description_yellow' | ||
c = 15585109 | ||
else | ||
t = 'webhook_public_title_green' | ||
m = 'webhook_public_description_green' | ||
c = 8567357 | ||
end | ||
|
||
SendContentToDiscord(Config.webhookPublic, true, { | ||
{ ['title'] = locale(t), ['description'] = locale(m), ['color'] = c, ['timestamp'] = os.date("!%Y-%m-%dT%H:%M:%SZ", os.time()) } | ||
}) | ||
end | ||
|
||
function SendWebhookLog(source) | ||
local officer = QBCore.Functions.GetPlayer(source) | ||
|
||
local name = officer.PlayerData.charinfo.firstname..' '..officer.PlayerData.charinfo.lastname | ||
local cid = officer.PlayerData.citizenid | ||
local title = 'placeholder' | ||
|
||
if DefconCurrentStatus == 'r' then | ||
title = locale('webhook_public_title_red') | ||
elseif DefconCurrentStatus == 'y' then | ||
title = locale('webhook_public_title_yellow') | ||
else | ||
title = locale('webhook_public_title_green') | ||
end | ||
|
||
|
||
SendContentToDiscord(Config.webhookLogs, false, { | ||
{ ['title'] = locale(title), ['description'] = locale('webhook_log_description', name, cid), ['color'] = 3191259, ['timestamp'] = os.date("!%Y-%m-%dT%H:%M:%SZ", os.time()) } | ||
}) | ||
end | ||
|
||
function SendContentToDiscord(webhookUrl, tagEveryone, embedContent) | ||
if DefconCurrentStatus ~= 'r' and DefconCurrentStatus ~= 'g' and DefconCurrentStatus ~= 'y' then return end | ||
if not webhookUrl or webhookUrl == '' or webhookUrl == nil then return end | ||
|
||
local contentData = {} | ||
|
||
contentData['embeds'] = embedContent | ||
|
||
if tagEveryone then contentData['content'] = '@everyone' end | ||
|
||
PerformHttpRequest(webhookUrl, function(e, t, h) end, 'POST', json.encode(contentData), { ['Content-Type'] = 'application/json' }) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters