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

FREE PlayerRanks : 1.3.4 1.3.4

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Rust;
using System.Collections.Generic;
using System;
using System.Text;
using UnityEngine;
using Oxide.Core;
using Oxide.Core.MySql;
using Oxide.Core.Plugins;
using Oxide.Core.Libraries;
using Oxide.Core.Database;
using Oxide.Core.Configuration;
using System.Linq;
using Oxide.Game.Rust.Cui;
using Newtonsoft.Json;
using System.Reflection;
namespace Oxide.Plugins {
    [Info("PlayerRanks", "Steenamaroo", "1.3.4", ResourceId = 2359)]
    class PlayerRanks : RustPlugin {
        [PluginReference]
        Plugin Clans, Friends, EventManager, PlaytimeTracker, Economics;
#region RustIO
        private Library lib;
        private MethodInfo isInstalled;
        private MethodInfo hasFriend;
        private bool IsInstalled() {
            if (lib == null) return false;
            return (bool)isInstalled.Invoke(lib, new object[] {
            }
            );
        }
        private bool HasFriend(string playerId, string friendId) {
            if (lib == null) return false;
            return (bool)hasFriend.Invoke(lib, new object[] {
                playerId, friendId
            }
            );
        }
#endregion
        private Dictionary<uint, Dictionary<ulong, int>> HeliAttackers = new Dictionary<uint, Dictionary<ulong, int>>();
        private Dictionary<uint, Dictionary<ulong, float>> BradleyAttackers = new Dictionary<uint, Dictionary<ulong, float>>();
        private Dictionary<ulong, WoundedData> woundedData = new Dictionary<ulong, WoundedData>();
        private List<ulong> airdrops = new List<ulong>();
        const string permAllowed = "playerranks.allowed";
        bool HasPermission(string id, string perm) => permission.UserHasPermission(id, perm);
        List<ulong> MenuOpen = new List<ulong>();
        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 string TimePlayed = "0";
            public string Status = "offline";
            public int Economics = 0;
            public int Recent = 0;
            public int PVPKills = 0;
            public double PVPDistance = 0.0;
            public int PVEKills = 0;
            public double PVEDistance = 0.0;
            public int NPCKills = 0;
            public double NPCDistance = 0.0;
            public int Deaths = 0;
            public int BarrelsDestroyed = 0;
            public int HeliHits = 0;
            public int HeliKills = 0;
            public int APCHits = 0;
            public int APCKills = 0;
            public int Suicides = 0;
            public int TimesWounded = 0;
            public int ExplosivesThrown = 0;
            public int ArrowsFired = 0;
            public int BulletsFired = 0;
            public int WeaponTrapsDestroyed = 0;
            public int SleepersKilled = 0;
            public int RocketsLaunched = 0;
            public int TimesHealed = 0;
            public double KDR = 0.0;
            public double SDR = 0.0;
            public int DropsLooted = 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 Loaded() {
            lang.RegisterMessages(messages, this);
            permission.RegisterPermission(permAllowed, this);
            cmd.AddChatCommand($"{chatCommandAlias}", this, "cmdTarget");
        }
        void OnServerInitialized() {
            PRData = Interface.Oxide.DataFileSystem.GetFile("PlayerRanks");
            LoadData();
            LoadVariables();
            CheckDependencies();
            if (useTimedTopList) {
                timer.Once(TimedTopListTimer * 60, () => pvpkills());
            }
            foreach(var entry in data.PlayerRankData) {
                entry.Value.Status = "offline";
            }
            foreach(BasePlayer player in BasePlayer.activePlayerList) {
                OnPlayerInit(player);
            }
            timer.Every(saveTimer * 60, () => {
                SaveData();
                Puts("Player Ranks Local Database Was Saved.");
            }
            );
        }
        private void CheckDependencies() {
            if (Friends == null) {
                if (useFriendsAPI) {
                    PrintWarning($"FriendsAPI could not be found! Disabling friends feature");
                    useFriendsAPI = false;
                }
            }
            if (Clans == null) if (useClans) {
                Puts("{0}: {1}", Title, "Clans could not be found! Disabling clans feature.");
                useClans = false;
            }
            if (PlaytimeTracker == null) Puts("{0}: {1}", Title, "PlayTime Tracker is not installed.Please install it and reload.");
            if (Economics == null) Puts("{0}: {1}", Title, "Economics is not installed.Category will show 0 for all players.");
            lib = Interface.GetMod().GetLibrary<Library>("RustIO");
            if (lib == null || (isInstalled = lib.GetFunction("IsInstalled")) == null || (hasFriend = lib.GetFunction("HasFriend")) == null) {
                lib = null;
                Puts("{0}: {1}", Title, "Rust:IO is not installed.");
            }
        }
        protected override void LoadDefaultConfig() {
            Puts("Creating a new config file");
            Config.Clear();
            LoadVariables();
        }
        void OnPlayerInit(BasePlayer player) {
            if (MenuOpen.Contains(player.userID)) {
                MenuOpen.Remove(player.userID);
                CuiHelper.DestroyUi(player, "ranksgui");
            }
            int maxNum = 0;
            if (data.PlayerRankData.Count != 0) {
                maxNum = data.PlayerRankData.Max(recent => {
                    if (recent.Value != null) return recent.Value.Recent;
                    return 0;
                }
                );
            }
            if (!data.PlayerRankData.ContainsKey(player.userID)) {
                maxNum++;
                data.PlayerRankData.Add(player.userID, new PRDATA() {
                    Admin = false, UserID = player.userID, Name = player.displayName, TimePlayed = "0", Status = "online", Recent = maxNum, Economics = 0, PVPKills = 0, PVPDistance = 0.0, PVEKills = 0, PVEDistance = 0.0, NPCKills = 0, NPCDistance = 0.0, Deaths = 0, BarrelsDestroyed = 0, HeliHits = 0, HeliKills = 0, APCHits = 0, APCKills = 0, Suicides = 0, TimesWounded = 0, TimesHealed = 0, ArrowsFired = 0, BulletsFired = 0, WeaponTrapsDestroyed = 0, SleepersKilled = 0, RocketsLaunched = 0, ExplosivesThrown = 0, KDR = 0, SDR = 0, DropsLooted = 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;
                data.PlayerRankData[player.userID].Status = "online";
                if (Economics) {
                    data.PlayerRankData[player.userID].Economics = Convert.ToInt32(Economics?.CallHook("GetPlayerMoney", player.userID));
                }
                else {
                    data.PlayerRankData[player.userID].Economics = 0;
                }
                maxNum++;
                data.PlayerRankData[player.userID].Recent = maxNum;
            }
            if (isAuth(player)) {
                data.PlayerRankData[player.userID].Admin = true;
            }
            SaveData();
        }
        private string GetPlaytimeClock(double time) {
            TimeSpan dateDifference = TimeSpan.FromSeconds((float)time);
            var days = dateDifference.Days;
            var hours = dateDifference.Hours;
            hours += (days * 24);
            var mins = dateDifference.Minutes;
            var secs = dateDifference.Seconds;
            return string.Format("{0:00}:{1:00}:{2:00}", hours, mins, secs);
            //credit K1lly0u
        }
        void OnEntityTakeDamage(BaseEntity entity, HitInfo hitinfo, HitInfo hitInfo) {
            if (hitinfo.Initiator == null) return;
            var player = hitinfo.Initiator.ToPlayer();
            DamageType type = hitinfo.damageTypes.GetMajorityDamageType();
            float amount = hitinfo.damageTypes.Total();
            if (blockEvents) {
                object isPlaying = EventManager?.Call("isPlaying", new object[] {
                    player
                }
                );
                if (isPlaying is bool) if ((bool)isPlaying) return;
            }
            if (hitinfo.Initiator is BasePlayer && entity is BaseHelicopter) {
                //NextTick(() =>
                //{
                //if (entity == null) return; //no longer necessary?
                if (!HeliAttackers.ContainsKey(entity.net.ID)) HeliAttackers.Add(entity.net.ID, new Dictionary<ulong, int>());
                if (!HeliAttackers[entity.net.ID].ContainsKey(player.userID)) HeliAttackers[entity.net.ID].Add(player.userID, 1);
                else {
                    HeliAttackers[entity.net.ID][player.userID]++;
                    ProcessHeliHits((BasePlayer)player, (BaseEntity)entity);
                }
                //});
            }
            if (hitinfo?.Initiator is BasePlayer && entity is BradleyAPC) {
                if (type.ToString() == "Bullet") {
                    ProcessAPCHits((BasePlayer)player, (BaseEntity)entity);
                    //questionable
                    return;
                }
                if (!BradleyAttackers.ContainsKey(entity.net.ID)) BradleyAttackers.Add(entity.net.ID, new Dictionary<ulong, float>());
                if (!BradleyAttackers[entity.net.ID].ContainsKey(player.userID)) BradleyAttackers[entity.net.ID].Add(player.userID, amount);
                else {
                    BradleyAttackers[entity.net.ID][player.userID] = BradleyAttackers[entity.net.ID][player.userID] + amount;
                    ProcessAPCHits((BasePlayer)player, (BaseEntity)entity);
                }
            }
        }
        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;
                }
            }
            if (BradleyAttackers.ContainsKey(id)) {
                Dictionary<ulong, float> majority = BradleyAttackers[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 OnEntityDeath(BaseEntity entity, HitInfo hitinfo, HitInfo info) {
            if (entity.name.Contains("corpse")) return;
            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);
                    if (blockEvents) {
                        object isPlaying = EventManager?.Call("isPlaying", new object[] {
                            attacker
                        }
                        );
                        if (isPlaying is bool) if ((bool)isPlaying) return;
                    }
                    var distance = woundedData[victim.userID].distance;
                    if (!victim.userID.IsSteamId() || victim is NPCPlayer) {
                        if (attacker != null) {
                            if (data.PlayerRankData.ContainsKey(attacker.userID)) data.PlayerRankData[attacker.userID].NPCKills++;
                            if (distance > data.PlayerRankData[attacker.userID].NPCDistance) data.PlayerRankData[attacker.userID].NPCDistance = Math.Round(distance, 2);
                        }
                        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);
                        }
                        return;
                    }
                    woundedData.Remove(victim.userID);
                }
                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));
                Puts("There wasn't one");
                if (player != null)  //eject plug?
                {
                    ProcessHeliKills((BasePlayer)player);
                    HeliAttackers.Remove(entity.net.ID);
                    return;
                }
                else return;
            }
            if (entity is BradleyAPC) {
                BasePlayer player;
                var BradleyID = entity.net.ID;
                player = BasePlayer.FindByID(GetMajorityAttacker(BradleyID));
                if (player != null)  //shouldn't be possible now
                {
                    ProcessAPCKills((BasePlayer)player);
                    BradleyAttackers.Remove(BradleyID);
                    return;
                }
                else return;
            }
            if (hitinfo?.Initiator is BasePlayer) {
                if (hitinfo?.Initiator is NPCPlayer) return;
                var player = hitinfo.Initiator.ToPlayer();
                if (player.userID.IsSteamId()) {
                    if (entity.name.Contains("agents/")) {
                        ProcessPVEKill((BasePlayer)hitinfo.Initiator, (BaseEntity)entity);
                        return;
                    }
                    if (entity.name.Contains("barrel")) {
                        ProcessBarrelsDestroyed((BasePlayer)hitinfo.Initiator, (BaseEntity)entity);
                        return;
                    }
                    if (entity.name.Contains("turret")) {
                        ProcessWeaponTrapsDestroyed((BasePlayer)player);
                        return;
                    }
                    if (entity.name.Contains("guntrap")) {
                        ProcessWeaponTrapsDestroyed((BasePlayer)player);
                        return;
                    }
                    if (victim is BasePlayer && !victim.userID.IsSteamId()) {
                        ProcessNPCKills((BasePlayer)player, (BaseEntity)entity);
                        return;
                    }
                    if (victim is BasePlayer && victim is NPCPlayer) {
                        ProcessNPCKills((BasePlayer)player, (BaseEntity)entity);
                        return;
                    }
                    if (entity is BasePlayer && victim.userID.IsSteamId()) {
                        ProcessDeath((BasePlayer)entity);
                        if (hitinfo.Initiator != entity) ProcessPVPKill((BasePlayer)player, (BasePlayer)entity);
                        if (victim.IsSleeping()) ProcessSleepersKilled((BasePlayer)player, (BasePlayer)victim);
                        if (hitinfo.Initiator == entity) ProcessSuicide((BasePlayer)player);
                        return;
                    }
                }
            }
            if (victim == null) return;
            if (victim is BasePlayer) {
                ProcessDeath((BasePlayer)victim);
                return;
            }
            if (woundedData.ContainsKey(victim.userID)) {
                woundedData.Remove(victim.userID);
            }
            else return;
        }
        void OnExplosiveThrown(BasePlayer player, BaseEntity entity, Item item) {
            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;
            if (!(player.userID.IsSteamId()) || player is NPCPlayer) 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);
                        }
                    }
                    );
                }
            }
            else return;
        }
        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 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 OnEntitySpawned(BaseEntity entity) {
            if (!(entity.name.Contains("supply_drop"))) return;
            else airdrops.Add(entity.net.ID);
        }
        void OnLootEntity(BasePlayer player, BaseEntity entity) {
            if (airdrops.Contains(entity.net.ID)) {
                airdrops.Remove(entity.net.ID);
                ProcessDropsLooted((BasePlayer)player);
            }
        }
        void Unload() {
            foreach (BasePlayer current in BasePlayer.activePlayerList) {
                if (MenuOpen.Contains(current.userID)) {
                    CuiHelper.DestroyUi(current, "ranksgui");
                    MenuOpen.Remove(current.userID);
                }
            }
            SaveData();
        }
