177 lines
5.7 KiB
Lua
177 lines
5.7 KiB
Lua
|
|
if SERVER then return end
|
|
|
|
if util.IsBinaryModuleInstalled("gdiscord") then
|
|
require("gdiscord")
|
|
local RPC_AppID = "1287531216630976603"
|
|
function DiscordUpdate()
|
|
local rpc_data = {}
|
|
|
|
rpc_data["buttonPrimaryLabel"] = "Join Server"
|
|
rpc_data["buttonPrimaryUrl"] = "steam://open/friends"-- .. "108.5.3.134:27015"
|
|
rpc_data["buttonSecondaryLabel"] = "Join Server"
|
|
rpc_data["buttonSecondaryUrl"] = "steam://open/friends"-- .. "108.5.3.134:27015"
|
|
rpc_data["partySize"] = player.GetCount()
|
|
rpc_data["partyMax"] = game.MaxPlayers()
|
|
rpc_data["largeImageKey"] = "benny_1"--"map_b-mp_6t"
|
|
rpc_data["largeImageText"] = "The Six Team Map"
|
|
--rpc_data["smallImageKey"] = "doof2"
|
|
--rpc_data["smallImageText"] = "Domination"
|
|
|
|
local NewTime = os.time() - math.floor(CurTime())
|
|
|
|
local modedata = BennyGame:GetModeData()
|
|
local modename = modedata and l8( modedata.name ) or "(unknown)"
|
|
|
|
local details = modename .. " on " .. BennyGame:GetMapName()
|
|
local title = ""
|
|
if BennyGame:GetState() == BG_STATE_ACTIVE then
|
|
rpc_data["startTimestamp"] = NewTime + BennyGame:GetRoundStartedAt()
|
|
rpc_data["endTimestamp"] = NewTime + BennyGame:GetRoundStartedAt() + BennyGame:GetTimeLimit()
|
|
|
|
local myteam = LocalPlayer():Team()
|
|
local myteamscore = BennyGame:GetScoreForTeam( myteam )
|
|
|
|
if BennyGame.RTeamID[ myteam ] then
|
|
-- In play
|
|
local BiggestScore = 0
|
|
|
|
for TeamID, RealTeamID in ipairs( BennyGame.TeamsInPlay ) do
|
|
if RealTeamID == myteam then continue end
|
|
BiggestScore = math.max( BiggestScore, BennyGame:GetScoreForTeam( RealTeamID ) )
|
|
end
|
|
|
|
if myteamscore > BiggestScore then
|
|
details = details .. " ▪ Winning"
|
|
elseif myteamscore == BiggestScore then
|
|
details = details .. " ▪ Tied"
|
|
else
|
|
details = details .. " ▪ Losing"
|
|
end
|
|
else
|
|
details = details .. " ▪ Spectating"
|
|
end
|
|
|
|
local first = true
|
|
if BennyGame.RTeamID[ myteam ] then
|
|
details = details .. " ▪ " .. myteamscore
|
|
first = false
|
|
else
|
|
details = details .. " ▪ "
|
|
end
|
|
|
|
for TeamID, RealTeamID in ipairs( BennyGame.TeamsInPlay ) do
|
|
if RealTeamID == myteam then continue end
|
|
details = details .. (first and "" or "-") .. BennyGame:GetScoreForTeam( RealTeamID ) -- placeholder, i need a thing
|
|
first = false
|
|
end
|
|
|
|
elseif BennyGame:GetState() == BG_STATE_PRE then
|
|
rpc_data["startTimestamp"] = NewTime + BennyGame:GetPregameStartedAt()
|
|
rpc_data["endTimestamp"] = NewTime + BennyGame:GetPregameStartedAt() + BennyGame:GetPregameTime()
|
|
|
|
title = "Pregame"
|
|
elseif BennyGame:GetState() == BG_STATE_POST then
|
|
rpc_data["startTimestamp"] = NewTime + BennyGame:GetRoundFinishedAt()
|
|
rpc_data["endTimestamp"] = NewTime + BennyGame:GetRoundFinishedAt() + BennyGame:GetPostgameTime()
|
|
|
|
title = "Postgame"
|
|
elseif BennyGame:GetState() == BG_STATE_WAITINGFORPLAYERS then
|
|
rpc_data["startTimestamp"] = nil--NewTime + BennyGame:GetRoundFinishedAt() + BennyGame:GetPostgameTime()
|
|
rpc_data["endTimestamp"] = nil
|
|
|
|
title = "Waiting for Players"
|
|
end
|
|
|
|
rpc_data["details"] = details
|
|
rpc_data["state"] = title
|
|
|
|
DiscordUpdateRPC(rpc_data)
|
|
end
|
|
hook.Add("Think", "RPresence_Think_Discord", function()
|
|
if !RPC_Initialized then
|
|
DiscordRPCInitialize(RPC_AppID)
|
|
DiscordUpdate()
|
|
RPC_Initialized = true
|
|
RPC_NextUpdate = RealTime() + 1
|
|
end
|
|
if RPC_NextUpdate <= RealTime() then
|
|
DiscordUpdate()
|
|
RPC_NextUpdate = RealTime() + 1
|
|
end
|
|
end)
|
|
else
|
|
print("A module is missing: gdiscord")
|
|
end
|
|
|
|
if util.IsBinaryModuleInstalled("steamrichpresencer") then
|
|
require("steamrichpresencer")
|
|
function SteamUpdate()
|
|
local title = "Your Name Is Benny"
|
|
--title = " ▪ Domination on SixT"
|
|
--title = " ▪ Winning"
|
|
--title = " ▪ 999-10"
|
|
|
|
local modedata = BennyGame:GetModeData()
|
|
local modename = modedata and l8( modedata.name ) or "(unknown)"
|
|
|
|
title = title .. " ▪ " .. modename .. " on " .. BennyGame:GetMapName()
|
|
if BennyGame:GetState() == BG_STATE_ACTIVE then
|
|
local myteam = LocalPlayer():Team()
|
|
local myteamscore = BennyGame:GetScoreForTeam( myteam )
|
|
|
|
if BennyGame.RTeamID[ myteam ] then
|
|
-- In play
|
|
local BiggestScore = 0
|
|
|
|
for TeamID, RealTeamID in ipairs( BennyGame.TeamsInPlay ) do
|
|
if RealTeamID == myteam then continue end
|
|
BiggestScore = math.max( BiggestScore, BennyGame:GetScoreForTeam( RealTeamID ) )
|
|
end
|
|
|
|
if myteamscore > BiggestScore then
|
|
title = title .. " ▪ Winning"
|
|
elseif myteamscore == BiggestScore then
|
|
title = title .. " ▪ Tied"
|
|
else
|
|
title = title .. " ▪ Losing"
|
|
end
|
|
else
|
|
title = title .. " ▪ Spectating"
|
|
end
|
|
|
|
local first = true
|
|
if BennyGame.RTeamID[ myteam ] then
|
|
title = title .. " ▪ " .. myteamscore
|
|
first = false
|
|
else
|
|
title = title .. " ▪ "
|
|
end
|
|
|
|
for TeamID, RealTeamID in ipairs( BennyGame.TeamsInPlay ) do
|
|
if RealTeamID == myteam then continue end
|
|
title = title .. (first and "" or "-") .. BennyGame:GetScoreForTeam( RealTeamID ) -- placeholder, i need a thing
|
|
first = false
|
|
end
|
|
|
|
elseif BennyGame:GetState() == BG_STATE_PRE then
|
|
title = title .. " ▪ Pregame"
|
|
elseif BennyGame:GetState() == BG_STATE_POST then
|
|
title = title .. " ▪ Postgame"
|
|
elseif BennyGame:GetState() == BG_STATE_WAITINGFORPLAYERS then
|
|
title = title .. " ▪ Waiting for Players"
|
|
end
|
|
|
|
steamworks.SetRichPresence("generic", title)
|
|
steamworks.SetRichPresence("steam_player_group", tostring(BennyGame:GetUUID()) )
|
|
steamworks.SetRichPresence("steam_player_group_size", tostring(#player.GetHumans()) )
|
|
end
|
|
hook.Add("Think", "RPresence_Think_Steam", function()
|
|
if (Steam_NextUpdate or 0) <= RealTime() then
|
|
SteamUpdate()
|
|
Steam_NextUpdate = RealTime() + 1
|
|
end
|
|
end)
|
|
else
|
|
print("A module is missing: steamrichpresencer")
|
|
end |