Skip to content
Open
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
33 changes: 25 additions & 8 deletions client/discord.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
local maxPlayers = GlobalState.MaxPlayers
local maxPlayers = GlobalState.MaxPlayers or GetConvarInt('sv_maxclients', 64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

local discord = require 'config.client'.discord

if not discord.enabled then return end

AddStateBagChangeHandler('PlayerCount', '', function(bagName, _, value)
if bagName == 'global' and value then
SetRichPresence(('Players %s/%s'):format(value, maxPlayers))
end
end)

SetDiscordAppId(discord.appId)
SetDiscordRichPresenceAsset(discord.largeIcon.icon)
SetDiscordRichPresenceAssetText(discord.largeIcon.text)
SetDiscordRichPresenceAssetSmall(discord.smallIcon.icon)
SetDiscordRichPresenceAssetSmallText(discord.smallIcon.text)
SetDiscordRichPresenceAction(0, discord.firstButton.text, discord.firstButton.link)
SetDiscordRichPresenceAction(1, discord.secondButton.text, discord.secondButton.link)

AddStateBagChangeHandler('PlayerCount', '', function(bagName, _, value)
if bagName == 'global' and value then
TriggerEvent('discord:updatePresence', value)
end
end)

RegisterNetEvent('discord:updatePresence', function(currentCount)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a function rather than an event.

local playerId = GetPlayerServerId(PlayerId())
local playerName = "Bilinmiyor"

local PlayerData = QBX.PlayerData
if PlayerData and PlayerData.charinfo then
playerName = PlayerData.charinfo.firstname .. " " .. PlayerData.charinfo.lastname
end

local presenceText = ('[%s] %s | %s/%s'):format(playerId, playerName, currentCount or 0, maxPlayers)
SetRichPresence(presenceText)
end)

CreateThread(function()
Wait(5000)
TriggerEvent('discord:updatePresence', GlobalState.PlayerCount or 0)
end)
Comment on lines +32 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for? Why are we waiting 5 seconds?