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

FREE MeMenu : 0.1 0.1

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("меню для сервера", "memories", "0.1")]
    class MeMenu : RustPlugin
    {
        
        [PluginReference] private Plugin ImageLibrary;
        [PluginReference] private Plugin Teleport;
        
        private string Sharp = "assets/content/ui/ui.background.tile.psd";
        private string Blur = "assets/content/ui/uibackgroundblur.mat";
        private string radial = "assets/content/ui/ui.background.transparent.radial.psd";
        
        readonly DynamicConfigFile dataFile = Interface.Oxide.DataFileSystem.GetFile("MeMenu/PlayerData");
        Dictionary<ulong, PlayerData> data = new Dictionary<ulong, PlayerData>();
        
        class PlayerData
        {
            public string name = "Неизвестно";
            public string avatar = "Неизвестно";
            
            public PlayerData() { }
        }

        private string[] GetFriendList(BasePlayer player)
        {
            var players = new List<string>();
            ulong plt = GetPlayerTeamID(player);
            if (plt != 0)
            {
                foreach (var member in RelationshipManager._instance.teams[plt].members)
                {
                    if (player != null && player.userID != player.userID)
                    {
                        players.Add(player.displayName);
                    }
                    else
                    {
                        if (member != player.userID) players.Add(member.ToString());
                    }
                }
            }
            return players.ToArray();
        }
        private ulong GetPlayerTeamID(BasePlayer player)
        {
            ulong teamid = 0;
            if (player != null)
            {
                teamid = player.currentTeam;
            }
            else
            {
                foreach (var team in RelationshipManager._instance.teams)
                    if (team.Value.members.Contains(player.userID)) teamid = team.Value.teamID;
            }
            return teamid;
        }

        void OnServerInitialized()
        {
            if (ImageLibrary == null)
            {
                PrintError("Не установлен плагин ImageLibrary, установите его и перезапустите плагин!");
                return;
            }
            if (Teleport == null)
            {
                PrintError("Не установлен плагин Teleport, установите его и перезапустите плагин!");
                return;
            }
            foreach (var a in cfg.Setts2)
            {
                ImageLibrary.Call<string>("AddImage", a.Image, a.Image);
            }
            
            foreach (var player in BasePlayer.activePlayerList)
                OnPlayerInit(player);
        }

        void OnPlayerInit(BasePlayer player)
        {
            GetAvatar(player.userID, avatar =>
            {
                data[player.userID].avatar = avatar;
                ImageLibrary.Call("AddImage", avatar, $"avatar{player.userID}");
                SaveData();
            });
            
            if (!data.ContainsKey(player.userID))
            {
                CreatePlayerData(player.userID);
            }
        }
        
        void CreatePlayerData(ulong id)
        {
            if (data.ContainsKey(id)) return;
            
            PlayerData i = new PlayerData();
            BasePlayer player = BasePlayer.FindByID(id) ?? BasePlayer.FindSleeping(id);
            if (player != null) i.name = player.displayName;
            data.Add(id, i);
        }
        
        void SaveData()
        {
            dataFile.WriteObject(data);

        }
        
        void OnNewSave()
        {
            data = new Dictionary<ulong, PlayerData>();
        }
        
        void GetAvatar(ulong uid, Action<string> callback)
        {
            if (callback == null) return;
            string url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=3F2959BD838BF8FB544B9A767F873457&" + "steamids=" + uid;
            webrequest.EnqueueGet(url, (i, json) => callback?.Invoke((string)JObject.Parse(json)["response"]["players"][0]["avatarfull"]), this);
        }
		
        public class Settings
        {
            [JsonProperty("Команда")]
            public string Command;
            [JsonProperty("Текст на кнопке")]
            public string Text;
        }
        public class Settings2
        {
            [JsonProperty("Команда")]
            public string Command;
            [JsonProperty("Изображение")]
            public string Image;
            [JsonProperty("Текст на кнопке")]
            public string Text;
        }
        public conf cfg;
                public class conf
        {
            [JsonProperty("Настройка верхних кнопок:")]
            public List<Settings> Setts = new List<Settings>();
            [JsonProperty("Настройка нижних кнопок:")]
            public List<Settings2> Setts2 = new List<Settings2>();
            public static conf GetConfiguration()
            {
                return new conf()
                {
                    Setts = new List<Settings>
                    {
                        new Settings
                        {
                            Command = "chat.say /xuy",
                            Text = "КНОПКА 1"
                        },
                        new Settings
                        {
                            Command = "chat.say /chlen",
                            Text = "КНОПКА 2"
                        },
                        new Settings
                        {
                            Command = "chat.say /chleni",
                            Text = "КНОПКА 3"
                        },
                        new Settings
                        {
                            Command = "chat.say /chlenus",
                            Text = "КНОПКА 4"
                        }
                    },
                    Setts2 = new List<Settings2>
                    {
                        new Settings2
                        {
                            Command = "chat.say /xuy",
                            Text = "Нажмите чтобы открыть",
                            Image = "https://i.imgur.com/HtaHm1u.jpg"
                        },
                        new Settings2
                        {
                            Command = "chat.say /hlern",
                            Text = "Нажмите чтобы открыть",
                            Image = "https://i.imgur.com/HtaHm1u.jpg"
                        },
                        new Settings2
                        {
                            Command = "chat.say /fsfs",
                            Text = "Нажмите чтобы открыть",
                            Image = "https://i.imgur.com/HtaHm1u.jpg"
                        },
                        new Settings2
                        {
                            Command = "chat.say /fsdf",
                            Text = "Нажмите чтобы открыть",
                            Image = "https://i.imgur.com/HtaHm1u.jpg"
                        },
                    }
                };
            }
        }
                protected override void LoadConfig()
                {
                    base.LoadConfig();
                    try
                    {
                        cfg = Config.ReadObject<conf>();
                        if (cfg?.Setts == null || cfg?.Setts2 == null ) LoadDefaultConfig();
                    }
                    catch
                    {
                        PrintWarning($"Error reading config, creating one new config!");
                        LoadDefaultConfig();
                    }

                    NextTick(SaveConfig);
                }
                protected override void LoadDefaultConfig()
                {
                    cfg = conf.GetConfiguration();
                }

                protected override void SaveConfig() => Config.WriteObject(cfg);

        public string GetGrid(BasePlayer player)
        {
            string[] mass = new string[]
            {
                "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "Q", "R", "S", "T", "U", "V",
                "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "Q", "R", "S", "T", "U", "V",
                "W", "X", "Y", "Z"
            };
            return $"{mass[GetGridString(player.transform.position)]}{GetGridNumber(player.transform.position)}";

        }

        public int GetGridNumber(Vector3 position)
        {
            Vector2 adjPosition = new Vector2((World.Size / 2) + position.x, (World.Size / 2) - position.z);

            return (int) (adjPosition.y / 150);
        }

        public int GetGridString(Vector3 position)
        {
            Vector2 adjPosition = new Vector2((World.Size / 2) + position.x, (World.Size / 2) - position.z); 
            return ((int)(adjPosition.x / 150)); 
        }
        
        void Unload()
        {
            foreach (var player in BasePlayer.activePlayerList)
            {
                CuiHelper.DestroyUi(player, "Box");
            }
        }
        [ChatCommand("menu")]
        void MenuCommand(BasePlayer player)
        {
            if (player == null) return;
                Menu(player);
        }
        [ConsoleCommand("command.cmd")]
        void ConnandCMD(ConsoleSystem.Arg args)
        {
            var player = args.Player();
            var name = GetGrid(player);
            switch (args.Args[0].ToLower())
                 {
                     case "sethome":
                         player.Command($"chat.say \"/sethome {name}\"");
                         break;
                     case "removehome":
                         player.Command($"chat.say \"/removehome {args.Args[1]}\"");
                         break;
                 }
        }

        void Menu(BasePlayer player)
        {
            CuiHelper.DestroyUi(player, "Box");
            var cont = new CuiElementContainer();
            cont.Add(new CuiPanel
            {
                CursorEnabled = true,
                Image = { Color = HexToRustFormat("#262825F1"), Material = Sharp, FadeIn = 0.25f},
                RectTransform = {AnchorMin = "0 0", AnchorMax = "1 1"}
            },"Overlay", "Box");
            cont.Add(new CuiButton
            {
                Button = {Close = "Box", Color = "0 0 0 0", FadeIn = 0.25f},
                RectTransform = {AnchorMin = "-100 -100", AnchorMax = "100 100", OffsetMin = "0 0"}
            }, "Box");
            cont.Add(new CuiElement
            {
                Parent = "Box",
                Name = "Box" + "Boxes",
                Components =
                {
                    new CuiImageComponent()
                    {
                        Color = HexToRustFormat("#0000000E"),
                        Material = Sharp,
                        FadeIn = 0.25f
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0.5 0.5",
                        AnchorMax = "0.5 0.5",
                        OffsetMin = "-380 -180",
                        OffsetMax = "380 180"
                    }
                }
            });
            cont.Add(new CuiElement
            {
                Parent = "Box" + "Boxes",
                Components =
                {
                    new CuiImageComponent()
                    {
                        Color = HexToRustFormat("#000000B5"), Material = Blur,
                        FadeIn = 0.25f
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "6.816117E-08 0.9277776",
                        AnchorMax = "1 0.951852",
                    }
                }
            });
            cont.Add(new CuiElement
            {
                Parent = "Box" + "Boxes",
                Components =
                {
                    new CuiImageComponent()
                    {
                        Color = HexToRustFormat("#000000B5"), Material = Blur,
                        FadeIn = 0.25f
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "6.816117E-08 0.04629408",
                        AnchorMax = "1 0.07036839",
                    }
                }
            });
            cont.Add(new CuiElement
            {
                Parent = "Box" + "Boxes",
                Components =
                {
                    new CuiImageComponent()
                    {
                        Color = HexToRustFormat("#000000B5"), Material = Blur,
                        FadeIn = 0.25f
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0.9692979 -0.02037038",
                        AnchorMax = "0.9807017 1.027778",
                    }
                }
            });
            cont.Add(new CuiElement
            {
                Parent = "Box" + "Boxes",
                Components =
                {
                    new CuiImageComponent()
                    {
                        Color = HexToRustFormat("#000000B5"), Material = Blur,
                        FadeIn = 0.25f
                        
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0.02104616 -0.02037038",
                        AnchorMax = "0.03244941 1.027778",
                    }
                }
            });
            cont.Add(new CuiElement
            {
                Parent = "Box" + "Boxes",
                Components =
                {
                    new CuiImageComponent()
                    {
                        Color = HexToRustFormat("#000000B5"), Material = Blur,
                        FadeIn = 0.25f
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0.2499927 -0.02037038",
                        AnchorMax = "0.2613965 1.027778",
                    }
                }
            });
            cont.Add(new CuiElement
            {
                Parent = "Box" + "Boxes",
                Components =
                {
                    new CuiImageComponent()
                    {
                        Color = HexToRustFormat("#000000B5"), Material = Blur,
                        FadeIn = 0.25f
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "6.816117E-08 0.4555542",
                        AnchorMax = "1 0.4796285",
                    }
                }
            });
            cont.Add(new CuiElement
            {
                Parent = "Box" + "Boxes",
                Components =
                {
                    new CuiRawImageComponent()
                    {
                        Color = "1 1 1 1",
                        Png = (string) ImageLibrary?.Call("GetImage", "avatar" + player.userID),
                        FadeIn = 0.25f
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0.0403508 0.4907407",
                        AnchorMax = "0.2421051 0.9166666",
                    }
                }
            });
            
            var homes =  (Dictionary<string, Vector3>)Teleport?.Call("ApiGetHomes", player.userID) ?? new Dictionary<string, Vector3>();
            var playerTeam = GetFriendList(player);
            
            int h = 0;
            foreach (var team in playerTeam)
            {
                var teamate = covalence.Players.FindPlayerById(team).Name;
                cont.Add(new CuiButton
                {
                    Button =
                    {
                        Color = HexToRustFormat("#181818F4"),
                        Command = $"teleport.tpr {team}",
                        Close = "Box",
                        FadeIn = 0.25f
                    },
                    Text =
                    {
                        Text = $"{teamate}",
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 19,
                        Font = "robotocondensed-regular.ttf",
                        FadeIn = 0.25f
                    },
                    RectTransform =
                    {
                        AnchorMin = $"{0.2649101 + h * 0.2228092 - Math.Floor((double) h / 2) * 2 * 0.2228092} {0.362963 - Math.Floor((double) h / 2) * 0.1259262}",
                        AnchorMax = $"{0.4833333 + h * 0.2228092 - Math.Floor((double) h / 2) * 2 * 0.2228092} {0.4481479 - Math.Floor((double) h / 2) * 0.1259262}"
                    }
                }, "Box" + "Boxes");
                h++;
            }
            
            if (homes.Count < 5)
            {
                cont.Add(new CuiButton
                {
                    RectTransform =
                    {
                       
                        AnchorMin = "0.7096478 0.2055548",
                        AnchorMax = "0.9649125 0.3222217"
                    },
                    Button =
                    {
                        Color = HexToRustFormat("#181818F4"),
                        Command = $"command.cmd sethome",
                        Close = "Box",
                        FadeIn = 0.25f
                    },
                    Text =
                    {
                        Text = "Сохранить дом",
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 22,
                        Font = "robotocondensed-regular.ttf",
                        FadeIn = 0.25f
                    },
                }, "Box" + "Boxes");
            }
            
            int z = 0, u = 0, i = 0;
            foreach (var check in homes)
            {
                cont.Add(new CuiButton
                {
                    RectTransform =
                    {
                        AnchorMin = $"{0.4877193 + (u * 0.2228092)} {0.331481 - (z * 0.1259262)}", 
                        AnchorMax = $"{0.6464887 + (u * 0.2228092)} {0.4481479 - (z * 0.1259262)}"
                     
                    },
                    Button =
                    {
                        Color = HexToRustFormat("#181818F4"),
                        Command = $"teleport.home {check.Key}",
                        Close = "Box",
                        FadeIn = 0.25f
                    },
                    Text =
                    {
                        Text = $"Дом:{check.Key}",
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 19,
                        Font = "robotocondensed-regular.ttf",
                        FadeIn = 0.25f
                            
                    },
                }, "Box" + "Boxes");

                cont.Add(new CuiButton
                {
                    Button =
                    {
                        Color = HexToRustFormat("#181818F4"),
                        Command = $"command.cmd removehome {check.Key}",
                        Close = "Box",
                        FadeIn = 0.25f
                    },
                    Text =
                    {
                        Text = $"✖",
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 30,
                        FadeIn = 0.25f
                    },
                    RectTransform =
                    {
                        AnchorMin = $"{0.6499975 + (u * 0.221932)} {0.331481 - (z * 0.1259262)}", 
                        AnchorMax = $"{0.7052608 + (u * 0.221932)} {0.4481479 - (z * 0.1259262)}"
                        
                    }
                }, "Box" + "Boxes");
                z++; i++;
                
                if (z == 3)
                {
                    z = 0;
                    u++;

                    if (u == 11)
                    {
                        break;
                    }
                }
            }

            cont.Add(new CuiButton
                    {
                        Button =
                        {
                            Color = HexToRustFormat("#181818F4"),
                            Command = $"chat.say /tpa",
                            Close = "Box",
                            FadeIn = 0.25f
                        },
                        Text =
                        {
                            Text = $"<b>Принять</b>\n"+ "<size=10>Телепорт</size>",
                            Align = TextAnchor.MiddleCenter,
                            Font = "robotocondensed-regular.ttf",
                            FontSize = 15,
                            FadeIn = 0.25f
                        },
                        RectTransform =
                        {
                            AnchorMin = 
                                "0.7096478 0.0777768",
                            AnchorMax =
                                "0.8350916 0.196295" 
                        }
                    }, "Box" + "Boxes");
                cont.Add(new CuiButton
                    {
                        Button =
                        {
                            Color = HexToRustFormat("#181818F4"),
                            Command = $"chat.say /tpc",
                            Close = "Box",
                            FadeIn = 0.25f
                        },
                        Text =
                        {
                            Text = $"<b>Отклонить</b>\n"+ "<size=10>Телепорт</size>",
                            Align = TextAnchor.MiddleCenter,
                            Font = "robotocondensed-regular.ttf",
                            FontSize = 15,
                            FadeIn = 0.25f
                        },
                        RectTransform =
                        {
                            AnchorMin =
                                "0.8394737 0.0777768",
                            AnchorMax =
                                "0.9649174 0.196295" 
                        }
                    }, "Box" + "Boxes");
                int x = 0;
                foreach (var check in cfg.Setts)
                {
                    cont.Add(new CuiButton
                        {
                            Button =
                            {
                                Color = HexToRustFormat("#181818F4"),
                                Command = check.Command,
                                Close = "Box",
                                FadeIn = 0.25f
                            },
                            Text =
                            {
                                Text = check.Text,
                                Align = TextAnchor.MiddleCenter,
                                Font = "robotocondensed-regular.ttf",
                                FontSize = 18,
                                FadeIn = 0.25f
                            },
                            RectTransform =
                            {
                                AnchorMin =
                                    $"{0.2692975 + x * 0.1736859 - Math.Floor((double) x / 4) * 4 * 0.1736859} 0.7981489", 
                                AnchorMax =
                                    $"{0.4377193 + x * 0.1736859 - Math.Floor((double) x / 4) * 4 * 0.1736859} 0.9166673"
                            }
                        }, "Box" + "Boxes", "Box" + "Boxes" + check.Text);
                    x++;
                }
                int y = 0;
                foreach (var check in cfg.Setts2)
                {
                    cont.Add(new CuiElement
                    {
                        Parent = "Box" + "Boxes",
                        Components =
                        {
                            new CuiRawImageComponent()
                            {
                                Color = "1 1 1 1",
                                Png = (string) ImageLibrary.CallHook("GetImage", $"{check.Image}")
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin =
                                    $"{0.2692975 + y * 0.1736859 - Math.Floor((double) y / 4) * 4 * 0.1736859} 0.4888888", 
                                AnchorMax =
                                    $"{0.4377193 + y * 0.1736859 - Math.Floor((double) y / 4) * 4 * 0.1736859} 0.7888889"
                            }
                        }
                    });
                    cont.Add(new CuiButton
                        {
                            Button =
                            {
                                Color = "0 0 0 0",
                                Command = check.Command,
                                Close = "Box",
                                FadeIn = 0.25f
                            },
                            Text =
                            {
                                Text = check.Text,
                                Align = TextAnchor.LowerCenter,
                                Font = "robotocondensed-regular.ttf",
                                FontSize = 12,
                                FadeIn = 0.25f
                            },
                            RectTransform =
                            {
                                AnchorMin =
                                    $"{0.2692975 + y * 0.1736859 - Math.Floor((double) y / 4) * 4 * 0.1736859} 0.4888888", 
                                AnchorMax =
                                    $"{0.4377193 + y * 0.1736859 - Math.Floor((double) y / 4) * 4 * 0.1736859} 0.7888889"
                            }
                        }, "Box" + "Boxes");
                    y++;
                }
                
                cont.Add(new CuiButton
                    {
                        Button =
                        {
                            Color = HexToRustFormat("#181818F4"),
                            Command = null,
                            FadeIn = 0.25f
                            
                        },
                        Text =
                        {
                            Text = $"<b>{player.displayName}</b>" + "\n<size=10>Ваше игровое имя</size>",
                            Align = TextAnchor.LowerCenter,
                            Font = "robotocondensed-regular.ttf",
                            FontSize = 16,
                            FadeIn = 0.25f
                        },
                        RectTransform =
                        {
                            AnchorMin =
                                $"0.041228 0.3277773", 
                            AnchorMax =
                                $"0.2429823 0.4462958"
                        }
                    }, "Box" + "Boxes");
                cont.Add(new CuiButton
                    {
                        Button =
                        {
                            Color = HexToRustFormat("#181818F4"),
                            Command = "chat.say /stats",
                            Close = "Box",
                            FadeIn = 0.25f
                        },
                        Text =
                        {
                            Text = $"<b>СТАТИСТИКА</b>" + "\n<size=10>Статистика игры</size>",
                            Align = TextAnchor.LowerCenter,
                            Font = "robotocondensed-regular.ttf",
                            FontSize = 16,
                            FadeIn = 0.25f
                        },
                        RectTransform =
                        {
                            AnchorMin =
                                $"0.041228 0.2037029", 
                            AnchorMax =
                                $"0.2429823 0.3222214"
                        }
                    }, "Box" + "Boxes");
                cont.Add(new CuiButton
                    {
                        Button =
                        {
                            Color = HexToRustFormat("#181818F4"),
                            Command = "chat.say /report",
                            Close = "Box",
                            FadeIn = 0.25f
                        },
                        Text =
                        {
                            Text = $"<b>РЕПОРТЫ</b>" + "\n<size=10>Отправь жалобу на игрока</size>",
                            Align = TextAnchor.LowerCenter,
                            Font = "robotocondensed-regular.ttf",
                            FontSize = 16,
                            FadeIn = 0.25f
                        },
                        RectTransform =
                        {
                            AnchorMin =
                                $"0.041228 0.07962871", 
                            AnchorMax =
                                $"0.2429823 0.198147"
                        }
                    }, "Box" + "Boxes");
                
                CuiHelper.AddUi(player, cont);
        }
        static string HexToRustFormat(string hex)
        {
            if (string.IsNullOrEmpty(hex))
            {
                hex = "#FFFFFFFF";
            }

            var str = hex.Trim('#');

            if (str.Length == 6)
                str += "FF";

            if (str.Length != 8)
            {
                throw new Exception(hex);
                throw new InvalidOperationException("Cannot convert a wrong format.");
            }

            var r = byte.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
            var g = byte.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
            var b = byte.Parse(str.Substring(4, 2), NumberStyles.HexNumber);
            var a = byte.Parse(str.Substring(6, 2), NumberStyles.HexNumber);

            Color color = new Color32(r, g, b, a);

            return string.Format("{0:F2} {1:F2} {2:F2} {3:F2}", color.r, color.g, color.b, color.a);
        }
    }
}

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