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

FREE PlayerRanks : 1.1.4 1.1.4

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
 // Reference: Oxide.Core.MySql
using System.Collections.Generic;
using System;
using System.Text;
using UnityEngine;
using Oxide.Core.Plugins;
using Oxide.Core;
using Oxide.Core.Database;
using Oxide.Core.Configuration;
using System.Linq;
using Oxide.Game.Rust.Cui;
using Newtonsoft.Json;
namespace Oxide.Plugins {
    [Info("PlayerRanks", "Steenamaroo", "1.1.4", ResourceId = 2359)]
    class PlayerRanks : RustPlugin {
        [PluginReference]
        Plugin Clans, Friends, EventManager;
        private Dictionary<uint, Dictionary<ulong, int>> HeliAttackers = new Dictionary<uint, Dictionary<ulong, int>>();
        private Dictionary<ulong, WoundedData> woundedData = new Dictionary<ulong, WoundedData>();
        const string permAllowed = "playerranks.allowed";
        bool HasPermission(string id, string perm) => permission.UserHasPermission(id, perm);
        class DataStorage {
            public Dictionary<ulong, PRDATA> PlayerRankData = new Dictionary<ulong, PRDATA>();
            public DataStorage() {
            }
        }
        class PRDATA {
            public bool Admin;
            public ulong UserID;
            public string Name;
            public int PVPKills = 0;
            public double PVPDistance = 0.0;
            public int PVEKills = 0;
            public double PVEDistance = 0.0;
            public int Deaths = 0;
            public int BarrelsDestroyed = 0;
            public int HeliHits = 0;
            public int HeliKills = 0;
            public int Suicides = 0;
            public int TimesWounded = 0;
            public int ExplosivesThrown = 0;
            public int ArrowsFired = 0;
            public int BulletsFired = 0;
            public int TurretsDestroyed = 0;
            public int SleepersKilled = 0;
            public int NPCsKilled = 0;
            public int RocketsLaunched = 0;
            public int TimesHealed = 0;
            public double KDR = 0.0;
            public double SDR = 0.0;
            //intense options
            public int StructuresBuilt = 0;
            public int ItemsDeployed = 0;
            public int ItemsCrafted = 0;
            public int EntitiesRepaired = 0;
            public int StructuresDemolished = 0;
            public int ResourcesGathered = 0;
            public int StructuresUpgraded = 0;
        }
        class WoundedData {
            public float distance;
            public ulong attackerId;
        }
        DataStorage data;
        private DynamicConfigFile PRData;
        void OnServerInitialized() {
            lang.RegisterMessages(messages, this);
            PRData = Interface.Oxide.DataFileSystem.GetFile("PlayerRanks");
            LoadData();
            LoadVariables();
            cmd.AddChatCommand($"{chatCommandAlias}", this, "cmdTarget");
            CheckDependencies();
            if (useTimedTopList) {
                timer.Once(TimedTopListTimer * 60, () => pvpkills());
            }
            foreach(BasePlayer player in BasePlayer.activePlayerList) {
                OnPlayerInit(player);
            }
            timer.Once(saveTimer * 60, () => SaveTrigger());
            if (useMySQL) {
                LoadMySQL();
            }
        }
        private void CheckDependencies() {
            if (Friends == null) {
                if (useFriendsAPI) {
                    PrintWarning($"FriendsAPI could not be found! Disabling friends feature");
                    useFriendsAPI = false;
                }
            }
            if (Clans == null) {
                if (useClans) {
                    PrintWarning($"Clans could not be found! Disabling clans feature");
                    useClans = false;
                }
            }
        }
        protected override void LoadDefaultConfig() {
            Puts("Creating a new config file");
            Config.Clear();
            LoadVariables();
        }
        void OnPlayerInit(BasePlayer player) {
            topsOpen = false;
            BindKeys(player);
            if (!data.PlayerRankData.ContainsKey(player.userID)) {
                data.PlayerRankData.Add(player.userID, new PRDATA() {
                    Admin = false, UserID = player.userID, Name = player.displayName, PVPKills = 0, PVPDistance = 0.0, PVEKills = 0, PVEDistance = 0.0, Deaths = 0, BarrelsDestroyed = 0, HeliHits = 0, HeliKills = 0, Suicides = 0, TimesWounded = 0, TimesHealed = 0, ArrowsFired = 0, BulletsFired = 0, TurretsDestroyed = 0, SleepersKilled = 0, NPCsKilled = 0, RocketsLaunched = 0, ExplosivesThrown = 0, KDR = 0, SDR = 0,  //intense options
                    StructuresBuilt = 0, ItemsDeployed = 0, ItemsCrafted = 0, EntitiesRepaired = 0, StructuresDemolished = 0, ResourcesGathered = 0, StructuresUpgraded = 0,
                }
                );
            }
            else {
                data.PlayerRankData[player.userID].Name = player.displayName;
            }
            if (isAuth(player)) {
                data.PlayerRankData[player.userID].Admin = true;
            }
        }
        void OnEntityDeath(BaseEntity entity, HitInfo hitinfo, HitInfo info) {
            var victim = entity as BasePlayer;
            if (hitinfo?.Initiator == null && entity is BasePlayer) {
                if (woundedData.ContainsKey(victim.userID)) {
                    BasePlayer attacker = BasePlayer.FindByID(woundedData[victim.userID].attackerId);
                    var distance = woundedData[victim.userID].distance;
                    if (!victim.userID.IsSteamId()) {
                        if (attacker != null) {
                            if (data.PlayerRankData.ContainsKey(attacker.userID)) data.PlayerRankData[attacker.userID].NPCsKilled++;
                            if (distance > data.PlayerRankData[attacker.userID].PVEDistance) data.PlayerRankData[attacker.userID].PVEDistance = Math.Round(distance, 2);
                        }
                        woundedData.Remove(victim.userID);
                        return;
                    }
                    if (victim.userID.IsSteamId()) {
                        ProcessDeath((BasePlayer)victim);
                        if (attacker != null) {
                            if (data.PlayerRankData.ContainsKey(attacker.userID)) data.PlayerRankData[attacker.userID].PVPKills++;
                            if (distance > data.PlayerRankData[attacker.userID].PVPDistance) data.PlayerRankData[attacker.userID].PVPDistance = Math.Round(distance, 2);
                        }
                        woundedData.Remove(victim.userID);
                        return;
                    }
                }
                String [] stringArray = {
                    "Cold", "Drowned", "Heat", "Suicide", "Generic", "Posion", "Radiation", "Thirst", "Hunger", "Fall"
                }
                ;
                if (stringArray.Any(victim.lastDamage.ToString().Contains)) {
                    ProcessDeath((BasePlayer)victim);
                    ProcessSuicide((BasePlayer)victim);
                    return;
                }
                else {
                    ProcessDeath((BasePlayer)victim);
                }
                return;
            }
            if (entity is BaseHelicopter) {
                BasePlayer player = null;
                player = BasePlayer.FindByID(GetMajorityAttacker(entity.net.ID));
                ProcessHeliKills((BasePlayer)player);
                HeliAttackers.Remove(entity.net.ID);
                return;
            }
            if (hitinfo?.Initiator is BasePlayer) {
                var attacker = hitinfo.Initiator as BasePlayer;
                if (entity.name.Contains("agents/")) {
                    if (attacker.userID.IsSteamId()) {
                        ProcessPVEKills((BasePlayer)hitinfo.Initiator, (BaseEntity)entity);
                        return;
                    }
                    return;
                }
                if (entity.name.Contains("barrel") && attacker.userID.IsSteamId()) {
                    ProcessBarrelsDestroyed((BasePlayer)hitinfo.Initiator, (BaseEntity)entity);
                    return;
                }
                if (entity.name.Contains("turret") && attacker.userID.IsSteamId()) {
                    var player = hitinfo.Initiator.ToPlayer();
                    ProcessTurretsDestroyed((BasePlayer)player);
                    return;
                }
                if (!attacker.userID.IsSteamId() && entity is BasePlayer && victim.userID.IsSteamId()) {
                    ProcessDeath((BasePlayer)entity);
                    return;
                }
                if (victim is BasePlayer && !victim.userID.IsSteamId() && attacker.userID.IsSteamId()) {
                    ProcessNPCsKilled((BasePlayer)hitinfo.Initiator, (BaseEntity)entity);
                    return;
                }
                if (entity is BasePlayer && victim.userID.IsSteamId()) {
                    ProcessDeath((BasePlayer)entity);
                    if (hitinfo.Initiator != entity) ProcessKill((BasePlayer)hitinfo.Initiator, (BasePlayer)entity);
                    if (victim.IsSleeping()) ProcessSleepersKilled((BasePlayer)attacker, (BasePlayer)victim);
                    if (hitinfo.Initiator == entity) ProcessSuicide((BasePlayer)hitinfo.Initiator);
                    return;
                }
            }
            if (victim is BasePlayer && victim.userID.IsSteamId()) {
                ProcessDeath((BasePlayer)victim);
                return;
            }
        }
        void OnExplosiveThrown(BasePlayer player, BaseEntity entity, Item item) {
            if (player.userID.IsSteamId() && player is BasePlayer) {
                if (!(player.GetActiveItem().info.displayName.english == "Supply Signal")) {
                    ProcessExplosivesThrown((BasePlayer)player);
                }
            }
        }
        void OnWeaponFired(BaseProjectile projectile, BasePlayer player, ItemModProjectile mod) {
            if (mod.ToString().Contains("arrow")) ProcessArrowsFired((BasePlayer)player);
            if (mod.ToString().Contains("ammo")) ProcessBulletsFired((BasePlayer)player);
        }
        void OnRocketLaunched(BasePlayer player) {
            ProcessRocketsLaunched((BasePlayer)player);
        }
        void OnEntityBuilt(Planner plan, GameObject objectBlock) {
            if (useIntenseOptions) {
                BasePlayer player = plan.GetOwnerPlayer();
                if (player.GetActiveItem().info.displayName.english == "Building Plan") {
                    ProcessStructuresBuilt((BasePlayer)player);
                    return;
                }
                ProcessItemsDeployed((BasePlayer)player);
                return;
            }
        }
        void OnStructureDemolish(BaseCombatEntity entity, BasePlayer player) {
            ProcessStructuresDemolished((BasePlayer)player);
            return;
        }
        void OnItemCraft(ItemCraftTask item) {
            if (useIntenseOptions) {
                BasePlayer crafter = item.owner;
                ProcessItemsCrafted((BasePlayer)crafter);
                return;
            }
        }
        void OnStructureRepair(BaseCombatEntity entity, BasePlayer player) {
            if (useIntenseOptions) {
                ProcessEntitiesRepaired((BasePlayer)player);
                return;
            }
        }
        void OnHealingItemUse(HeldEntity item, BasePlayer target) {
            ProcessTimesHealed((BasePlayer)target);
            return;
        }
        void OnItemUse(Item item) {
            BasePlayer player = item?.GetOwnerPlayer();
            if (item.info.displayName.english == "Large Medkit" && player == null) {
                return;
            }
            if (item.info.displayName.english == "Large Medkit") {
                ProcessTimesHealed((BasePlayer)player);
                return;
            }
        }
        void CanBeWounded(BasePlayer player, HitInfo hitInfo) {
            if (player == null || hitInfo == null) return;
            var attacker = hitInfo.InitiatorPlayer;
            if (attacker != null) {
                if (attacker == player || IsFriend(attacker.userID, player.userID) || IsClanmate(attacker.userID, player.userID)) return;
                woundedData[player.userID] = new WoundedData {
                    distance = Vector3.Distance(player.transform.position, attacker.transform.position), attackerId = attacker.userID
                }
                ;
                {
                    NextTick(() => {
                        if (player.IsWounded()) {
                            ProcessTimesWounded((BasePlayer)player);
                        }
                    }
                    );
                }
            }
        }
        void OnPlayerRecover(BasePlayer player) {
            if (woundedData.ContainsKey(player.userID)) woundedData.Remove(player.userID);
        }
        void OnStructureUpgrade(BaseCombatEntity entity, BasePlayer player, BuildingGrade.Enum grade) {
            ProcessStructuresUpgraded((BasePlayer)player);
        }
        void OnEntityTakeDamage(BaseEntity entity, HitInfo hitinfo) {
            if (hitinfo?.Initiator is BasePlayer && entity is BaseHelicopter) {
                var heli = entity.GetComponent<BaseHelicopter>();
                var player = hitinfo.Initiator.ToPlayer();
                NextTick(() => {
                    if (heli == null) return;
                    if (!HeliAttackers.ContainsKey(heli.net.ID)) HeliAttackers.Add(heli.net.ID, new Dictionary<ulong, int>());
                    if (!HeliAttackers[heli.net.ID].ContainsKey(player.userID)) HeliAttackers[heli.net.ID].Add(player.userID, 1);
                    else {
                        HeliAttackers[heli.net.ID][player.userID]++;
                        ProcessHeliHits((BasePlayer)player, (BaseEntity)entity);
                        GetMajorityAttacker(heli.net.ID);
                    }
                }
                );
            }
        }
        private ulong GetMajorityAttacker(uint id) {
            ulong majorityPlayer = 0U;
            if (HeliAttackers.ContainsKey(id)) {
                Dictionary<ulong, int> majority = HeliAttackers[id].OrderByDescending(pair => pair.Value).Take(1).ToDictionary(pair => pair.Key, pair => pair.Value);
                foreach (var name in majority) {
                    majorityPlayer = name.Key;
                }
            }
            return majorityPlayer;
        }
        void OnCollectiblePickup(Item item, BasePlayer player) {
            if (useIntenseOptions) ProcessResourcesGathered((BasePlayer)player, item.amount);
        }
        void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) {
            if (useIntenseOptions) {
                BasePlayer player = entity?.ToPlayer();
                ProcessResourcesGathered(player, item.amount);
            }
        }
        void Unload() {
            SaveData();
        }
#region processes
        private void ProcessKill(BasePlayer player, BasePlayer victim) {
            if (useClans) if (victim != null) if (IsClanmate(player.userID, victim.userID)) return;
            if (useFriendsAPI) if (victim != null) if (IsFriend(player.userID, victim.userID)) return;
            if (blockEvents) {
                object isPlaying = EventManager?.Call("isPlaying", new object[] {
                    player
                }
                );
                if (isPlaying is bool) if ((bool)isPlaying) return;
            }
            if (data.PlayerRankData.ContainsKey(player.userID)) {
                data.PlayerRankData[player.userID].PVPKills++;
                if (victim.Distance(player.transform.position) > data.PlayerRankData[player.userID].PVPDistance) data.PlayerRankData[player.userID].PVPDistance = Math.Round(victim.Distance(player.transform.position), 2);
                if ((data.PlayerRankData[player.userID].Deaths) > 0) {
                    var KDR = System.Convert.ToDouble(data.PlayerRankData[player.userID].PVPKills) / (data.PlayerRankData[player.userID].Deaths);
                    data.PlayerRankData[player.userID].KDR = Math.Round(KDR, 2);
                }
                else {
                    data.PlayerRankData[player.userID].KDR = (data.PlayerRankData[player.userID].PVPKills);
                }
            }
        }
        private void ProcessPVEKills(BasePlayer player, BaseEntity victim) {
            if (data.PlayerRankData.ContainsKey(player.userID)) {
                data.PlayerRankData[player.userID].PVEKills++;
                if (victim.Distance(player.transform.position) > data.PlayerRankData[player.userID].PVEDistance) {
                    data.PlayerRankData[player.userID].PVEDistance = Math.Round(victim.Distance(player.transform.position), 2);
                }
            }
        }
        private void ProcessDeath(BasePlayer player) {
            if (blockEvents) {
                object isPlaying = EventManager?.Call("isPlaying", new object[] {
                    player
                }
                );
                if (isPlaying is bool) if ((bool)isPlaying) return;
            }
            if (data.PlayerRankData.ContainsKey(player.userID)) {
                data.PlayerRankData[player.userID].Deaths++;
                var SDR = System.Convert.ToDouble(data.PlayerRankData[player.userID].Suicides) / (data.PlayerRankData[player.userID].Deaths);
                data.PlayerRankData[player.userID].SDR = Math.Round(SDR, 2);
                var KDR = System.Convert.ToDouble(data.PlayerRankData[player.userID].PVPKills) / (data.PlayerRankData[player.userID].Deaths);
                data.PlayerRankData[player.userID].KDR = Math.Round(KDR, 2);
            }
        }
        private void ProcessBarrelsDestroyed(BasePlayer player, BaseEntity victim) {
            if (blockEvents) {
                object isPlaying = EventManager?.Call("isPlaying", new object[] {
                    player
                }
                );
                if (isPlaying is bool) if ((bool)isPlaying) return;
            }
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].BarrelsDestroyed++;
        }
        private void ProcessHeliHits(BasePlayer player, BaseEntity victim) {
            if (blockEvents) {
                object isPlaying = EventManager?.Call("isPlaying", new object[] {
                    player
                }
                );
                if (isPlaying is bool) if ((bool)isPlaying) return;
            }
            if (data.PlayerRankData.ContainsKey(player.userID)) {
                data.PlayerRankData[player.userID].HeliHits++;
            }
        }
        private void ProcessHeliKills(BasePlayer player) {
            if (blockEvents) {
                object isPlaying = EventManager?.Call("isPlaying", new object[] {
                    player
                }
                );
                if (isPlaying is bool) if ((bool)isPlaying) return;
            }
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].HeliKills++;
        }
        private void ProcessSuicide(BasePlayer player) {
            if (blockEvents) {
                object isPlaying = EventManager?.Call("isPlaying", new object[] {
                    player
                }
                );
                if (isPlaying is bool) if ((bool)isPlaying) return;
            }
            if (data.PlayerRankData.ContainsKey(player.userID)) {
                data.PlayerRankData[player.userID].Suicides++;
                if ((data.PlayerRankData[player.userID].Deaths) > 0) {
                    var SDR = System.Convert.ToDouble(data.PlayerRankData[player.userID].Suicides) / (data.PlayerRankData[player.userID].Deaths);
                    data.PlayerRankData[player.userID].SDR = Math.Round(SDR, 2);
                }
                else {
                    data.PlayerRankData[player.userID].SDR = (data.PlayerRankData[player.userID].Suicides);
                }
                if ((data.PlayerRankData[player.userID].Deaths) > 0) {
                    var KDR = System.Convert.ToDouble(data.PlayerRankData[player.userID].PVPKills) / (data.PlayerRankData[player.userID].Deaths);
                    data.PlayerRankData[player.userID].KDR = Math.Round(KDR, 2);
                }
                else {
                    data.PlayerRankData[player.userID].KDR = (data.PlayerRankData[player.userID].PVPKills);
                }
            }
        }
        private void ProcessTimesWounded(BasePlayer player) {
            if (blockEvents) {
                object isPlaying = EventManager?.Call("isPlaying", new object[] {
                    player
                }
                );
                if (isPlaying is bool) if ((bool)isPlaying) return;
            }
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].TimesWounded++;
        }
        private void ProcessExplosivesThrown(BasePlayer player) {
            if (blockEvents) {
                object isPlaying = EventManager?.Call("isPlaying", new object[] {
                    player
                }
                );
                if (isPlaying is bool) if ((bool)isPlaying) return;
            }
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].ExplosivesThrown++;
        }
        private void ProcessArrowsFired(BasePlayer player) {
            if (blockEvents) {
                object isPlaying = EventManager?.Call("isPlaying", new object[] {
                    player
                }
                );
                if (isPlaying is bool) if ((bool)isPlaying) return;
            }
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].ArrowsFired++;
        }
        private void ProcessBulletsFired(BasePlayer player) {
            if (blockEvents) {
                object isPlaying = EventManager?.Call("isPlaying", new object[] {
                    player
                }
                );
                if (isPlaying is bool) if ((bool)isPlaying) return;
            }
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].BulletsFired++;
        }
        private void ProcessTurretsDestroyed(BasePlayer player) {
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].TurretsDestroyed++;
        }
        private void ProcessSleepersKilled(BasePlayer player, BaseEntity victim) {
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].SleepersKilled++;
            if (victim.Distance(player.transform.position) > data.PlayerRankData[player.userID].PVPDistance) data.PlayerRankData[player.userID].PVPDistance = Math.Round(victim.Distance(player.transform.position), 2);
        }
        private void ProcessNPCsKilled(BasePlayer player, BaseEntity victim) {
            if (data.PlayerRankData.ContainsKey(player.userID)) {
                data.PlayerRankData[player.userID].NPCsKilled++;
            }
            if (victim.Distance(player.transform.position) > data.PlayerRankData[player.userID].PVEDistance) data.PlayerRankData[player.userID].PVEDistance = Math.Round(victim.Distance(player.transform.position), 2);
        }
        private void ProcessStructuresBuilt(BasePlayer player) {
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].StructuresBuilt++;
        }
        private void ProcessStructuresDemolished(BasePlayer player) {
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].StructuresDemolished++;
        }
        private void ProcessItemsDeployed(BasePlayer player) {
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].ItemsDeployed++;
        }
        private void ProcessItemsCrafted(BasePlayer player) {
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].ItemsCrafted++;
        }
        private void ProcessEntitiesRepaired(BasePlayer player) {
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].EntitiesRepaired++;
        }
        private void ProcessRocketsLaunched(BasePlayer player) {
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].RocketsLaunched++;
        }
        private void ProcessTimesHealed(BasePlayer player) {
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].TimesHealed++;
        }
        private void ProcessResourcesGathered(BasePlayer player, int amount = 0) {
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].ResourcesGathered+=amount;
        }
        private void ProcessStructuresUpgraded(BasePlayer player) {
            if (data.PlayerRankData.ContainsKey(player.userID)) data.PlayerRankData[player.userID].StructuresUpgraded++;
        }
        private void BroadcastToAll(string msg, string keyword) => PrintToChat(fontColor1 + keyword + " </color>" + fontColor2 + msg + "</color>");
        private void BroadcastToPlayer(BasePlayer player, string msg, string keyword) => SendReply(player, fontColor1 + keyword + " </color>" + fontColor2 + msg + "</color>");
        private bool IsClanmate(ulong playerId, ulong friendId) {
            if (!Clans || !useClans) return false;
            object playerTag = Clans?.Call("GetClanOf", playerId);
            object friendTag = Clans?.Call("GetClanOf", friendId);
            if (playerTag is string && friendTag is string) if (playerTag == friendTag) return true;
            return false;
        }
        private bool IsFriend(ulong playerID, ulong friendID) {
            if (!Friends || !useFriendsAPI) return false;
            bool isFriend = (bool)Friends?.Call("IsFriend", playerID, friendID);
            return isFriend;
        }
