A game component that tracks recent kills for a killfeed. It stores a small list of KillEntry structs with killer, victim, method and timestamp, exposes a singleton Instance, and keeps the list capped at five entries.
using Sandbox;
using System.Collections.Generic;
public sealed class Killfeed : Component
{
public static Killfeed Instance { get; private set; }
public struct KillEntry
{
public string KillerName { get; set; }
public string VictimName { get; set; }
public string Method { get; set; }
public float Time { get; set; }
}
public List<KillEntry> Entries { get; private set; } = new();
protected override void OnStart()
{
Instance = this;
}
public void AddEntry( string killer, string victim, string method = "Push" )
{
Entries.Add( new KillEntry
{
KillerName = killer,
VictimName = victim,
Method = method,
Time = RealTime.Now
} );
if ( Entries.Count > 5 )
{
Entries.RemoveAt( 0 );
}
}
}