Improved Discord Presence Script

This commit is contained in:
Jacob
2023-04-28 20:05:13 +01:00
parent a6b67b4229
commit 9c0b873be4
3 changed files with 225 additions and 0 deletions
@@ -0,0 +1,137 @@
Citizen.CreateThread(function()
while true do
local prevtime = GetGameTimer()
local prevframes = GetFrameCount()
local fps = -1
local curtime = GetGameTimer()
local curframes = GetFrameCount()
local id = GetPlayerServerId(PlayerId())
local playername = GetPlayerName(PlayerId())
local player = GetPlayerPed(GetPlayerFromServerId(playerid))
local position = GetEntityCoords(player, true)
local zoneID = GetNameOfZone(position.x, position.y, position.z)
local zone = GetLabelText(zoneID)
local coords = GetEntityCoords(ped)
local streetcord1, streetcord2 = GetStreetNameAtCoord(coords.x, coords.y, coords.z, Citizen.ResultAsInteger(), Citizen.ResultAsInteger())
local street1 = GetStreetNameFromHashKey(streetcord1)
local street2 = GetStreetNameFromHashKey(streetcord2)
local onlinePlayers = #GetActivePlayers()
SetDiscordAppId(Config.ApplicationID)
if Config.EnableLargeImage then
SetDiscordRichPresenceAsset(Config.LargeImageName)
end
if Config.SetRichPresenceText then
if Config.RichPresenceText == "standard" then
SetRichPresence("Mainhatten Scripts - discord.gg/ce6auKzCbV")
elseif Config.RichPresenceText == "playerFPS" then
Citizen.CreateThread(function()
while not NetworkIsPlayerActive(PlayerId()) or not NetworkIsSessionStarted() do
Citizen.Wait(Config.UpdateTime*1000)
end
while true do
if((curtime - prevtime) > 1000) then
fps = (curframes - prevframes) - 1
prevtime = curtime
prevframes = curframes
end
SetRichPresence(Translation[Config.Locale]['playerfps_text'] ..fps.. "FPS")
Citizen.Wait(Config.UpdateTime*1000)
end
end)
elseif Config.RichPresenceText == "playerID" then
SetRichPresence(playername.." [ID: "..id.."]")
elseif Config.RichPresenceText == "playerLocZone" then
SetRichPresence(Translation[Config.Locale]['zone_text'] ..zone)
elseif Config.RichPresenceText == "playerLocStreet" then
SetRichPresence(Translation[Config.Locale]['street1_text'] ..street1.. " | " ..street2)
elseif Config.RichPresenceText == "discordServer" then
SetRichPresence(Translation[Config.Locale]['discordserver_text'] ..Config.YourDisordServerLink)
elseif Config.RichPresenceText == "customEGRP" then
SetRichPresence(playername.." ID: "..id.." | Players: "..onlinePlayers.." | Currently at: "..zone)
else
SetRichPresence(Config.RichPresenceText)
end
end
if Config.EnableLargeImageText then
if Config.LargeImageText == "playerFPS" then
Citizen.CreateThread(function()
while not NetworkIsPlayerActive(PlayerId()) or not NetworkIsSessionStarted() do
Citizen.Wait(Config.UpdateTime*1000)
end
while true do
if((curtime - prevtime) > 1000) then
fps = (curframes - prevframes) - 1
prevtime = curtime
prevframes = curframes
end
SetDiscordRichPresenceAssetText(Translation[Config.Locale]['playerfps_text'] ..fps.. "FPS")
Citizen.Wait(Config.UpdateTime*1000)
end
end)
elseif Config.LargeImageText == "playerID" then
SetDiscordRichPresenceAssetText(playername.." [ID: "..id.."]")
elseif Config.LargeImageText == "playerLoc" then
SetDiscordRichPresenceAssetText(Translation[Config.Locale]['zone_text'] ..zone)
elseif Config.LargeImageText == "playerLocStreet" then
SetDiscordRichPresenceAssetText(Translation[Config.Locale]['street1_text'] ..street1.. " | " ..street2)
elseif Config.LargeImageText == "discordServer" then
SetDiscordRichPresenceAssetText(Translation[Config.Locale]['discordserver_text'] ..Config.YourDisordServerLink)
elseif Config.RichPresenceText == "customEGRP" then
SetRichPresence(playername.." ID: "..id.." | Players: "..onlinePlayers.." | Currently at: "..zone)
else
SetDiscordRichPresenceAssetText(Config.LargeImageText)
end
end
if Config.EnableSmallImage then
SetDiscordRichPresenceAssetSmall(Config.SmallImageName)
end
if Config.EnableSmallImageText then
if Config.SmallImageText == "playerFPS" then
Citizen.CreateThread(function()
while not NetworkIsPlayerActive(PlayerId()) or not NetworkIsSessionStarted() do
Citizen.Wait(5*1000)
end
while true do
if((curtime - prevtime) > 1000) then
fps = (curframes - prevframes) - 1
prevtime = curtime
prevframes = curframes
end
SetDiscordRichPresenceAssetSmallText(Translation[Config.Locale]['playerfps_text'] ..fps.. "FPS")
Citizen.Wait(Config.UpdateTime*1000)
end
end)
elseif Config.SmallImageText == "playerID" then
SetDiscordRichPresenceAssetSmallText(playername.." ["..id.."]")
elseif Config.SmallImageText == "playerLoc" then
SetDiscordRichPresenceAssetSmallText(Translation[Config.Locale]['zone_text'] ..zone)
elseif Config.SmallImageText == "playerLocStreet" then
SetDiscordRichPresenceAssetSmallText(Translation[Config.Locale]['street1_text'] ..street1.. " | " ..street2)
elseif Config.SmallImageText == "discordServer" then
SetDiscordRichPresenceAssetSmallText(Translation[Config.Locale]['discordserver_text'] ..Config.YourDisordServerLink)
elseif Config.RichPresenceText == "customEGRP" then
SetRichPresence(playername.." ID: "..id.." | Players: "..onlinePlayers.." | Currently at: "..zone)
else
SetDiscordRichPresenceAssetSmallText(Config.SmallImageText)
end
end
if Config.EnableButtons then
for k,v in pairs(Config.Buttons) do
SetDiscordRichPresenceAction(v.Index, v.Label, v.URL)
end
end
Citizen.Wait(Config.UpdateTime*1000)
end
end)
@@ -0,0 +1,81 @@
Config = {}
Translation = {}
Config.ApplicationID = "543866591079694346" -- Enter your Discord Application ID --> https://discord.com/developers/applications/
Config.UpdateTime = 5 -- 1 = 1 Second -> Updates every Second. Default is 60 Seconds
Config.Locale = "en" -- Current translations: de, en
Config.YourDisordServerLink = "https://discord.elitegami.ng"
--[[ Premade Text Version for RichPresenceText, LargeImageText and SmallImageText - Just
"playerFPS" = Shows the players FPS when you hover the image
"playerID" = Shows the Server ID of the player
"discordServer" = Shows your Discord Server Link from Config.YourDisordServerLink = "YOUR_LINK_HERE"
"playerLocZone" = Shows the current Zone Location of the Player
"playerLocStreet" = Shows the current Street Location of the Player
"standard" = Standart Option
If you want to display own text just write it there
]]
--Main Text Options
Config.SetRichPresenceText = true -- Main Text
Config.RichPresenceText = "customEGRP" --Main Text of DiscordRP
-- Icon Options
Config.EnableLargeImage = true -- Large Image enabled. Replace true with false to disable.
Config.LargeImageName = "eg-blurple" -- Image Name without .png, .jpg, or .jpeg --> https://discord.com/developers/applications/YOUR_APPLICATION_ID/rich-presence/assets
Config.EnableLargeImageText = true -- Text which shows up if you hover large image. Replace true with false to disable.
Config.LargeImageText = "Elite Gaming RP" -- Text which shows up if you hover image.
Config.EnableSmallImage = false -- Small Image enabled. Replace true with false to disable.
Config.SmallImageName = "YOUR_IMAGE_NAME" -- Image Name without .png, .jpg, or .jpeg --> https://discord.com/developers/applications/YOUR_APPLICATION_ID/rich-presence/assets
Config.EnableSmallImageText = false -- Text which shows up if you hover small image. Replace true with false to disable.
Config.SmallImageText = "standard" -- Text which shows up if you hover image.
-- Button Options
Config.EnableButtons = true
--[[ If you want to add more Buttons you only need to Copy the "ButtonDiscord" Section from Line 51 to 55 and Rename ButtonDiscord to what you want.
!! You need to add a , after all section endings. Here in Line 56 so it looks like this }, !!
Don't forget to increase the index by one number each time!
Unfortunately, a maximum of two buttons are currently possible from Discord.]]
Config.Buttons = {
ButtonWebsite = {
Index = 0,
Label = "Discord",
URL = "https://discord.com/invite/x6PwsHtVjE"
}
ButtonWebsite = {
Index = 1,
Label = "Connect",
URL = "fivem://connect/play.elitegami.ng:30120"
}
}
-- Translations
Translation = {
['de'] = {
['zone_text'] = 'Derzeitige Position: ',
['discordserver_text'] = 'Unser Discord:',
['playerfps_text'] = 'Derzeitige FPS: ',
['street1_text'] = 'Befindet sich auf: ',
},
['en'] = {
['zone_text'] = 'Current Position: ',
['discordserver_text'] = 'Our Disord: ',
['playerfps_text'] = 'Current FPS: ',
['street1_text'] = 'Located on: ',
}
}
@@ -0,0 +1,7 @@
fx_version 'cerulean'
games { 'gta5' }
client_scripts {
'config.lua',
'client/main.lua'
}