#endregion
        void Unloaded() {
            foreach (BasePlayer current in BasePlayer.activePlayerList) {
                current.Command($"bind {topsKeyBind} \"\"");
                CuiHelper.DestroyUi(current, "ranksgui");
                topsOpen = false;
            }
        }
        void OnPlayerDisconnected(BasePlayer player, string reason) {
            if (isAuth(player)) {
                data.PlayerRankData[player.userID].Admin = true;
            }
            player.Command($"bind {topsKeyBind} \"\"");
            CuiHelper.DestroyUi(player, "ranksgui");
            topsOpen = false;
        }
        void UseUI(BasePlayer player, string msg, string msg1) {
            string guiString = String.Format("0.1 0.1 0.1 {0}", guitransparency);
            var elements = new CuiElementContainer();
            var mainName = elements.Add(new CuiPanel {
                Image = {
                    Color = guiString
                }
                , RectTransform = {
                    AnchorMin = "0.3 0.1", AnchorMax = "0.7 0.9"
                }
                , CursorEnabled = true
            }
            , "Overlay", "ranksgui");
            elements.Add(new CuiElement {
                Parent = "ranksgui", Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0 0", AnchorMax = "1 1"
                    }
                }
            }
            );
            var Close = new CuiButton {
                Button = {
                    Command = "ToggleTops", Color = closeColor
                }
                , RectTransform = {
                    AnchorMin = "0.4 0.02", AnchorMax = "0.6 0.082"
                }
                , Text = {
                    Text = "Close", FontSize = 22, Align = TextAnchor.MiddleCenter
                }
            }
            ;
            elements.Add(new CuiLabel {
                Text = {
                    Text = msg1, FontSize = 26, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.9", AnchorMax = "1 0.98"
                }
            }
            , mainName);
            elements.Add(new CuiLabel {
                Text = {
                    Text = msg, FontSize = 14, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.10", AnchorMax = "1 0.9"
                }
            }
            , mainName);
            elements.Add(Close, mainName);
            CuiHelper.AddUi(player, elements);
        }
        void BindKeys(BasePlayer player, bool unbind = false) {
            if (unbind) player.Command($"bind {topsKeyBind} \"\"");
            else player.Command($"bind {topsKeyBind} \"ToggleTops\"");
        }
        public string RemoveSpecialCharacters(string str) {
            StringBuilder sb = new StringBuilder(str);
            sb.Replace('{', '[');
            sb.Replace('}', ']');
            sb.Replace("'", ",");
            return sb.ToString();
        }
        [ConsoleCommand("ToggleTops")]
        private void cmdToggleTops(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) return;
            player.Command("chat.say", "/pr tops");
        }
