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

FREE Stats : 7.0.0 7.0.0

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
namespace Oxide.Plugins {
    [Info("Stats", "Sempai#3239", "7.0.0")]
    class Stats : RustPlugin {
#region Вар
        string Layer = "Stats_UI";
        [PluginReference]
        Plugin ImageLibrary;
        Dictionary<ulong, string> NameButton = new Dictionary<ulong, string>();
        public Dictionary<ulong, DBSettings> DB = new Dictionary<ulong, DBSettings>();
#endregion
#region Класс
        Dictionary<string, string> top = new Dictionary<string, string>() {
            ["УБИЙСТВА ИГРОКОВ"]
            = "0", ["УБИЙСТВА ЖИВОТНЫХ"] = "1", ["УБИЙСТВА УЧЕНЫХ"] = "2", ["СБОР РЕСУРСОВ"] = "3", ["ВРЕМЯ НА СЕРВЕРЕ"] = "4", ["РЕЙДЕР"] = "5"
        }
        ;
        public class DBSettings {
            public string DisplayName;
            public List<int> Count;
        }
#endregion
#region Хуки
        void OnServerInitialized() {
            if (Interface.Oxide.DataFileSystem.ExistsDatafile("StatsSystem/PlayerList")) DB = Oxide.Core.Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, DBSettings>>("StatsSystem/PlayerList");
            foreach (var check in BasePlayer.activePlayerList) OnPlayerConnected(check);
            timer.Every(60f, PlayTime);
        }
        void OnPlayerConnected(BasePlayer player) {
            SteamAvatarAdd(player.UserIDString);
            if (!DB.ContainsKey(player.userID)) DB.Add(player.userID, new DBSettings {
                DisplayName = player.displayName, Count = new List<int>() {
                    0, 0, 0, 0, 0, 0
                }
            }
            );
            NameButton[player.userID] = "0";
            SaveDataBase();
        }
        void PlayTime() {
            foreach (var check in BasePlayer.activePlayerList) DB[check.userID].Count[4] += 1;
        }
        void SaveDataBase() => Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("StatsSystem/PlayerList", DB);
        void OnPlayerDisconnected(BasePlayer player, string reason) => SaveDataBase();
        void Unload() => SaveDataBase();
        void OnDispenserGather(ResourceDispenser dispenser, BasePlayer player, Item item) {
            if (dispenser == null || player == null || item == null) return;
            DB[player.userID].Count[3] += item.amount;
        }
        void OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item) {
            if (dispenser == null || player == null || item == null) return;
            DB[player.userID].Count[3] += item.amount;
        }
        void OnCollectiblePickup(Item item, BasePlayer player) {
            if (item == null || player == null) return;
            DB[player.userID].Count[3] += item.amount;
        }
        void OnPlayerDeath(BasePlayer player, HitInfo info) {
            if (info == null || player == null || player.IsNpc || info.InitiatorPlayer == null || info.InitiatorPlayer.IsNpc) return;
            if (info.InitiatorPlayer != null) {
                var killer = info.InitiatorPlayer;
                if (killer != player) {
                    DB[killer.userID].Count[0] += 1;
                }
            }
        }
        void OnEntityDeath(BaseCombatEntity entity, HitInfo info) {
            if (entity == null || info == null) return;
            BasePlayer player = info.InitiatorPlayer;
            if (player == null) return;
            if (entity is NPCPlayer) {
                DB[player.userID].Count[2] += 1;
            }
            if (entity is BaseAnimalNPC) {
                DB[player.userID].Count[1] += 1;
            }
        }
        void OnExplosiveThrown(BasePlayer player, BaseEntity entity, ThrownWeapon item) {
            if (player == null || entity == null || item == null) return;
            DB[player.userID].Count[5] += 1;
        }
        void OnRocketLaunched(BasePlayer player, BaseEntity entity) {
            if (player == null || entity == null) return;
            DB[player.userID].Count[5] += 1;
        }
#endregion
#region Команды
        [ConsoleCommand("stats")]
        void ConsoleStats(ConsoleSystem.Arg args) {
            var player = args.Player();
            if (player != null && args.HasArgs(1)) {
                if (args.Args[0] == "button") {
                    NameButton[player.userID] = args.Args[1];
                    StatsUI(player);
                }
            }
        }
#endregion
#region Интерфейс
        void StatsUI(BasePlayer player) {
            CuiHelper.DestroyUi(player, "MainInterface");
            var container = new CuiElementContainer();
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = "0.276 0", AnchorMax = "0.955 1", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "0.117 0.121 0.109 0.95"
                }
            }
            , "Menu_UI", "MainInterface");
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = $"0 0", AnchorMax = $"0.3 1", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "0.549 0.270 0.215 0.7"
                }
            }
            , "MainInterface", "Buttons");
            container.Add(new CuiLabel {
                RectTransform = {
                    AnchorMin = "0.01 0.92", AnchorMax = $"0.78 1", OffsetMax = "0 0"
                }
                , Text = {
                    Text = $"СТАТИСТИКА", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 28, Font = "robotocondensed-bold.ttf"
                }
            }
            , "Buttons");
            float width1 = 0.95f, height1 = 0.063f, startxBox1 = 0.058f, startyBox1 = 0.63f - height1, xmin1 = startxBox1, ymin1 = startyBox1;
            foreach (var check in top) {
                var color = NameButton[player.userID] == check.Value ? "0 0 0 0.6" : "0 0 0 0";
                container.Add(new CuiButton {
                    RectTransform = {
                        AnchorMin = $"{xmin1} {ymin1}", AnchorMax = $"{xmin1 + width1} {ymin1 + height1 * 1}", OffsetMin = "2 1", OffsetMax = "-2 -1"
                    }
                    , Button = {
                        Color = color, Command = $"stats button {check.Value}"
                    }
                    , Text = {
                        Text = ""
                    }
                }
                , "Buttons", "Top");
                container.Add(new CuiLabel {
                    RectTransform = {
                        AnchorMin = $"0 0", AnchorMax = $"1 1", OffsetMax = "0 0"
                    }
                    , Text = {
                        Text = $"{check.Key}    ", Color = "1 1 1 0.8", Align = TextAnchor.MiddleRight, FontSize = 20, Font = "robotocondensed-bold.ttf"
                    }
                }
                , "Top");
                xmin1 += width1;
                if (xmin1 + width1 >= 1) {
                    xmin1 = startxBox1;
                    ymin1 -= height1;
                }
            }
            var tops = int.Parse(NameButton[player.userID]);
            var target = DB.OrderByDescending(z => z.Value.Count.ElementAt(tops));
            container.Add(new CuiPanel {
                RectTransform = {
                    AnchorMin = $"0.558 0.54", AnchorMax = $"0.731 0.835", OffsetMax = "0 0"
                }
                , Image = {
                    Color = "0 0 0 0"
                }
            }
            , "MainInterface", "Top1");
            container.Add(new CuiElement {
                Parent = "Top1", Components = {
                    new CuiRawImageComponent {
                        Png = (string) ImageLibrary.Call("GetImage", target.ElementAt(0).Key.ToString())
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0 0.3", AnchorMax = "1 1", OffsetMax = "0 0"
                    }
                }
            }
            );
            container.Add(new CuiLabel {
                RectTransform = {
                    AnchorMin = $"0 0", AnchorMax = $"1 0.3", OffsetMax = "0 0"
                }
                , Text = {
                    Text = $"<color=#ffd700><size=18><b>----------</b></size>\n1. {target.ElementAt(0).Value.DisplayName}</color>\nСчет: {target.ElementAt(0).Value.Count[tops]}", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf"
                }
            }
            , "Top1");
            if (target.Count() >= 2) {
                container.Add(new CuiPanel {
                    RectTransform = {
                        AnchorMin = $"0.3555 0.643", AnchorMax = $"0.53 0.938", OffsetMax = "0 0"
                    }
                    , Image = {
                        Color = "0 0 0 0"
                    }
                }
                , "MainInterface", "Top2");
                container.Add(new CuiElement {
                    Parent = "Top2", Components = {
                        new CuiRawImageComponent {
                            Png = (string) ImageLibrary.Call("GetImage", target.ElementAt(1).Key.ToString())
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0.3", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                container.Add(new CuiLabel {
                    RectTransform = {
                        AnchorMin = $"0 0", AnchorMax = $"1 0.3", OffsetMax = "0 0"
                    }
                    , Text = {
                        Text = $"<color=#c0c0c0><size=18><b>----------</b></size>\n2. {target.ElementAt(1).Value.DisplayName}</color>\nСчет: {target.ElementAt(1).Value.Count[tops]}", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf"
                    }
                }
                , "Top2");
            }
            if (target.Count() >= 3) {
                container.Add(new CuiPanel {
                    RectTransform = {
                        AnchorMin = $"0.76 0.643", AnchorMax = $"0.933 0.938", OffsetMax = "0 0"
                    }
                    , Image = {
                        Color = "0 0 0 0"
                    }
                }
                , "MainInterface", "Top3");
                container.Add(new CuiElement {
                    Parent = "Top3", Components = {
                        new CuiRawImageComponent {
                            Png = (string) ImageLibrary.Call("GetImage", target.ElementAt(2).Key.ToString())
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0.3", AnchorMax = "1 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                container.Add(new CuiLabel {
                    RectTransform = {
                        AnchorMin = $"0 0", AnchorMax = $"1 0.3", OffsetMax = "0 0"
                    }
                    , Text = {
                        Text = $"<color=#cd7f32><size=18><b>----------</b></size>\n3. {target.ElementAt(2).Value.DisplayName}</color>\nСчет: {target.ElementAt(2).Value.Count[tops]}", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf"
                    }
                }
                , "Top3");
            }
            float width = 0.641f, height = 0.06f, startxBox = 0.324f, startyBox = 0.54f - height, xmin = startxBox, ymin = startyBox;
            for (int z = 3; z < target.Take(10).Count();
            z++) {
                container.Add(new CuiPanel {
                    RectTransform = {
                        AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width} {ymin + height * 1}", OffsetMin = "0 7", OffsetMax = "0 -7"
                    }
                    , Image = {
                        Color = "1 1 1 0.1"
                    }
                }
                , "MainInterface", "Players");
                container.Add(new CuiLabel {
                    RectTransform = {
                        AnchorMin = $"0.07 0", AnchorMax = $"1 1", OffsetMax = "0 0"
                    }
                    , Text = {
                        Text = $"<color=#8bcd4d>{z + 1}. {target.ElementAt(z).Value.DisplayName}</color>", Color = "1 1 1 0.8", Align = TextAnchor.MiddleLeft, FontSize = 14, Font = "robotocondensed-bold.ttf"
                    }
                }
                , "Players");
                container.Add(new CuiLabel {
                    RectTransform = {
                        AnchorMin = $"0 0", AnchorMax = $"0.97 1", OffsetMax = "0 0"
                    }
                    , Text = {
                        Text = $"<color=#8bcd4d>Счет: {target.ElementAt(z).Value.Count[tops]}</color>", Color = "1 1 1 0.8", Align = TextAnchor.MiddleRight, FontSize = 14, Font = "robotocondensed-bold.ttf"
                    }
                }
                , "Players");
                container.Add(new CuiElement {
                    Parent = "Players", Components = {
                        new CuiRawImageComponent {
                            Png = (string) ImageLibrary.Call("GetImage", target.ElementAt(z).Key.ToString())
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "0.06 1", OffsetMax = "0 0"
                        }
                    }
                }
                );
                xmin += width;
                if (xmin + width1 >= 1) {
                    xmin = startxBox;
                    ymin -= height;
                }
            }
            CuiHelper.AddUi(player, container);
        }
#endregion
#region Подгрузка аватарок
        void SteamAvatarAdd(string userid) {
            string url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=B23DC0D84302CF828713C73F35A30006&" + "steamids=" + userid;
            webrequest.Enqueue(url, null, (code, response) => {
                if (code == 200) {
                    string Avatar = (string)JObject.Parse(response)["response"]?["players"]?[0]?["avatarfull"];
                    ImageLibrary.Call("AddImage", Avatar, userid);
                }
            }
            , this);
        }
#endregion
    }
}

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