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

FREE HomeProtection : 0.2.0 0.2.0

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
/*
TODO:
- Add option to enable/disable cupboard protection
- Add option to enable/disable protection when away
- Add option to enable/disable protection when offline
- Fix RaidTimer to actually work
*/

using System;
using System.Collections.Generic;

namespace Oxide.Plugins
{
    [Info("HomeProtection", "Wulf/lukespragg", "0.2.0", ResourceId = 1391)]
    [Description("Protects you and your home from intruders.")]

    class HomeProtection : RustPlugin
    {
        // Do NOT edit this file, instead edit HomeProtection.json in server/<identity>/oxide/config

        #region Configuration

        bool adminOnly;
        int RaidTimer;

        protected override void LoadDefaultConfig()
        {
            Config["AdminOnly"] = adminOnly = GetConfig("AdminOnly", false);
            Config["RaidTimer"] = RaidTimer = GetConfig("RaidTimer", 0);

            SaveConfig();
        }

        void Loaded() => LoadDefaultConfig();

        #endregion

        #region Raid Timer

        class Raidable
        {
            public BaseEntity Entity;
            public bool IsRaidable;
        }

        Dictionary<BaseEntity, Timer> raidTimer = new Dictionary<BaseEntity, Timer>();

        void OnEntityEnter(TriggerBase trigger, BaseEntity entity)
        {
            if (!(entity is BasePlayer) || !(trigger is BuildPrivilegeTrigger)) return;

            timer.Once(RaidTimer, () => Raidable[entity]);
        }

        #endregion

        #region Damage Blocking

        object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
            if ((entity is BuildingBlock) && (info.Initiator is BasePlayer))
            {
                var attacker = info.Initiator.ToPlayer();

                if (adminOnly && !attacker.IsAdmin()) return true;
                if (RaidTimer > 0 && !IsRaidable) return true;
                if (!attacker.CanBuild()) return true;
            }

            if ((entity is BasePlayer))
            {
                var player = entity.ToPlayer();

                if (adminOnly && !player.IsAdmin()) return true;
                if (RaidTimer > 0 && !IsRaidable) return true;
                if (!player.CanBuild()) return true;
            }

            return null;
        }

        #endregion

        #region Helpers

        T GetConfig<T>(string name, T defaultValue)
        {
            if (Config[name] == null) return defaultValue;
            return (T) Convert.ChangeType(Config[name], typeof(T));
        }

        #endregion
    }
}

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