Getting a list of spawned animals? (C#)
Discussion in 'Rust Development' started by ThunderZ, Jun 29, 2016.
-
You could reach this with something like that, what give you a list of all animals with their count:
[DOUBLEPOST=1467220466][/DOUBLEPOST]The plugin Cornucopia will give you a deeper look into this and other stuff of getting numbers from spawned "autospawns":Code:Dictionary<string, IGrouping<string, BaseEntity>> GetAnimals() { return Resources.FindObjectsOfTypeAll<BaseNPC>() .Where(c => c.isActiveAndEnabled) .Cast<BaseEntity>() .GroupBy(c => c.LookupShortPrefabName()).ToDictionary(c => c.Key, c => c); } void DumpSpawns(Dictionary<string, IGrouping<string, BaseEntity>> entities) { foreach (var t in entities) Puts($"{t.Key.PadRight(50)} {t.Value.Count()}"); } [ConsoleCommand("animals.dump")] private void DumpCommand(ConsoleSystem.Arg arg) { if (arg != null && arg.Player() != null && arg.Player().IsAdmin() == false) return; DumpSpawns(GetAnimals()); }
Cornucopia for Rust | Oxide