#region processes
        private void ProcessPVPKill(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 (useRustIO) {
                if(HasFriend(player.userID.ToString(), victim.userID.ToString())) 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 ProcessPVEKill(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].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 ProcessAPCHits(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].APCHits++;
            }
        }
        private void ProcessAPCKills(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].APCKills++;
        }
        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 ProcessWeaponTrapsDestroyed(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].WeaponTrapsDestroyed++;
        }
        private void ProcessSleepersKilled(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].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 ProcessNPCKills(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].NPCKills++;
            }
            if (victim.Distance(player.transform.position) > data.PlayerRankData[player.userID].NPCDistance) data.PlayerRankData[player.userID].NPCDistance = Math.Round(victim.Distance(player.transform.position), 2);
        }
        private void ProcessStructuresBuilt(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].StructuresBuilt++;
        }
        private void ProcessStructuresDemolished(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].StructuresDemolished++;
        }
        private void ProcessItemsDeployed(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].ItemsDeployed++;
        }
        private void ProcessItemsCrafted(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].ItemsCrafted++;
        }
        private void ProcessEntitiesRepaired(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].EntitiesRepaired++;
        }
        private void ProcessRocketsLaunched(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].RocketsLaunched++;
        }
        private void ProcessTimesHealed(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].TimesHealed++;
        }
        private void ProcessDropsLooted(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].DropsLooted++;
        }
        private void ProcessResourcesGathered(BasePlayer player, int amount = 0) {
            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].ResourcesGathered+=amount;
        }
        private void ProcessStructuresUpgraded(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].StructuresUpgraded++;
        }
        private void BroadcastToAll(string msg, string keyword) => PrintToChat(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 OnPlayerDisconnected(BasePlayer player, string reason) {
            data.PlayerRankData[player.userID].Status = "offline";
            if (isAuth(player)) {
                data.PlayerRankData[player.userID].Admin = true;
            }
            if (MenuOpen.Contains(player.userID)) {
                CuiHelper.DestroyUi(player, "ranksgui");
                MenuOpen.Remove(player.userID);
            }
        }
        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 = "Close", Color = closeColor
                }
                , RectTransform = {
                    AnchorMin = "0.4 0.02", AnchorMax = "0.6 0.082"
                }
                , Text = {
                    Text = "Close", FontSize = 20, Align = TextAnchor.MiddleCenter
                }
            }
            ;
            elements.Add(new CuiLabel {
                Text = {
                    Text = msg1, FontSize = 16, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.9", AnchorMax = "1 0.98"
                }
            }
            , mainName);
            elements.Add(new CuiLabel {
                Text = {
                    Text = msg, FontSize = 12, Align = TextAnchor.MiddleCenter
                }
                , RectTransform = {
                    AnchorMin = "0 0.10", AnchorMax = "1 0.9"
                }
            }
            , mainName);
            elements.Add(Close, mainName);
            CuiHelper.AddUi(player, elements);
        }
