A static service class for game telemetry and achievements. It provides methods to record game events like pushes, round wins, and survival time, and fetches leaderboard data.
using Sandbox;
using Sandbox.Services;
using System.Threading.Tasks;
public static class GameServices
{
public static void RecordPush()
{
Stats.Increment( "pushes_count", 1 );
Achievements.Unlock( "first_push" );
}
public static void RecordRoundWin()
{
Stats.Increment( "rounds_won", 1 );
}
public static void RecordSurvivalTime( double seconds )
{
Stats.SetValue( "survival_time", seconds );
}
public static void RecordRevive( int count = 1 )
{
Stats.Increment( "total_revives", count );
}
public static async Task SaveStatsAsync()
{
await Stats.FlushAsync();
}
public static async Task FetchLeaderboard( string statIdent = "pushes_count" )
{
var board = Leaderboards.GetFromStat( "seilordstudio.one_more_push", statIdent );
board.SetAggregationSum();
board.CenterOnMe();
await board.Refresh();
if ( board.Entries != null )
{
foreach ( var entry in board.Entries )
{
Log.Info( $"#{entry.Rank} {entry.DisplayName} — {entry.Value}" );
}
}
}
}