How can I just have just the AutomatedWorkcarts and remove all other Trains Above Ground?
using Oxide.Core;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("PrefabLimiter", "HoverCatz", "1.0.0")]
class PrefabLimiter : RustPlugin
{
Dictionary<string, int> spawnChances = new Dictionary<string, int>();
void OnServerInitialized()
{
/* Load config */
spawnChances = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, int>>("PrefabLimiter") ?? spawnChances;
if (spawnChances == null)
spawnChances = new Dictionary<string, int>();
if (spawnChances.Count <= 0)
AddDefaultConfig();
Interface.Oxide.DataFileSystem.WriteObject("PrefabLimiter", spawnChances);
Puts($"PrefabLimiter successfully initialized. Loaded {spawnChances.Count} config values.");
}
private void AddDefaultConfig()
{
//spawnChances.Add("assets/bundled/prefabs/autospawn/resource/ores/metal-ore.prefab", 100); // 0% chance to spawn
//spawnChances.Add("assets/bundled/prefabs/autospawn/resource/ores/stone-ore.prefab", 100); // 100% chance to spawn
//spawnChances.Add("assets/bundled/prefabs/autospawn/resource/ores/sulfur-ore.prefab", 100); // 0% chance to spawn
//spawnChances.Add("assets/bundled/prefabs/autospawn/resource/ores_sand/metal-ore.prefab", 100); // 0% chance to spawn
//spawnChances.Add("assets/bundled/prefabs/autospawn/resource/ores_sand/stone-ore.prefab", 100); // 100% chance to spawn
//spawnChances.Add("assets/bundled/prefabs/autospawn/resource/ores_sand/sulfur-ore.prefab", 100); // 0% chance to spawn
//spawnChances.Add("assets/bundled/prefabs/autospawn/resource/ores_snow/metal-ore.prefab", 100); // 0% chance to spawn
//spawnChances.Add("assets/bundled/prefabs/autospawn/resource/ores_snow/stone-ore.prefab", 100); // 100% chance to spawn
//spawnChances.Add("assets/bundled/prefabs/autospawn/resource/ores_snow/sulfur-ore.prefab", 100); // 100% chance to spawn
//spawnChances.Add("assets/bundled/prefabs/autospawn/collectable/stone/metal-collectable.prefab", 100); // 0% chance to spawn
//spawnChances.Add("assets/bundled/prefabs/autospawn/collectable/stone/sulfur-collectable.prefab", 100); // 0% chance to spawn
spawnChances.Add("assets/content/vehicles/trains/locomotive/locomotive.entity.prefab", 0); // 0% chance to spawn
spawnChances.Add("assets/content/vehicles/trains/workcart/workcart_aboveground.entity.prefab", 0); // 0% chance to spawn
spawnChances.Add("assets/content/vehicles/trains/workcart/workcart_aboveground2.entity.prefab", 0); // 0% chance to spawn
spawnChances.Add("assets/content/vehicles/trains/wagons/trainwagona.entity.prefab", 0); // 0% chance to spawn
spawnChances.Add("assets/content/vehicles/trains/wagons/trainwagonb.entity.prefab", 0); // 0% chance to spawn
spawnChances.Add("assets/content/vehicles/trains/wagons/trainwagonc.entity.prefab", 0); // 0% chance to spawn
spawnChances.Add("assets/content/vehicles/trains/wagons/trainwagond.entity.prefab", 0); // 0% chance to spawn
spawnChances.Add("assets/content/vehicles/trains/wagons/trainwagone.entity.prefab", 0); // 0% chance to spawn
spawnChances.Add("assets/content/vehicles/trains/wagons/trainwagonunloadable.entity.prefab", 0); // 0% chance to spawn
spawnChances.Add("assets/content/vehicles/trains/wagons/trainwagonunloadablefuel.entity.prefab", 0); // 0% chance to spawn
spawnChances.Add("assets/content/vehicles/trains/wagons/trainwagonunloadableloot.entity.prefab", 0); // 0% chance to spawn
// Add more prefabs here if you want
// https://www.corrosionhour.com/rust-prefab-list/
}
void Unload()
{
Interface.Oxide.DataFileSystem.WriteObject("PrefabLimiter", spawnChances);
}
[ConsoleCommand("prefabLimiterReload")]
void ReloadConfig(ConsoleSystem.Arg _)
{
/* Reload config */
spawnChances = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, int>>("PrefabLimiter") ?? spawnChances;
if (spawnChances == null)
spawnChances = new Dictionary<string, int>();
if (spawnChances.Count <= 0)
AddDefaultConfig();
Interface.Oxide.DataFileSystem.WriteObject("PrefabLimiter", spawnChances);
Puts($"PrefabLimiter successfully reloaded {spawnChances.Count} config values.");
}
void OnEntitySpawned(BaseNetworkable entity)
{
int intChance;
string name = entity.name;
if (!spawnChances.TryGetValue(name, out intChance))
return; // Doesn't exist in our list? 100% chance to spawn
if (intChance == 100)
return; // 100% chance, spawn.
else
if (intChance == 0)
{
entity.AdminKill(); // Destroy the Prefab! No chance check.
return;
}
float fChance = intChance / 100f;
float rnd = UnityEngine.Random.value;
if (rnd > fChance)
entity.AdminKill(); // Destroy the Prefab!
}
}
}