From e62bd9d53cf1b61f8227e8384145666ab55b66b3 Mon Sep 17 00:00:00 2001
From: Joseph Unitt <43848673+unitt99@users.noreply.github.com>
Date: Mon, 18 Nov 2024 16:52:45 +0000
Subject: [PATCH 1/5] Update .gitignore
---
.gitignore | 3 +++
1 file changed, 3 insertions(+)
diff --git a/.gitignore b/.gitignore
index 96bf815d..1e8f5b91 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,3 +39,6 @@ banlist.xml
# Personal
.vscode
+mods/deathmatch/libcrypto-3.dll
+mods/deathmatch/libssl-3.dll
+mods/deathmatch/mta_mysql.dll
From e4e49b2bb696e6d901fadd8b8e5443e9ddca2a11 Mon Sep 17 00:00:00 2001
From: Joseph Unitt <43848673+unitt99@users.noreply.github.com>
Date: Mon, 18 Nov 2024 19:00:16 +0000
Subject: [PATCH 2/5] Better Rich Presence Support.
---
.../resources/account/s_characters.lua | 3 ++
.../resources/discord/c_discord.lua | 37 +++++++++++++++++++
mods/deathmatch/resources/discord/meta.xml | 6 +++
.../resources/discord/s_discord.lua | 20 ++++++++++
mods/deathmatch/settings.xml.bak | 3 ++
5 files changed, 69 insertions(+)
create mode 100644 mods/deathmatch/resources/discord/c_discord.lua
create mode 100644 mods/deathmatch/resources/discord/meta.xml
create mode 100644 mods/deathmatch/resources/discord/s_discord.lua
diff --git a/mods/deathmatch/resources/account/s_characters.lua b/mods/deathmatch/resources/account/s_characters.lua
index 4ef42545..e681e8c0 100644
--- a/mods/deathmatch/resources/account/s_characters.lua
+++ b/mods/deathmatch/resources/account/s_characters.lua
@@ -518,6 +518,9 @@ function spawnCharacter(characterID, remoteAccountID, theAdmin, targetAccountNam
if freshSpawn then
triggerEvent( "social:look", client, client, ":edit" )
end
+
+ -- update discord
+ triggerClientEvent(client, "discord:updateRPC", client)
end
end
addEventHandler("accounts:characters:spawn", getRootElement(), spawnCharacter)
diff --git a/mods/deathmatch/resources/discord/c_discord.lua b/mods/deathmatch/resources/discord/c_discord.lua
new file mode 100644
index 00000000..f98e1db4
--- /dev/null
+++ b/mods/deathmatch/resources/discord/c_discord.lua
@@ -0,0 +1,37 @@
+-- Update function.
+function updateRPC()
+ if isDiscordRichPresenceConnected() then
+ local name = getPlayerName(localPlayer)
+
+ local currentPlayers = getElementsByType("player")
+ local maxPlayers = getElementData(root, "server:Slots") or 1024
+
+ if getElementData(localPlayer, "loggedin") == 0 then
+ setDiscordRichPresenceDetails("Logging into OwlGaming...")
+ else
+ setDiscordRichPresenceDetails("Playing as: "..name:gsub("_", " "))
+ end
+
+ setDiscordRichPresenceState("Currently " .. #currentPlayers .. "/" .. maxPlayers .. " playing!")
+ end
+end
+addEvent("discord:updateRPC", true)
+addEventHandler("discord:updateRPC", root, updateRPC)
+
+function connectRPC(appId)
+ -- reset
+ resetDiscordRichPresenceData()
+
+ -- set discord ApplicationID
+ setDiscordApplicationID(appId)
+
+ -- force an update.
+ updateRPC()
+end
+addEvent("discord:connectRPC", true)
+addEventHandler("discord:connectRPC", root, connectRPC)
+
+-- prevents the rich presence bugging.
+addEventHandler("onClientResourceStop", resourceRoot, function()
+ resetDiscordRichPresenceData()
+end)
\ No newline at end of file
diff --git a/mods/deathmatch/resources/discord/meta.xml b/mods/deathmatch/resources/discord/meta.xml
new file mode 100644
index 00000000..1d3f4233
--- /dev/null
+++ b/mods/deathmatch/resources/discord/meta.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mods/deathmatch/resources/discord/s_discord.lua b/mods/deathmatch/resources/discord/s_discord.lua
new file mode 100644
index 00000000..0bf8057b
--- /dev/null
+++ b/mods/deathmatch/resources/discord/s_discord.lua
@@ -0,0 +1,20 @@
+-- The below function will handle if the resource is restarted while players are on the server... let's sort out a few things...
+local appKey = get("application_id")
+
+function startUp()
+ for _, player in ipairs(getElementsByType("player")) do
+ triggerClientEvent(player, "discord:connectRPC", player, appKey)
+ end
+end
+
+-- we add a delay here so that the client resource loads in.
+function delayStartup()
+ setTimer(startUp, 2000, 1)
+end
+addEventHandler("onResourceStart", root, delayStartup)
+
+-- sends the application key to the player on join.
+function playerJoin()
+ triggerClientEvent(source, "discord:connectRPC", source, appKey)
+end
+addEventHandler("onPlayerJoin", root, playerJoin)
\ No newline at end of file
diff --git a/mods/deathmatch/settings.xml.bak b/mods/deathmatch/settings.xml.bak
index 59647c1a..5a3d965c 100644
--- a/mods/deathmatch/settings.xml.bak
+++ b/mods/deathmatch/settings.xml.bak
@@ -24,6 +24,9 @@
+
+
+
From 78bb04ec869f0cca4a6c8ac46db5269c80ef3882 Mon Sep 17 00:00:00 2001
From: Joseph Unitt <43848673+unitt99@users.noreply.github.com>
Date: Mon, 18 Nov 2024 19:04:36 +0000
Subject: [PATCH 3/5] Update mtaserver.conf.bak
---
mods/deathmatch/mtaserver.conf.bak | 1 +
1 file changed, 1 insertion(+)
diff --git a/mods/deathmatch/mtaserver.conf.bak b/mods/deathmatch/mtaserver.conf.bak
index d1a1eba2..8d08dba6 100644
--- a/mods/deathmatch/mtaserver.conf.bak
+++ b/mods/deathmatch/mtaserver.conf.bak
@@ -242,6 +242,7 @@
+
From d42449117511d462c40eb6f0c5755fed36b87ddc Mon Sep 17 00:00:00 2001
From: Joseph Unitt <43848673+unitt99@users.noreply.github.com>
Date: Mon, 18 Nov 2024 19:11:08 +0000
Subject: [PATCH 4/5] Revert "Update .gitignore"
This reverts commit e62bd9d53cf1b61f8227e8384145666ab55b66b3.
---
.gitignore | 3 ---
1 file changed, 3 deletions(-)
diff --git a/.gitignore b/.gitignore
index 1e8f5b91..96bf815d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,6 +39,3 @@ banlist.xml
# Personal
.vscode
-mods/deathmatch/libcrypto-3.dll
-mods/deathmatch/libssl-3.dll
-mods/deathmatch/mta_mysql.dll
From e6494349aa951d8b9937f393d6d9fbcbe7c004a5 Mon Sep 17 00:00:00 2001
From: Joseph Unitt <43848673+unitt99@users.noreply.github.com>
Date: Mon, 18 Nov 2024 19:24:06 +0000
Subject: [PATCH 5/5] Update meta.xml
---
mods/deathmatch/resources/discord/meta.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mods/deathmatch/resources/discord/meta.xml b/mods/deathmatch/resources/discord/meta.xml
index 1d3f4233..69397a60 100644
--- a/mods/deathmatch/resources/discord/meta.xml
+++ b/mods/deathmatch/resources/discord/meta.xml
@@ -1,5 +1,5 @@
-
+