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

FREE SilentBuildingBlocks : 1.0.1 1.0.1

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using HarmonyLib;
using Oxide.Core;
using Oxide.Core.Plugins;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Silent Building Blocks", "rustmods.ru", "1.0.1")]
    [Description("Removes the smoke effect when placing building blocks.")]
    public class SilentBuildingBlocks : RustPlugin
    {
        #region Fields

        private static SilentBuildingBlocks _plugin;

        #endregion Fields

        #region Oxide Hooks

        private void Init()
        {
            _plugin = this;
        }

        private void Unload()
        {
            _plugin = null;
        }

        private object OnCustomConstructionPlace(Planner planner, Construction.Target placement, Construction component)
        {
            // Replicate the original 'DoPlacement' method minus the effect.BasePlayer ownerPlayer = planner.GetOwnerPlayer();
            if (ownerPlayer == null)
                return null;

            BaseEntity baseEntity = component.CreateConstruction(placement, true);
            if (baseEntity == null)
                return null;

            float conditionMultiplier = 1f;

            // Replicate the logic from 'GetOwnerItem'.Item ownerItem = null;
            if (ownerPlayer.inventory != null)
                ownerItem = ownerPlayer.inventory.FindItemByUID((planner as HeldEntity).ownerItemUID);

            if (ownerItem != null)
            {
                baseEntity.skinID = ownerItem.skin;
                if (ownerItem.hasCondition)
                {
                    conditionMultiplier = ownerItem.conditionNormalized;
                }
            }

            baseEntity.gameObject.AwakeFromInstantiate();

            BuildingBlock buildingBlock = baseEntity as BuildingBlock;
            if (buildingBlock != null)
            {
                buildingBlock.blockDefinition = PrefabAttribute.server.Find<Construction>(buildingBlock.prefabID);
                if (buildingBlock.blockDefinition == null)
                {
                    Debug.LogError("Placing a building block that has no block definition!");
                    return null;
                }

                buildingBlock.SetGrade(buildingBlock.blockDefinition.defaultGrade.gradeBase.type);
            }

            BaseCombatEntity baseCombatEntity = baseEntity as BaseCombatEntity;
            if (baseCombatEntity != null)
            {
                float maxHealth;
                if (buildingBlock != null)
                    maxHealth = buildingBlock.currentGrade.maxHealth;
                else
                    maxHealth = baseCombatEntity.startHealth;

                baseCombatEntity.ResetLifeStateOnSpawn = false;
                baseCombatEntity.InitializeHealth(maxHealth * conditionMultiplier, maxHealth);
            }

            if (Interface.CallHook("OnConstructionPlace", baseEntity, component, placement, ownerPlayer) != null)
            {
                if (baseEntity.IsValid())
                    baseEntity.KillMessage();
                else
                    GameManager.Destroy(baseEntity, 0f);

                return null;
            }

            baseEntity.OnPlaced(ownerPlayer);
            baseEntity.OwnerID = ownerPlayer.userID;
            baseEntity.Spawn();

            StabilityEntity stabilityEntity = baseEntity as StabilityEntity;
            if (stabilityEntity != null)
                stabilityEntity.UpdateSurroundingEntities();

            // Return the GameObject of the entity that was created.return baseEntity.gameObject;
        }

        #endregion Oxide Hooks

        #region Harmony Patches

        [AutoPatch]
        [HarmonyPatch(typeof(Planner), "DoPlacement")]
        public static class DoPlacement_Patch
        {
            public static bool Prefix(Planner __instance, Construction.Target placement, Construction component, ref GameObject __result)
            {
                object hookResult = Interface.CallHook("OnCustomConstructionPlace", __instance, placement, component);

                if (hookResult is GameObject)
                {
                    // If the hook returned a GameObject, use it as the result and skip the original method.__result = (GameObject)hookResult;
                    return false;
                }

                // Otherwise let the original method run.return true;
            }
        }

        #endregion Harmony Patches
    }
}

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