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

FREE FSpawnObject : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using System.Collections.Generic;
using Oxide.Core.Plugins;
using Rust;
using UnityEngine;
using System.Linq;
using Newtonsoft.Json;
using Oxide.Core;

namespace Oxide.Plugins
{
    // Плагин не несет какой то функциональности серверу, только спавн различных объектов на территории НПС ГОРОДА
    [Info("FSpawnObject", "Sempai#3239", "1.0.0")]
    public class FSpawnObject : RustPlugin
    {

        #region Variable
        
        [PluginReference] private Plugin CopyPaste;
        private MonumentInfo monument;
        
        public List<BaseEntity> _activeEntity = new List<BaseEntity>();
        public List<BasePlayer> _playerBot = new List<BasePlayer>();

        #endregion
        
       


        #region Spawn
        
        
        void LoadHouse()
        {
            List<BaseEntity> obj = new List<BaseEntity>();
            Vis.Entities(GetPosition(), 50f, obj, LayerMask.GetMask("Construction", "Deployable", "Deployed", "Debris", "Default"));
            foreach (BaseEntity item in obj.Where(x => x.OwnerID == 5565))
            {
                if (item == null)
                {
                    continue;
                }

                item.Kill();
            }

            timer.Once(2, () => { SetupHouse(); });
        }
        
        void SetupHouse()
        {
            var position = GetPosition();
            if (position == Vector3.zero) return;
            List<string> options = new List<string> { "entityowner", "true", "stability", "true", "deployables", "true", "autoheight", "false", "height", "-1" };
            object success = CopyPaste.Call("TryPasteFromVector3", position, (monument.transform.rotation.eulerAngles * Mathf.Deg2Rad).y - 12.90f, "House2", options.ToArray());
            if (success is string)
            {
                PrintWarning("Что то пошло не так! Дом не был установлен!");
                return;
            }
        }

        
        public Vector3 GetPosition()
        {
            return monument.transform.position + monument.transform.rotation * new Vector3(-26.30f, 2.73f, 16.35f);
        }
        
        void OnPasteFinished(List<BaseEntity> pastedEntities, string fileName)
        {
            if (fileName == "House2")
            {
                try
                {
                    _activeEntity.AddRange(pastedEntities);

                    foreach (var key in pastedEntities)
                    {
                        key.OwnerID = 5565;
                        
                        DecayEntity decayEntity = key as DecayEntity;
                        if (decayEntity != null)
                        {
                            decayEntity.decay = null;
                            decayEntity.decayVariance = 0;
                            decayEntity.ResetUpkeepTime();
                            decayEntity.DecayTouch();
                        }
                        
                        if (key.PrefabName == "assets/prefabs/deployable/table/table.deployed.prefab")
                        {
                            key.GetComponent<BaseCombatEntity>().pickup.enabled = false;
                        }

                        BaseChair chair = key as BaseChair;
                        if (chair != null && chair.skinID == 0 && config.SupportFCase)
                        {
                            chair.pickup.enabled = false;
                            var player = InitializeNPC(chair.transform.position);
                            chair.MountPlayer(player);
                            chair.SetFlag(BaseEntity.Flags.Busy, true);
                        }

                        if (chair != null && chair.skinID == 100)
                        {
                            InitializeNPCExcahnger(key.transform);
                            key.Kill();
                        }
                        BuildingBlock block = key as BuildingBlock;
                        if (block != null)
                        {
                            block.StopBeingDemolishable();
                            block.StopBeingRotatable();
                        }
                        
                    }
                }
                catch 
                {
                }
            }
        }
        
        

        #endregion


        #region FCase

        
        public void SpawnLootPrefab(Vector3 pos)
        {
            BaseEntity box = GameManager.server.CreateEntity("assets/prefabs/deployable/quarry/fuelstorage.prefab", new Vector3(pos.x, pos.y + Vector3.up.y, pos.z + 0.5f));
            box.enableSaving = false;
            box.OwnerID = 1156;
            box.Spawn();
        }
        
        
        
        
        
        private BasePlayer InitializeNPC(Vector3 pos)
        {
            BasePlayer npc = GameManager.server.CreateEntity("assets/prefabs/player/player.prefab", pos) as BasePlayer;
            npc.userID = config._FCaseNPC.ID;
            npc.name = config._FCaseNPC.Name;
            npc.displayName = npc.name;
            npc.Spawn();
            npc.SendNetworkUpdate();
            SpawnLootPrefab(npc.transform.position);
            _playerBot.Add(npc);
            if (config._FCaseNPC.Wear.Count > 0)
            {
                for (int i = 0; i < config._FCaseNPC.Wear.Count; i++)
                {
                    ItemManager.Create(ItemManager.FindItemDefinition(config._FCaseNPC.Wear[i].ShortName), 1, config._FCaseNPC.Wear[i].SkinID).MoveToContainer(npc.inventory.containerWear);
                }
            }
            return npc;
        }

        #endregion


        #region FExchanger

        private BasePlayer InitializeNPCExcahnger(Transform pos)
        {
            BasePlayer npc = GameManager.server.CreateEntity("assets/prefabs/player/player.prefab") as BasePlayer;
            npc.transform.position = pos.position;
            npc.userID = config._FExchangerNPC.ID;
            npc.name = config._FExchangerNPC.Name;
            npc.displayName = npc.name;
            npc.Spawn();

            npc.viewAngles = pos.rotation.eulerAngles;

            npc.SendNetworkUpdateImmediate();
            
            _playerBot.Add(npc);
            if (config._FExchangerNPC.Wear.Count > 0)
            {
                for (int i = 0; i < config._FExchangerNPC.Wear.Count; i++)
                {
                    ItemManager.Create(ItemManager.FindItemDefinition(config._FExchangerNPC.Wear[i].ShortName), 1, config._FExchangerNPC.Wear[i].SkinID).MoveToContainer(npc.inventory.containerWear);
                }
            }

            return npc;
        }
        

