Иконка ресурса

FREE HorseModifier : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using Newtonsoft.Json;
using System;
using System.IO;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Thoroughbred Spawner", "Boj", "1.0.0")]
    [Description("Automatically changes the breed of spawned and existing horses to a random thoroughbred.")]
    public class HorseModifier : RustPlugin
    {
        private const int BlackThoroughbredBreed = 9;
        private const int WhiteThoroughbredBreed = 8;

        private System.Random random = new System.Random();

        private bool loggingEnabled = true;

        #region Configuration

        private class PluginConfig
        {
            [JsonProperty(PropertyName = "Enable Logging")]
            public bool EnableLogging { get; set; } = true;
        }

        private PluginConfig config;

        protected override void LoadDefaultConfig()
        {
            config = new PluginConfig();
            SaveConfig();
        }

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<PluginConfig>();
            }
            catch (Exception ex)
            {
                PrintError($"Error reading config: {ex.Message}");
                LoadDefaultConfig();
            }
        }

        protected override void SaveConfig() => Config.WriteObject(config);

        #endregion

        private void OnServerInitialized()
        {
            loggingEnabled = config.EnableLogging;
            ConvertExistingHorses();
        }

        private void ConvertExistingHorses()
        {
            foreach (var entity in BaseNetworkable.serverEntities)
            {
                if (entity is RidableHorse horse && horse != null && IsTestRidableHorse(horse))
                {
                    ChangeHorseToRandomThoroughbred(horse);
                }
            }
        }

        private bool IsTestRidableHorse(RidableHorse horse)
        {
            return horse.ShortPrefabName.Contains("testridablehorse");
        }

        private void ChangeHorseToRandomThoroughbred(RidableHorse horse)
        {
            int randomBreed = random.Next(0, 2); 

            if (randomBreed == 0)
            {
                horse.ApplyBreed(BlackThoroughbredBreed);
                Log("Changed horse to Black Thoroughbred.");
            }
            else
            {
                horse.ApplyBreed(WhiteThoroughbredBreed);
                Log("Changed horse to White Thoroughbred.");
            }
        }

        private void OnEntitySpawned(BaseNetworkable entity)
        {
            if (entity is RidableHorse horse && horse != null && IsTestRidableHorse(horse))
            {
                ChangeHorseToRandomThoroughbred(horse);
            }
        }

        private void Log(string message)
        {
            if (loggingEnabled)
                Puts(message);
        }
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху