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

FREE MolotovCooldown : 1.0.0 1.0.0

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

namespace Oxide.Plugins
{
    [Info("Molotov Cooldown", "sdapro", "1.0.0", ResourceId = 2806)]
    [Description("Add a cooldown to Molotovs to avoid players leaving out of rage.")]
    class MolotovCooldown : RustPlugin
    {
        private bool Changed;
        private bool refundMolotov;
        private int timeCooldown;
        private string cooldownPerm;
        private ulong messageIcon;
        private int authLevel;

        public List<ulong> molotovCooldown = new List<ulong>();
        public Dictionary<ulong, float> lastRun = new Dictionary<ulong, float>();

        string GetLang(string msg, string userID) => lang.GetMessage(msg, this, userID);

        protected override void LoadDefaultConfig()
        {
            Puts("Creating a new config file.");
            Config.Clear();
            LoadVariables();
        }
        private void LoadVariables()
        {
            refundMolotov = Convert.ToBoolean(GetConfig("Settings", "Refund molotov", true));
            timeCooldown = Convert.ToInt32(GetConfig("Settings", "Cooldown in seconds", 300));
            cooldownPerm = Convert.ToString(GetConfig("Settings", "Ignore cooldown permission", "molotovcooldown.ignore"));
            messageIcon = Convert.ToUInt64(GetConfig("Settings", "Icon for message", 0));
            authLevel = Convert.ToInt32(GetConfig("Settings", "Auth level admin commands", 1));

            if (!Changed) return;
            SaveConfig();
            Changed = false;
        }

        object GetConfig(string menu, string datavalue, object defaultValue)
        {
            var data = Config[menu] as Dictionary<string, object>;
            if (data == null)
            {
                data = new Dictionary<string, object>();
                Config[menu] = data;
                Changed = true;
            }
            object value;
            if (!data.TryGetValue(datavalue, out value))
            {
                value = defaultValue;
                data[datavalue] = value;
                Changed = true;
            }
            return value;
        }

        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["cooldownActive"] = "<color=#b7b7b7>Molotov cooldown active, wait {0} seconds till you can throw a Molotov again.</color>",
                ["cooldownOver"] = "<color=#b7b7b7>You are able to throw a Molotov again.</color>",
                ["noPermission"] = "<color=#b7b7b7>You don't have the required auth level to run this command.</color>",
                ["manualReset"] = "<color=#b7b7b7>All Molotov cooldowns have been manually reset.</color>"
            }, this);
        }

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

        public bool HasMolotovCooldown(ulong userId)
        {
            if (molotovCooldown.Contains(userId))
            {
                return true;
            }
            return false;
        }

        private void OnExplosiveDropped(BasePlayer player, BaseEntity entity) => OnExplosiveThrown(player, entity);

        private void OnExplosiveThrown(BasePlayer player, BaseEntity entity)
        {
            if (entity.ShortPrefabName != "grenade.molotov.deployed")
                return;
                            if (HasMolotovCooldown(player.userID))
            {
                float timeLeft = lastRun[player.userID] + timeCooldown - Time.realtimeSinceStartup;
                if (timeLeft > 0)
                {
                    player.ChatMessage(string.Format(GetLang("cooldownActive", player.UserIDString), Convert.ToInt32(timeLeft)));
                    if (refundMolotov)
                    {
                        player.GiveItem(ItemManager.CreateByName("grenade.molotov", 1));
                    }
                    entity.Kill();
                    return;
                }
                else
                {
                    molotovCooldown.Remove(player.userID);
                    lastRun[player.userID] = Time.realtimeSinceStartup;
                    player.ChatMessage(GetLang("cooldownOver", player.UserIDString));
                }
            }
            else
            {
                molotovCooldown.Add(player.userID);
                lastRun[player.userID] = Time.realtimeSinceStartup;
            }
        }

        [ChatCommand("molotovreset")]
        private void ResetCooldowns(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, cooldownPerm))
            {
                player.ChatMessage(GetLang("noPermission", player.UserIDString));
                return;
            }
            molotovCooldown.Clear();
            lastRun.Clear();
            player.ChatMessage(GetLang("manualReset", player.UserIDString));
        }
    }
}

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