"facepunch.ss1" is a combination of the organization facepunch and the package/game ident ss1.
It means Sausage Survivors 1.
The code belongs in a new simple component, which you attach to a GameObject.
I think for all this to work properly, your game has to be published. It doesn't need to be publically available, hidden works.
You need to save stats to a leaderboard. I have a public function inside my HighscoreManager.cs to write to the leaderboard "LeaderboardTest". When my player runs out of HP my HealthSystem.cs writes to the leaderboard.
public void WriteToLeaderboard()
{
// Add score to leaderboard
Sandbox.Services.Stats.SetValue("LeaderboardTest", CurrentScore );
LastScore = CurrentScore;
}
To display the board I created this simple component. It uses a TextRenderer as a Property. Both are on the same GameObject.
using Sandbox;
using System;
using System.Threading.Tasks;
public sealed class LeaderboardDisplay : Component
{
[Property] TextRenderer boardText;
protected override void OnStart()
{
// Call this whenever you want to display/update the leaderboard
DisplayLeaderboard();
}
public async Task DisplayLeaderboard()
{
// You fetch the stats from the package your organization published. You set your package name when publishing.
var _scoreBoard = Sandbox.Services.Leaderboards.GetFromStat( "your_organization.your_package", "LeaderboardTest" );
// Configure the created board
_scoreBoard.SetAggregationMax();
_scoreBoard.SetSortDescending();
_scoreBoard.MaxEntries = 15;
boardText.Text = "LOADING...";
await _scoreBoard.Refresh();
boardText.Text = "";
// Loop over the entries and add them to the TextRenderer
foreach ( var entry in _scoreBoard.Entries )
{
boardText.Text += $"\n{entry.CountryCode} #{entry.Rank} {entry.DisplayName}: {Math.Round( entry.Value, 0 )}";
// Log.Info( $"#{entry.Rank} {entry.DisplayName}: {entry.Value}" );
}
}
}Feel free to ask more questions. ❤
I hope this helps! 🙂👍