        #endregion

        #region Hooks
        
        

        void OnServerInitialized()
        {
            PrintWarning("\n-----------------------------\n " +" Author - Sempai#3239\n " +" VK - https://vk.com/rustnastroika\n " +" Forum - https://topplugin.ru\n " +" Discord - https://discord.gg/5DPTsRmd3G\n" +"-----------------------------");  
            if (!CopyPaste)
            {
                NextTick(() =>
                {
                    PrintError("Проверьте, установлен ли у вас плагин 'CopyPaste'");
                    Interface.Oxide.UnloadPlugin(Name);
                });
                return;
            }
            
            monument = TerrainMeta.Path.Monuments.FirstOrDefault(p => p.name.ToLower().Contains("compound") && p.IsSafeZone == true);
            
            if (!monument)
            {
                NextTick(() =>
                {
                    PrintError("Монумент 'ГОРОД НПС' не был найден на карте!");
                    Interface.Oxide.UnloadPlugin(Name);
                });
                return;
            }
            
            LoadHouse();
        }
        
        void Unload()
        {
            for (int i = 0; i < _activeEntity.Count; i++)
            {
                if (!_activeEntity[i].IsDestroyed)
                {
                    _activeEntity[i]?.Kill();
                }
            }
            for (int i = 0; i < _playerBot.Count; i++)
            {
                _playerBot[i]?.KillMessage();
            }
        }
        
        object CanAffordUpgrade(BasePlayer player, BuildingBlock block, BuildingGrade.Enum grade)
        {
            if (block.OwnerID == 5565)
            {
                return false;
            }

            return null;
        }
        

        void OnEntityTakeDamage(BaseCombatEntity victim, HitInfo info)
        {
            if (victim == null || info == null) return;

            if (victim.ToPlayer() != null)
            {
                if (_playerBot.Contains(victim))
                    info.damageTypes.ScaleAll(0);
            }
            if (victim.OwnerID == 5565)
                info.damageTypes.ScaleAll(0);
                
        }

        #endregion

        
        #region Configuration


        private PluginConfig config;

        protected override void LoadDefaultConfig()
        {
            config = PluginConfig.DefaultConfig();
        }

        protected override void LoadConfig()
        {
            base.LoadConfig();
            config = Config.ReadObject<PluginConfig>();

            if (config.PluginVersion < Version)
                UpdateConfigValues();

            Config.WriteObject(config, true);
        }

        private void UpdateConfigValues()
        {
            PluginConfig baseConfig = PluginConfig.DefaultConfig();
            if (config.PluginVersion < new VersionNumber(1, 0, 0))
            {
                PrintWarning("Config update detected! Updating config values...");
                PrintWarning("Config update completed!");
            }

            config.PluginVersion = Version;
        }

        protected override void SaveConfig()
        {
            Config.WriteObject(config);
        }
        
        
        public class ItemNPC
        {
            [JsonProperty("ShortName")]
            public string ShortName;

            [JsonProperty("SkinId")] 
            public ulong SkinID;
        }


        public class SettingsNpc
        {
            [JsonProperty("Имя")]
            public string Name;
            [JsonProperty("ID NPC (От его ID будет зависеть его внешность)")]
            public ulong ID;
            [JsonProperty("Одежда")]
            public List<ItemNPC> Wear = new List<ItemNPC>();
        }


        private class PluginConfig
        {

            [JsonProperty("Добавить поддержку FCase ?")]
            public bool SupportFCase;

            [JsonProperty("Настройка бота для плагина FCase")]
            public SettingsNpc _FCaseNPC = new SettingsNpc();

            [JsonProperty("Добавить поддержку FExchanger ?")]
            public bool SupportFExchanger;
            
            [JsonProperty("Настройка бота для плагина FExchanger")]
            public SettingsNpc _FExchangerNPC = new SettingsNpc();

            [JsonProperty("Добавить поддержку FDayReward ?")]
            public bool FDayReward;
            
            [JsonProperty("Настройка бота для плагина FDayReward")]
            public SettingsNpc _FDayRewardNPC = new SettingsNpc();

            [JsonProperty("Версия конфигурации")]
            public VersionNumber PluginVersion = new VersionNumber();

            public static PluginConfig DefaultConfig()
            {
                return new PluginConfig()
                {
                    SupportFCase = true,
                    _FCaseNPC = new SettingsNpc()
                    {
                        Name = "УЧЕНЫЙ",
                        ID = 21,
                        Wear = new List<ItemNPC>()
                        {
                            new ItemNPC()
                            {
                                ShortName = "pants",
                                SkinID = 1833026292,
                            },
                            new ItemNPC()
                            {
                                ShortName = "tshirt",
                                SkinID = 1833021945,
                            },
                            new ItemNPC()
                            {
                                ShortName = "shoes.boots",
                                SkinID = 0,
                            }
                        }
                    },
                    SupportFExchanger = true,
                    _FExchangerNPC = new SettingsNpc()
                    {
                        Name = "ГОРОДСКОЙ СКУПЩИК",
                        ID = 31,
                        Wear = new List<ItemNPC>()
                        {
                            new ItemNPC()
                            {
                                ShortName = "pants",
                                SkinID = 2899698577,
                            },
                            new ItemNPC()
                            {
                                ShortName = "tshirt.long",
                                SkinID = 2899684971,
                            },
                            new ItemNPC()
                            {
                                ShortName = "burlap.gloves",
                                SkinID = 0,
                            }
                        }
                    },
                    FDayReward = false,
                    PluginVersion = new VersionNumber(),
                };
            }
        }

        #endregion
        
    }
}

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