// NoMobs: no zombies and no mutants on the island (and, if you want, no wildlife or only some species). Those already
// there are removed when the plugin starts; their spawn points stay idle while it runs. Remove NoMobs.cs and they come
// back by themselves (rl_mob_respawn, 5 minutes by default).
// Admins: /mobs shows what is blocked; /mobs zombie|mutant|animal on|off changes it (kept in plugins/config/NoMobs.json).
// The AI survivors (bots) are not mobs: turn them off with the server setting rl_bots 0.
// Install: copy this file into the server's data folder, plugins/NoMobs.cs.
// Script engine rules: test objects with != null, no static fields that change, callbacks with one parameter at most.
using RustLegacy;
public class NoMobsConfig
{
public bool Zombies { get; set; } = false;
public bool Mutants { get; set; } = false;
/// Wildlife: chickens, rabbits, boars, stags, wolves, bears.
public bool Animals { get; set; } = true;
/// Species blocked even when their kind is allowed, e.g. "Wolf", "Bear", "Fast Zombie".
public List BlockedSpecies { get; set; } = new List();
}
public class NoMobs : RustPlugin
{
NoMobsConfig _config;
public override void OnLoaded()
{
_config = LoadConfig();
AddCommand( "mobs", OnMobs, "Which mobs spawn", true, "[zombie | mutant | animal] [on | off]" );
var removed = RemoveBlocked();
if ( removed > 0 ) Puts( $"removed {removed} mobs" );
}
bool Allowed( string kind, string species )
{
if ( _config.BlockedSpecies.Contains( species ) ) return false;
if ( kind == "zombie" ) return _config.Zombies;
if ( kind == "mutant" ) return _config.Mutants;
return _config.Animals;
}
public override bool? CanSpawnAnimal( string kind, string species, Vector3 position ) => Allowed( kind, species ) ? null : false;
/// Removes the blocked mobs already on the island; returns how many.
int RemoveBlocked()
{
var removed = 0;
foreach ( var a in Scene.GetAllComponents().ToList() )
{
if ( a == null || a.Species == null || Allowed( a.Species.Kind, a.Species.Name ) ) continue;
a.GameObject.Destroy();
removed++;
}
return removed;
}
void OnMobs( ChatCommand cmd )
{
var p = cmd.Player;
var kind = cmd.Arg( 0 );
var state = cmd.Arg( 1 );
if ( (kind == "zombie" || kind == "mutant" || kind == "animal") && (state == "on" || state == "off") )
{
if ( kind == "zombie" ) _config.Zombies = state == "on";
if ( kind == "mutant" ) _config.Mutants = state == "on";
if ( kind == "animal" ) _config.Animals = state == "on";
SaveConfig( _config );
var removed = RemoveBlocked();
Reply( p, state == "on" ? $"{kind}s spawn again (at their next respawn)." : $"{kind}s blocked, {removed} removed." );
return;
}
Reply( p, $"Zombies {Show( _config.Zombies )}, mutants {Show( _config.Mutants )}, animals {Show( _config.Animals )}"
+ (_config.BlockedSpecies.Count > 0 ? $", blocked species: {string.Join( ", ", _config.BlockedSpecies )}" : "") + ". /mobs zombie off to change." );
}
static string Show( bool on ) => on ? "on" : "off";
}