From 85fda7475932c0b37c38beb462702c52d1424a8f Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Sun, 12 Nov 2023 21:02:47 -0500 Subject: [PATCH 1/5] feat: drp and pause menu text --- client/discord.lua | 20 ++++++++++++++++++++ client/loops.lua | 6 ++++++ config.lua | 20 ++++++++++++++++++++ fxmanifest.lua | 1 + 4 files changed, 47 insertions(+) create mode 100644 client/discord.lua diff --git a/client/discord.lua b/client/discord.lua new file mode 100644 index 000000000..2dbe7604e --- /dev/null +++ b/client/discord.lua @@ -0,0 +1,20 @@ +local playersConnected = GlobalState.PlayerCount + +AddStateBagChangeHandler('PlayerCount', nil, function(bagName, _, value) + if bagName ~= 'global' or not value then return end + playersConnected = value +end) + +CreateThread(function() + while true do + SetDiscordAppId(Config.Discord.AppId) + SetDiscordRichPresenceAsset(Config.Discord.LargeIcon.icon) + SetDiscordRichPresenceAssetText(Config.Discord.LargeIcon.text) + SetDiscordRichPresenceAssetSmall(Config.Discord.SmallIcon.icon) + SetDiscordRichPresenceAssetSmallText(Config.Discord.SmallIcon.text) + SetRichPresence(('Players %s/'..Config.MaxPlayers):format(playersConnected)) + SetDiscordRichPresenceAction(0, Config.Discord.FirstButton.text, Config.Discord.FirstButton.link) + SetDiscordRichPresenceAction(1, Config.Discord.SecondButton.text, Config.Discord.SecondButton.link) + Wait(60000) + end +end) \ No newline at end of file diff --git a/client/loops.lua b/client/loops.lua index eafa73188..827c59b5f 100644 --- a/client/loops.lua +++ b/client/loops.lua @@ -12,3 +12,9 @@ CreateThread(function() end end end) + +CreateThread(function() + local mapText = Config.Server.PauseMapText + if mapText == '' or type(mapText) ~= 'string' then mapText = 'FiveM' end + Citizen.InvokeNative(joaat('ADD_TEXT_ENTRY'), 'FE_THDR_GTAO', mapText) +end) \ No newline at end of file diff --git a/config.lua b/config.lua index 4d5da8f21..9d0d23d20 100644 --- a/config.lua +++ b/config.lua @@ -109,9 +109,29 @@ Config.Server.PVP = true -- Enable or disable pvp on the server (Ability to shoo Config.Server.Discord = "" -- Discord invite link Config.Server.CheckDuplicateLicense = true -- Check for duplicate rockstar license on join Config.Server.Permissions = { 'god', 'admin', 'mod' } -- Add as many groups as you want here after creating them in your server.cfg +Config.Server.PauseMapText = 'Powered by Qbox' -- Text shown above the map when ESC is pressed. If left empty 'FiveM' will appear Config.NotifyPosition = 'top-right' -- 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-right' | 'bottom-left' +Config.Discord = {} -- Discord Rich Presence config +Config.Discord.AppId = '' -- This is the Application ID (Replace this with you own) +Config.Discord.LargeIcon = { -- To set this up, visit https://forum.cfx.re/t/how-to-updated-discord-rich-presence-custom-image/157686 + icon = 'logo_name', -- Here you will have to put the image name for the 'large' icon. + text = 'This is a large icon with text', -- Here you can add hover text for the 'large' icon. +} +Config.Discord.SmallIcon = { + icon = 'logo_name', -- Here you will have to put the image name for the 'small' icon. + text = 'This is a small icon with text', -- Here you can add hover text for the 'small' icon. +} +Config.Discord.FirstButton = { + text = 'First Button!', + link = 'fivem://connect/localhost:30120', +} +Config.Discord.SecondButton = { + text = 'Second Button!', + link = 'fivem://connect/localhost:30120', +} + ---@alias TableName string ---@alias ColumnName string diff --git a/fxmanifest.lua b/fxmanifest.lua index ed738de41..890f89606 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -19,6 +19,7 @@ client_scripts { 'client/loops.lua', 'client/events.lua', 'client/character.lua', + 'client/discord.lua', 'bridge/qb/client/drawtext.lua', 'bridge/qb/client/events.lua', } From ecf6d9951a82a8516275dc7fb33d2b24c25ac44f Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Sun, 12 Nov 2023 22:27:47 -0500 Subject: [PATCH 2/5] fix: invoke native directly --- client/loops.lua | 6 ------ client/main.lua | 4 ++++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/client/loops.lua b/client/loops.lua index 827c59b5f..eafa73188 100644 --- a/client/loops.lua +++ b/client/loops.lua @@ -12,9 +12,3 @@ CreateThread(function() end end end) - -CreateThread(function() - local mapText = Config.Server.PauseMapText - if mapText == '' or type(mapText) ~= 'string' then mapText = 'FiveM' end - Citizen.InvokeNative(joaat('ADD_TEXT_ENTRY'), 'FE_THDR_GTAO', mapText) -end) \ No newline at end of file diff --git a/client/main.lua b/client/main.lua index e50cb9a7d..5eedf42e9 100644 --- a/client/main.lua +++ b/client/main.lua @@ -59,3 +59,7 @@ end) lib.callback.register('qbx_core:client:setHealth', function(health) SetEntityHealth(cache.ped, health) end) + +local mapText = Config.Server.PauseMapText +if mapText == '' or type(mapText) ~= 'string' then mapText = 'FiveM' end +Citizen.InvokeNative(joaat('ADD_TEXT_ENTRY'), 'FE_THDR_GTAO', mapText) \ No newline at end of file From f739ed5d1d43fae0fd71c164ab6ecf4f21ba2421 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Sun, 12 Nov 2023 22:53:51 -0500 Subject: [PATCH 3/5] fix: drp --- client/discord.lua | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/client/discord.lua b/client/discord.lua index 2dbe7604e..ceff5fb8d 100644 --- a/client/discord.lua +++ b/client/discord.lua @@ -1,20 +1,12 @@ -local playersConnected = GlobalState.PlayerCount - AddStateBagChangeHandler('PlayerCount', nil, function(bagName, _, value) if bagName ~= 'global' or not value then return end - playersConnected = value + SetRichPresence(('Players %s/' .. Config.MaxPlayers):format(value)) end) -CreateThread(function() - while true do - SetDiscordAppId(Config.Discord.AppId) - SetDiscordRichPresenceAsset(Config.Discord.LargeIcon.icon) - SetDiscordRichPresenceAssetText(Config.Discord.LargeIcon.text) - SetDiscordRichPresenceAssetSmall(Config.Discord.SmallIcon.icon) - SetDiscordRichPresenceAssetSmallText(Config.Discord.SmallIcon.text) - SetRichPresence(('Players %s/'..Config.MaxPlayers):format(playersConnected)) - SetDiscordRichPresenceAction(0, Config.Discord.FirstButton.text, Config.Discord.FirstButton.link) - SetDiscordRichPresenceAction(1, Config.Discord.SecondButton.text, Config.Discord.SecondButton.link) - Wait(60000) - end -end) \ No newline at end of file +SetDiscordAppId(Config.Discord.AppId) +SetDiscordRichPresenceAsset(Config.Discord.LargeIcon.icon) +SetDiscordRichPresenceAssetText(Config.Discord.LargeIcon.text) +SetDiscordRichPresenceAssetSmall(Config.Discord.SmallIcon.icon) +SetDiscordRichPresenceAssetSmallText(Config.Discord.SmallIcon.text) +SetDiscordRichPresenceAction(0, Config.Discord.FirstButton.text, Config.Discord.FirstButton.link) +SetDiscordRichPresenceAction(1, Config.Discord.SecondButton.text, Config.Discord.SecondButton.link) From d1cbc58651c9c3f3a5abca197d02b9b8617b3162 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Sun, 12 Nov 2023 23:02:10 -0500 Subject: [PATCH 4/5] fix: native --- client/main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/main.lua b/client/main.lua index 5eedf42e9..c829527f9 100644 --- a/client/main.lua +++ b/client/main.lua @@ -62,4 +62,4 @@ end) local mapText = Config.Server.PauseMapText if mapText == '' or type(mapText) ~= 'string' then mapText = 'FiveM' end -Citizen.InvokeNative(joaat('ADD_TEXT_ENTRY'), 'FE_THDR_GTAO', mapText) \ No newline at end of file +AddTextEntry('FE_THDR_GTAO', mapText) \ No newline at end of file From 3abf588a144f38046e7b190c7ebab46e5191e581 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Sun, 12 Nov 2023 23:05:58 -0500 Subject: [PATCH 5/5] fix: var --- client/discord.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/discord.lua b/client/discord.lua index ceff5fb8d..095fa10f0 100644 --- a/client/discord.lua +++ b/client/discord.lua @@ -1,6 +1,7 @@ AddStateBagChangeHandler('PlayerCount', nil, function(bagName, _, value) if bagName ~= 'global' or not value then return end - SetRichPresence(('Players %s/' .. Config.MaxPlayers):format(value)) + local players = 'Players %s/' .. Config.MaxPlayers + SetRichPresence((players):format(value)) end) SetDiscordAppId(Config.Discord.AppId)