#region console commands
        [ConsoleCommand("Close")]
        private void Close(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (MenuOpen.Contains(player.userID)) {
                CuiHelper.DestroyUi(player, "ranksgui");
                MenuOpen.Remove(player.userID);
            }
            return;
        }
        [ConsoleCommand("ToggleTops")]
        private void cmdToggleTops(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) return;
            cmdTarget(player, "pr", new String[] {
                "tops"
            }
            );
        }
        [ConsoleCommand("playerranks.save")]
        private void cmdSave(ConsoleSystem.Arg arg) {
            SaveData();
            Puts("PlayerRanks database was saved.");
        }
        [ConsoleCommand("playerranks.wipe")]
        private void cmdWipe(ConsoleSystem.Arg arg) {
            data.PlayerRankData.Clear();
            PRData.WriteObject(data);
            OnServerInitialized();
            Puts("PlayerRanks database was wiped.");
        }
#endregion
#region chat commands
        [ChatCommand("pr")]
        void cmdTarget(BasePlayer player, string command, string[] args) {
            if (args == null || args.Length == 0) {
                var outMsg = string.Format(fontColor1 + lang.GetMessage("prtop", this, player.UserIDString) + " : </color>" + fontColor3 + lang.GetMessage("prtop2", this, player.UserIDString) + "</color> \n", fontColor1 + lang.GetMessage("title", this, player.UserIDString) + "</color>");
                outMsg += string.Format(fontColor1 + lang.GetMessage("prcat", this, player.UserIDString) + " : </color>" + fontColor3 + lang.GetMessage("prcat2", this, player.UserIDString) + "</color>", fontColor1 + lang.GetMessage("title", this, player.UserIDString) + "\n </color>");
                SendReply(player, outMsg);
                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 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(usenpckills)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("NPCKills", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.NPCKills), 1.0) + "</color> \n";
                if(usenpcdistance)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("NPCDistance", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.NPCDistance), 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(useapckills)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("APCKills", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.APCKills), 1.0) + "</color> \n";
                if(useapchits)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("APCHits", this, player.UserIDString) + ": </color>" + fontColor1 + "{0}", d.APCHits), 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(useweapontrapsdestroyed)topsMsgGUI += string.Format(string.Format(fontColor3 + lang.GetMessage("WeaponTrapsDestroyed", this, player.UserIDString) + ": </color>" + fontColor1 + "{0
// ... [Code preview truncated due to length. Full source in attached file] ...

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