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

FREE AntiRaidNight : 1.6.0 1.6.0

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

namespace Oxide.Plugins
{
    [Info("AntiRaidNight", "Sergioklv", "1.6.0")]
    [Description("Снижает урон по структурам ночью, в зависимости от владельца")]

    public class AntiRaidNight : RustPlugin
    {
        private readonly TimeSpan StartTime = new TimeSpan(22, 0, 0);
        private readonly TimeSpan EndTime = new TimeSpan(7, 0, 0);

        private const string VIPPermission = "antiraidnight.vip";

        private Dictionary<ulong, float> nextNotifyTime = new Dictionary<ulong, float>();
        private bool raidProtectionWasActive = false;

		private bool IsRaidProtectionActive()
		{
			TimeSpan now = DateTime.UtcNow.TimeOfDay; // UTC+3 para Moscú
			if (StartTime < EndTime)
				return now >= StartTime && now < EndTime;
			else
				return now >= StartTime || now < EndTime;
		}

        private void Init()
        {
            permission.RegisterPermission(VIPPermission, this);
        }

        private void OnServerInitialized()
        {
            raidProtectionWasActive = IsRaidProtectionActive();
            timer.Every(60f, CheckNightState);

            if (raidProtectionWasActive)
            {
                Puts("Ночная защита активна при запуске сервера.");
            }
        }

        private void CheckNightState()
        {
            bool isActive = IsRaidProtectionActive();

            if (isActive && !raidProtectionWasActive)
            {
                Server.Broadcast($"Ночная защита активирована! Блокировка действует с <color=#cc3333>22:00</color> до <color=#cc3333>07:00</color>.");
                raidProtectionWasActive = true;
            }
            else if (!isActive && raidProtectionWasActive)
            {
                Server.Broadcast($"Ночная защита завершена! Блокировка действовала с <color=#cc3333>22:00</color> до <color=#cc3333>07:00</color>.");
                raidProtectionWasActive = false;
            }
        }

        object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
            if (!IsRaidProtectionActive()) return null;
            if (entity == null || info == null || info.InitiatorPlayer == null) return null;
            BasePlayer attacker = info.InitiatorPlayer;
            if (attacker == null || attacker.IsNpc) return null;

            ulong ownerId = entity.OwnerID;
            if (ownerId == 0) return null;

            float protection = permission.UserHasPermission(ownerId.ToString(), VIPPermission) ? 0.7f : 0.3f;
            float damageMultiplier = 1f - protection;

            info.damageTypes.ScaleAll(damageMultiplier);

            if (!nextNotifyTime.ContainsKey(attacker.userID) || Time.realtimeSinceStartup >= nextNotifyTime[attacker.userID])
            {
                attacker.ChatMessage($"⚠ Защита <color=#cc3333>{protection * 100}%</color>. Вы наносите уменьшенный урон. Ночная защита: <color=#cc3333>22:00</color> – <color=#cc3333>07:00</color>.");
                nextNotifyTime[attacker.userID] = Time.realtimeSinceStartup + 15f;
            }

            return null;
        }
    }
}

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