Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close the pause menu with esc #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 48 additions & 23 deletions client/pausemenu_cl.lua
Original file line number Diff line number Diff line change
@@ -1,45 +1,70 @@
----------------------------------
--<!>-- BOII | DEVELOPMENT --<!>--
----------------------------------

local mapOpen = false

-- Thread to trigger menu on keypress
Citizen.CreateThread(function()
while true do
Wait(1)
SetPauseMenuActive(false)
if (IsControlJustPressed(0, 200)) then
TransitionToBlurred(1000)
SetNuiFocus(true, true)
SendNUIMessage({
open = true
})
end
end
while true do
Wait(1)
SetPauseMenuActive(false)
if IsControlJustPressed(0, 200) then
if not IsPauseMenuActive() then
if mapOpen then
CloseMap()
mapOpen = false
else
TriggerEvent("boii-pausemenu:OpenMenu")
end
end
end
end
end)
-- Function to close menu
function ClosePause()
TransitionFromBlurred(1000)
SetNuiFocus(false, false)
SendNUIMessage({
open = false
})
end

-- Event to open the menu
RegisterNetEvent("boii-pausemenu:OpenMenu")
AddEventHandler("boii-pausemenu:OpenMenu", function()
TransitionToBlurred(1000)
SetNuiFocus(true, true)
SendNUIMessage({ open = true })
end)

-- Close button; closes menu
RegisterNUICallback('Close', function(data)
ClosePause()
end)

-- Settings button; sends to GTA options
RegisterNUICallback('Settings', function(data)
ClosePause()
ActivateFrontendMenu(GetHashKey('FE_MENU_VERSION_MP_PAUSE'),0,-1)
ClosePause()
ActivateFrontendMenu(GetHashKey('FE_MENU_VERSION_MP_PAUSE'), 0, -1)
end)

-- Disconnect button; drops player
RegisterNUICallback('DropPlayer', function(data)
TriggerServerEvent('boii-pausemenu:DropPlayer')
end)

-- Submit button; submits a report as a discord webhook
RegisterNUICallback('NewReport', function(data)
local NewReport = {fname = data.fname, lname = data.lname, reporttype = data.reporttype, subject = data.subject, description = data.description}
local NewReport = {
fname = data.fname,
lname = data.lname,
reporttype = data.reporttype,
subject = data.subject,
description = data.description
}
TriggerServerEvent('boii-pausemenu:SendReport', NewReport)
end)

-- Function to close menu
function ClosePause()
TransitionFromBlurred(1000)
SetNuiFocus(false, false)
SendNUIMessage({ open = false })
end

-- Event to listen for map opening
RegisterCommand("map", function()
mapOpen = not mapOpen
end)
13 changes: 12 additions & 1 deletion html/pausemenu.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
//------------------------------\\
//---\\ BOII | DEVELOPMENT //---\\
//------------------------------\\

document.addEventListener('keydown', function(event) {
if (event.key === 'Escape') {
// Envoyer un message au Lua pour fermer le menu
fetch(`https://${GetParentResourceName()}/exit`, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
body: JSON.stringify({})
});
}
});
$(document).ready(function(){
window.addEventListener('message', function(event) {
var item = event.data;
Expand Down
71 changes: 41 additions & 30 deletions server/pausemenu_sv.lua
Original file line number Diff line number Diff line change
@@ -1,48 +1,57 @@
----------------------------------
--<!>-- BOII | DEVELOPMENT --<!>--
----------------------------------

-- Event to collect (data) from nui callback
-- Event to collect data from NUI callback and send a report
RegisterNetEvent('boii-pausemenu:SendReport')
AddEventHandler('boii-pausemenu:SendReport', function(data)
local ids = ExtractIdentifiers(source)
local NewReport = {
playerid = source,
fname = data.fname,
local identifiers = ExtractIdentifiers(source)
local NewReport = {
playerid = source,
fname = data.fname,
lname = data.lname,
reporttype = data.reporttype,
subject = data.subject,
description = data.description,
discord = '<@'..ids.discord:gsub('discord:', '')..'>',
license = ids.license:gsub('license2:', '')
}
SendWebhook(NewReport)
subject = data.subject,
description = data.description,
discord = '<@' .. identifiers.discord:gsub('discord:', '') .. '>',
license = identifiers.license:gsub('license2:', '')
}
SendWebhook(NewReport)
end)
-- Function to send (data) through webhook

-- Function to send data through webhook
function SendWebhook(data)
local footertext = Config.Discord.BotData.Footer.Text
local footerText = Config.Discord.BotData.Footer.Text
local icon = Config.Discord.BotData.Footer.Icon
local botname = Config.Discord.BotData.Name
local botlogo = Config.Discord.BotData.Logo
local report = {
{
['title'] = '**Type:** '..data.reporttype,
['color'] = Config.Discord.Colour,
['footer'] = {
['text'] = footertext..os.date('%c'),
['icon_url'] = icon,
local botName = Config.Discord.BotData.Name
local botLogo = Config.Discord.BotData.Logo

local report = {
{
title = '**Type:** ' .. data.reporttype,
color = Config.Discord.Colour,
footer = {
text = footerText .. os.date('%c'),
icon_url = icon,
},
['description'] = '**First name:** '..data.fname..'\n**Last name:** '..data.lname..'\n**Subject:** '..data.subject..'\n**Description:** '..data.description..'\n**ID:** '..data.playerid..'\n**Discord:** '..data.discord..'\n**License:** ||'..data.license..'||',
}
}
PerformHttpRequest(Config.Discord.Webhook, function(err, text, headers) end, 'POST', json.encode({username = botname, embeds = report, avatar_url = botlogo}), {['Content-Type'] = 'application/json'})
description = string.format('**First name:** %s\n**Last name:** %s\n**Subject:** %s\n**Description:** %s\n**ID:** %s\n**Discord:** %s\n**License:** ||%s||',
data.fname, data.lname, data.subject, data.description, data.playerid, data.discord, data.license)
}
}

PerformHttpRequest(Config.Discord.Webhook, function(err, text, headers) end, 'POST', json.encode({
username = botName,
embeds = report,
avatar_url = botLogo
}), { ['Content-Type'] = 'application/json' })
end

-- Event to drop player
RegisterServerEvent('boii-pausemenu:DropPlayer')
AddEventHandler('boii-pausemenu:DropPlayer', function()
DropPlayer(source, 'You disconnected from the server.')
DropPlayer(source, 'You disconnected from the server.')
end)
-- Function to grab indentifiers; borrowed from BADGER-ANTICHEAT <3

-- Function to grab identifiers
function ExtractIdentifiers(id)
local identifiers = {
steam = '',
Expand All @@ -52,6 +61,7 @@ function ExtractIdentifiers(id)
xbl = '',
live = ''
}

for i = 0, GetNumPlayerIdentifiers(id) - 1 do
local playerID = GetPlayerIdentifier(id, i)
if string.find(playerID, 'steam') then
Expand All @@ -68,5 +78,6 @@ function ExtractIdentifiers(id)
identifiers.live = playerID
end
end

return identifiers
end
end