#region chat commands
        [ChatCommand("pr")]
        void cmdTarget(BasePlayer player, string command, string[] args) {
            if (args == null || args.Length == 0) {
                BroadcastToPlayer(player, fontColor2 + lang.GetMessage("prtop", this, player.UserIDString) + " : </color>" + fontColor3 + lang.GetMessage("prtop2", this, player.UserIDString) + "</color>", fontColor1 + lang.GetMessage("title", this, player.UserIDString) + "\n </color>");
                return;
            }
            var d = data.PlayerRankData[player.userID];
            switch (args[0].ToLower()) {
                case "tops" :  //string msg1 = string.Format(fontColor1 + lang.GetMessage("title", this, player.UserIDString) + "</color>" + fontColor2 + "{0}" + "</color> \n", d.Name);
                string msg1 = string.Format(fontColor1 + lang.GetMessage("title", this, player.UserIDString) + "</color>" + fontColor2 + "{0}" + "</color> \n", d.Name);
                string topsMsgGUI = string.Format(string.Format(""));
                if(usepvpkills)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("PVPKills", this, player.UserIDString)+ ": </color>" + fontColor1 + "{0}", d.PVPKills), 1.0) + "</color> \n";
                if(usepvpdistance)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("PVPDistance", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.PVPDistance), 1.0) + "</color> \n";
                if(usepvekills)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("PVEKills", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.PVEKills), 1.0) + "</color> \n";
                if(usepvedistance)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("PVEDistance", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.PVEDistance), 1.0) + "</color> \n";
                if(usenpcskilled)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("NPCsKilled", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.NPCsKilled), 1.0) + "</color> \n";
                if(usedeaths)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("Deaths", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.Deaths), 1.0) + "</color> \n";
                if(usesuicides)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("Suicides", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.Suicides), 1.0) + "</color> \n";
                if(usetimeswounded)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("TimesWounded", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.TimesWounded), 1.0) + "</color> \n";
                if(usekdr)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("KDR", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.KDR), 1.0) + "</color> \n";
                if(usesdr)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("SDR", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.SDR), 1.0) + "</color> \n";
                if(usehelikills)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("HeliKills", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.HeliKills), 1.0) + "</color> \n";
                if(usehelihits)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("HeliHits", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.HeliHits), 1.0) + "</color> \n";
                if(usebarrelsdestroyed)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("BarrelsDestroyed", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.BarrelsDestroyed), 1.0) + "</color> \n";
                if(useexplosivesthrown)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("ExplosivesThrown", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.ExplosivesThrown), 1.0) + "</color> \n";
                if(usearrowsfired)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("ArrowsFired", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.ArrowsFired), 1.0) + "</color> \n";
                if(usebulletsfired)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("BulletsFired", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.BulletsFired), 1.0) + "</color> \n";
                if(useturretsdestroyed)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("TurretsDestroyed", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.TurretsDestroyed), 1.0) + "</color> \n";
                if(usesleeperskilled)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("SleepersKilled", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.SleepersKilled), 1.0) + "</color> \n";
                if(userocketslaunched)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("RocketsLaunched", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.RocketsLaunched), 1.0) + "</color> \n";
                if(usetimeshealed)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("TimesHealed", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.TimesHealed), 1.0) + "</color> \n";
                if(usestructuresbuilt)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("StructuresBuilt", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.StructuresBuilt), 1.0) + "</color> \n";
                if(useitemsdeployed)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("ItemsDeployed", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.ItemsDeployed), 1.0) + "</color> \n";
                if(useitemscrafted)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("ItemsCrafted", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.ItemsCrafted), 1.0) + "</color> \n";
                if(useentitiesrepaired)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("EntitiesRepaired", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.EntitiesRepaired), 1.0) + "</color> \n";
                if(usestructuresdemolished)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("StructuresDemolished", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.StructuresDemolished), 1.0) + "</color> \n";
                if(useresourcesgathered)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("ResourcesGathered", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.ResourcesGathered), 1.0) + "</color> \n";
                if(usestructuresupgraded)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("StructuresUpgraded", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.StructuresUpgraded), 1.0) + "</color> \n";
                if (topsOpen) {
                    CuiHelper.DestroyUi(player, "ranksgui");
                    topsOpen = false;
                    return;
                }
                else {
                    UseUI(player, topsMsgGUI.ToString(), msg1.ToString());
                    topsOpen = true;
                }
                return;
                case "pvpkills" : if (usepvpkills) {
                    var dictToUse = data.PlayerRankData;
                    int amount = PrivateTopListAmount;
                    if (allowadmin == false) {
                        dictToUse = data.PlayerRankData.Where(pair => pair.Value.Admin == false).ToDictionary(val => val.Key, val => val.Value);
                    }
                    Dictionary<string, int> top = dictToUse.OrderByDescending(pair => pair.Value.PVPKills).Take(amount).ToDictionary(pair => pair.Value.Name, pair => pair.Value.PVPKills);
                    top = top.Where(kvp => kvp.Value > 0).ToDictionary(x => x.Key, x => x.Value);
                    if (top.Count > 0) {
                        var outMsg = string.Format(fontColor1 + lang.GetMessage("title", this) + "</color>" + fontColor2 + lang.GetMessage("bestHits", this) + lang.GetMessage("PVPKills", this), 1.0) + "</color> \n";
                        foreach (var name in top) {
                            outMsg += string.Format(fontColor3 + "{0} : " + "</color>" + fontColor1 + "{1}" + "</color>" + "\n", name.Key, name.Value);
                        }
                        if (outMsg != "") SendReply(player, outMsg);
                    }
                }
                return;
                case "pvpdistance" : if (usepvpdistance) {
                    var dictToUse = data.PlayerRankData;
                    int amount = PrivateTopListAmount;
                    if (allowadmin == false) {
                        dictToUse = data.PlayerRankData.Where(pair => pair.Value.Admin == false).ToDictionary(val => val.Key, val => val.Value);
                    }
                    Dictionary<string, double> top = dictToUse.OrderByDescending(pair => pair.Value.PVPDistance).Take(amount).ToDictionary(pair => pair.Value.Name, pair => pair.Value.PVPDistance);
                    top = top.Where(kvp => kvp.Value > 0).ToDictionary(x => x.Key, x => x.Value);
                    if (top.Count > 0) {
                        var outMsg = string.Format(fontColor1 + lang.GetMessage("title", this) + "</color>" + fontColor2 + lang.GetMessage("bestHits", this) + lang.GetMessage("PVPDistance", this), 1.0) + "</color> \n";
                        foreach (var name in top) {
                            outMsg += string.Format(fontColor3 + "{0} : " + "</color>" + fontColor1 + "{1}" + "</color>" + "\n", name.Key, name.Value);
                        }
                        if (outMsg != "") SendReply(player, outMsg);
                    }
                }
                return;
                case "pvekills" : if (usepvekills) {
                    var dictToUse = data.PlayerRankData;
                    int amount = PrivateTopListAmount;
                    if (allowadmin == false) {
                        dictToUse = data.PlayerRankData.Where(pair => pair.Value.Admin == false).ToDictionary(val => val.Key, val => val.Value);
                    }
                    Dictionary<string, int> top = dictToUse.OrderByDescending(pair => pair.Value.PVEKills).Take(amount).ToDictionary(pair => pair.Value.Name, pair => pair.Value.PVEKills);
                    top = top.Where(kvp => kvp.Value > 0).ToDictionary(x => x.Key, x => x.Value);
                    if (top.Count > 0) {
                        var outMsg = string.Format(fontColor1 + lang.GetMessage("title", this) + "</color>" + fontColor2 + lang.GetMessage("bestHits", this) + lang.GetMessage("PVEKills", this), 1.0) + "</color> \n";
                        foreach (var name in top) {
                            outMsg += string.Format(fontColor3 + "{0} : " + "</color>" + fontColor1 + "{1}" + "</color>" + "\n", name.Key, name.Value);
                        }
                        if (outMsg != "") SendReply(player, outMsg);
                    }
                }
                return;
                case "pvedistance" : if (usepvedistance) {
                    var dictToUse = data.PlayerRankData;
                    int amount = PrivateTopListAmount;
                    if (allowadmin == false) {
                        dictToUse = data.PlayerRankData.Where(pair => pair.Value.Admin == false).ToDictionary(val => val.Key, val => val.Value);
                    }
                    Dictionary<string, double> top = dictToUse.OrderByDescending(pair => pair.Value.PVEDistance).Take(amount).ToDictionary(pair => pair.Value.Name, pair => pair.Value.PVEDistance);
                    top = top.Where(kvp => kvp.Value > 0).ToDictionary(x => x.Key, x => x.Value);
                    if (top.Count > 0) {
                        var outMsg = string.Format(fontColor1 + lang.GetMessage("title", this) + "</color>" + fontColor2 + lang.GetMessage("bestHits", this) + lang.GetMessage("PVEDistance", this), 1.0) + "</color> \n";
                        foreach (var name in top) {
                            outMsg += string.Format(fontColor3 + "{0} : " + "</color>" + fontColor1 + "{1}" + "</color>" + "\n", name.Key, name.Value);
                        }
                        if (outMsg != "") SendReply(player, outMsg);
                    }
                }
                return;
                case "deaths" : if (usedeaths) {
                    var dictToUse = data.PlayerRankData;
                    int amount = PrivateTopListAmount;
                    if (allowadmin == false) {
                        dictToUse = data.PlayerRankData.Where(pair => pair.Value.Admin == false).ToDictionary(val => val.Key, val => val.Value);
                    }
                    Dictionary<string, int> top = dictToUse.OrderByDescending(pair => pair.Value.Deaths).Take(amount).ToDictionary(pair => pair.Value.Name, pair => pair.Value.Deaths);
                    top = top.Where(kvp => kvp.Value > 0).ToDictionary(x => x.Key, x => x.Value);
                    if (top.Count > 0) {
                        var outMsg = string.Format(fontColor1 + lang.GetMessage("title", this) + "</color>" + fontColor2 + lang.GetMessage("bestHits", this) + lang.GetMessage("Deaths", this), 1.0) + "</color> \n";
                        foreach (var name in top) {
                            //outMsg += string.Format(fontColor3 + "{0} : " + "</color>" + fontColor1 + "{1}" + "</color>" + "\n", name.Key, name.Value); old string
                            outMsg += string.Format(fontColor3 + "{0} : " + "</color>" + fontColor1 + "{1}" + "</color>" + "\n", name.Key, name.Value);
                        }
                        if (outMsg != "") SendReply(player, outMsg);
                    }
                }
                return;
                case "barrelsdestroyed" : case "barrels" : if (usebarrelsdestroyed) {
                    var dictToUse = data.PlayerRankData;
                    int amount = PrivateTopListAmount;
                    if (allowadmin == false) {
                        dictToUse = data.PlayerRankData.Where(pair => pair.Value.Admin == false).ToDictionary(val => val.Key, val => val.Value);
                    }
                    Dictionary<string, int> top = dictToUse.OrderByDescending(pair => pair.Value.BarrelsDestroyed).Take(amount).ToDictionary(pair => pair.Value.Name, pair => pair.Value.BarrelsDestroyed);
                    top = top.Where(kvp => kvp.Value > 0).ToDictionary(x => x.Key, x => x.Value);
                    if (top.Count > 0) {
                        var outMsg = string.Format(fontColor1 + lang.GetMessage("title", this) + "</color>" + fontColor2 + lang.GetMessage("bestHits", this) + lang.GetMessage("BarrelsDestroyed", this), 1.0) + "</color> \n";
                        foreach (var name in top) {
                            outMsg += string.Format(fontColor3 + "{0} : " + "</color>" + fontColor1 + "{1}" + "</color>" + "\n", name.Key, name.Value);
                        }
                        if (outMsg != "") SendReply(player, outMsg);
                    }
                }
                return;
                case "helicopterhits" : case "helihits" : if (usehelihits) {
                    var dictToUse = data.PlayerRankData;
                    int amount = PrivateTopListAmount;
                    if (allowadmin == false) {
                        dictToUse = data.PlayerRankData.Where(pair => pair.Value.Admin == false).ToDictionary(val => val.Key, val => val.Value);
                    }
                    Dictionary<string, int> top = dictToUse.OrderByDescending(pair => pair.Value.HeliHits).Take(amount).ToDictionary(pair => pair.Value.Name, pair => pair.Value.HeliHits);
                    top = top.Where(kvp => kvp.Value > 0).ToDictionary(x => x.Key, x => x.Value);
                    if (top.Count > 0) {
                        var outMsg = string.Format(fontColor1 + lang.GetMessage("title", this) + "</color>" + fontColor2 + lang.GetMessage("bestHits", this) + lang.GetMessage("HeliHits", this), 1.0) + "</color> \n";
                        foreach (var name in top) {
                            outMsg += string.Format(fontColor3 + "{0} : " + "</color>" + fontColor1 + "{1}" + "</color>" + "\n", name.Key, name.Value);
                        }
                        if (outMsg != "") SendReply(player, outMsg);
                    }
                }
                return;
                case "helicopterkills" : case "helikills" : if (usehelikills) {
                    var dictToUse = data.PlayerRankData;
                    int amount = PrivateTopListAmount;
                    if (allowadmin == false) {
                        dictToUse = data.PlayerRankData.Where(pair => pair.Value.Admin == false).ToDictionary(val => val.Key, val => val.Value);
                    }
                    Dictionary<string, int> top = dictToUse.OrderByDescending(pair => pair.Value.HeliKills).Take(amount).ToDictionary(pair => pair.Value.Name, pair => pair.Value.HeliKills);
                    top = top.Where(kvp => kvp.Value > 0).ToDictionary(x => x.Key, x => x.Value);
                    if (top.Count > 0) {
                        var outMsg = string.Format(fontColor1 + lang.GetMessage("title", this) + "</color>" + fontColor2 + lang.GetMessage("bestHits", thi
// ... [Code preview truncated due to length. Full source in attached file] ...

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