The killfeed UI backend. Keeps a list of the last six kill entries and broadcasts new ones to all clients with an [Rpc.Broadcast] method. Has convenience helpers for push, nextbot, revive, time freeze and hazard announcements.
using Sandbox;
using System.Collections.Generic;
public enum KillCategory
{
Push,
Nextbot,
Revive,
TimeFreeze,
Hazard,
System
}
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 string Icon { get; set; }
public KillCategory Category { get; set; }
public float Time { get; set; }
}
public List<KillEntry> Entries { get; private set; } = new();
protected override void OnStart()
{
Instance = this;
}
[Rpc.Broadcast]
public void BroadcastEntry( string killer, string victim, string method, string icon, KillCategory category )
{
Entries.Add( new KillEntry
{
KillerName = killer,
VictimName = victim,
Method = method,
Icon = icon,
Category = category,
Time = RealTime.Now
} );
if ( Entries.Count > 6 )
{
Entries.RemoveAt( 0 );
}
}
public void AddEntry( string killer, string victim, string method = "Push", string icon = "", KillCategory category = KillCategory.System )
{
if ( string.IsNullOrEmpty( icon ) )
{
icon = category switch
{
KillCategory.Push => "💥",
KillCategory.Nextbot => "💀",
KillCategory.Revive => "🚑",
KillCategory.TimeFreeze => "❄️",
KillCategory.Hazard => "💣",
_ => "ℹ️"
};
}
BroadcastEntry( killer, victim, method, icon, category );
}
public void AnnouncePush( string pusher, string victim )
{
AddEntry( pusher, victim, "PUSHED OFF", "💥", KillCategory.Push );
}
public void AnnounceNextbotDown( string botName, string victim )
{
AddEntry( botName, victim, "DOWNED", "💀", KillCategory.Nextbot );
}
public void AnnounceRevive( string rescuer, string revived )
{
AddEntry( rescuer, revived, "REVIVED", "🚑", KillCategory.Revive );
}
public void AnnounceTimeFreeze( string player )
{
AddEntry( player, "ARENA", "ACTIVATED TIME FREEZE", "❄️", KillCategory.TimeFreeze );
}
public void AnnounceHazard( string victim, string hazardName = "ANVIL" )
{
AddEntry( hazardName, victim, "CRUSHED", "💣", KillCategory.Hazard );
}
}