Component attached to a local player that wraps the engine's player stats object. It stores a reference to Sandbox.Services.Stats.LocalPlayer and reads the "kills" stat into a tuple, and provides an async RefreshAsync method to refresh the local stats from the service.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KOTH;
public sealed class LocalStats : Component
{
public Sandbox.Services.Stats.PlayerStats LocalStatsObject { get; private set; }
public (string Name, double Value) KillsStat = ("kills", 0);
protected override void OnAwake()
{
base.OnAwake();
LocalStatsObject = Sandbox.Services.Stats.LocalPlayer;
KillsStat.Value = LocalStatsObject.Get(KillsStat.Name).Sum;
}
public async Task RefreshAsync()
{
await LocalStatsObject.Refresh();
}
}