• File: ServerManager.cs
  • Full Path: /var/www/FileManager/Files/RUST PLUGINS/ServerManager.cs
  • Date Modified: 04/30/2025 6:10 PM
  • File size: 4.48 KB
  • MIME-type: text/plain
  • Charset: utf-8
 
Open Back
using Rust;
using System.Collections.Generic;
using ConVar;
using Steamworks;

namespace Oxide.Plugins
{
    [Info("ServerManager", "Sopelka", "1.2.1")]
    public class ServerManager : RustPlugin
    {
        public string Map = "Belarus Map";
        public List<string> nameprefabs = new List<string>()
        {
            "assets/bundled/prefabs/autospawn/resource/wood_log_pile/wood-pile.prefab",
            "assets/prefabs/deployable/hot air balloon/hotairballoon.prefab",
            "assets/bundled/prefabs/autospawn/resource/v3_arid_cactus/cactus-2.prefab",
            "assets/content/vehicles/trains/wagons/trainwagonc.entity.prefab",
            "assets/content/vehicles/trains/caboose/traincaboose.entity.prefab"
        };

        // void Init() => 
        void OnTerrainInitialized() => SetLevelName();
        private void OnServerInitialized() => SendCommandServer();
        private void SendCommandServer()
        {
            SetLevelName();
            Server.Command("ai.move false");
            Server.Command("ai.think false");
            Server.Command("server.radiation false");
            Server.Command("fps.limit 100");

            Server.Command("bear.population 1");
            Server.Command("bike.motorbikemonumentpopulation 0");
            Server.Command("bike.pedalmonumentpopulation 0");
            Server.Command("bike.pedalroadsidepopulation 0");
            Server.Command("boar.population 1");
            Server.Command("chicken.population 0");
            Server.Command("ai.npc_max_population_military_tunnels 0");
            Server.Command("halloween.murdererpopulation 0");
            Server.Command("halloween.scarecrowpopulation 0");
            Server.Command("spawn.fill_populations 1");
            Server.Command("halloweendungeon.population 0");
            Server.Command("hotairballoon.population 0");
            Server.Command("metaldetectorsource.population 4");
            Server.Command("minicopter.population 0");
            Server.Command("modularcar.population 0");
            Server.Command("motorrowboat.population 0");
            Server.Command("polarbear.population 0");
            Server.Command("rhib.rhibpopulation 1");
            Server.Command("ridablehorse2.population 1");
            Server.Command("scraptransporthelicopter.population 0");
            Server.Command("stag.population 0");
            Server.Command("traincar.population 1");
            Server.Command("wolf.population 0");
            Server.Command("xmasdungeon.xmaspopulatio 0");
            Server.Command("zombie.population 0");

            //POPULATION SPAWN
            //foreach (ConsoleSystem.Command command in ConsoleGen.All)
            //{
            //    try {
            //        if (command.FullName.Contains("population"))
            //        {

            //            Server.Command($"{command.FullName} {GetPopulate(command.FullName)}");
            //        }
            //    }
            //    catch { }
            //}

            timer.Every(1f, () => { SetLevelName(); });
        }

        private void SetLevelName()
        {
            try { LevelManager.CurrentLevelName = Map; } catch { }
            try { ConVar.Server.level = Map; } catch { }
            try { SteamServer.MapName = Map; } catch { }
        }

        private object GetPopulate(string fullName)
        {
            try
            {
                if (fullName.Contains("npc")) return 1;
                if (fullName.Contains("boar")) return 1;
                if (fullName.Contains("bear")) return 1;
                if (fullName.Contains("ridablehorse2")) return 1;
                if (fullName.Contains("rhib")) return 1;
                if (fullName.Contains("traincar")) return 2;
            }
            catch { }
            return 0;
        }

        void OnEntitySpawned(BaseEntity entity)
        {
            if (entity != null) entity.OnKilled();
            foreach (string nameprefab in nameprefabs)
            {
                if (entity.name == nameprefab)
                {
                    //Puts($"Destroy {nameprefab}");
                    if (entity != null) entity.OnKilled();
                }
            }
        }

        object OnWeaponReload(BaseProjectile projectile, BasePlayer player)
        {
            projectile.primaryMagazine.capacity = 100;
            projectile.SendNetworkUpdate();
            return null;
        }
    }
}