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

FREE MStore : 0.0.1 0.0.1

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






namespace Oxide.Plugins
{
    [Info("MStore", "Mystery", "0.0.1")]
    [Description("Store")]
    class MStore : RustPlugin
    {
        [PluginReference] private Plugin ImageLibrary;
		







        private string Layer = "UI_Mstore";
        [ChatCommand("store")] 
        private void CmdChagb(BasePlayer player)
        {
            UI(player);
        }
        void UI(BasePlayer p, int page = 0)
        {
            CuiElementContainer container = new CuiElementContainer();
            container.Add(new CuiPanel()
            {
                CursorEnabled = true,
                RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                Image = { Color = "0 0 0 0" }
            }, "Mystery", Layer);
            container.Add(new CuiPanel()
            {
                CursorEnabled = true,
                RectTransform = { AnchorMin = "0 0", AnchorMax = "1 0.1" },
                Image = { Color = "0 1 0 0" }
            }, Layer, "p"); 
            container.Add(new CuiPanel()
            {
                CursorEnabled = true,
                RectTransform = { AnchorMin = "0 0.1", AnchorMax = "1 1" },
                Image = { Color = "0 0 1 0" }
            }, Layer, "i");

            var s = GetStorage(p.userID);
            
            float gap = 0.02f, width = 0.18f, height = 0.317f, startxBox = 0.01f, startyBox = 1.01f - height, xmin = startxBox, ymin = startyBox;
            int i = 0;
            var itemsList = s.Shop.OrderBy(l => l.CountItem).Skip(page * 15).Take(15);
            foreach (var item in itemsList)
            {
                var c = item.Item == null ? item.ImageCommand : "https://www.rustedit.io/images/imagelibrary/" + item.Item + ".png";
                i++;
                container.Add(new CuiPanel
                {
                    RectTransform = { AnchorMin = xmin + " " + ymin, AnchorMax = (xmin + width) + " " + (ymin + height * 0.95), OffsetMax = "0 0", OffsetMin = "0 0" },
                    Image = { Color = "0.89 0.81 0.70 0.4" }
                }, "i", $"Button.{i}");
               
				container.Add(new CuiElement
                {
                    Parent = $"Button.{i}",
                    Components = { 
                         new CuiRawImageComponent { Url = c},
                         new CuiRectTransformComponent {AnchorMin = "0.05 0.1", AnchorMax = "0.95 0.9", OffsetMax = "0 0", OffsetMin = "0 0" }
                    }
                });

                


				container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0", OffsetMin = "0 0" },
                    Button = { Color = "1 1 1 0", Command = $"add giv {item.key}" },
                    Text = { Text = $"X{item.CountItem}" }
                }, $"Button.{i}");
				
				 xmin += width + gap;
                if (xmin + width >= 1)
                {
                    xmin = startxBox;
                    ymin -= height + gap;
                }
				
			}
			
			
			string color = s.Shop.Skip(15 * (page + 1)).Count() > 0 ? "0 0 0 1" : "1 1 1 0.5";
            string color1 = s.Shop.Skip(15 * (page + 1)).Count() > 0 ? "0.89 0.81 0.70 0.5" : "0.89 0.81 0.70 0.3";
            string color2 = page < 1 ? "0 0 0 1" : "1 1 1 0.5";
            string color3 = page > 0 ? "0.89 0.81 0.70 0.5" : "0.89 0.81 0.70 0.3";
            container.Add(new CuiButton
            {
                Button =
                {
                    Color = color3 , Command = page > 0 ? $"add page {page -1}" : ""
                },
                Text =
                {
                    Text = "<", FontSize = 25, Align = TextAnchor.MiddleCenter, Color = color
                },
                RectTransform =
                {
                    AnchorMin = $"0 0", AnchorMax = $"0.1 0.8"
                }
            }, "p");

            container.Add(new CuiButton
            {
                Button =
                {
                    Color = color1, Command =  s.Shop.Skip(15 * (page + 1)).Count() > 0 ? $"add page {page +1}" : ""
                },
                Text =
                {
                    Text = ">", FontSize = 25, Align = TextAnchor.MiddleCenter, Color = color2
                },
                RectTransform =
                {
                  AnchorMin = $"0.11 0", AnchorMax = $"0.21 0.8"
                }
            }, "p");




            container.Add(new CuiButton
            {
                Button =
                {
                    Color = color1, Command =  ""
                },
                Text =
                {
                    Text =  s.Shop.Skip(15 * (page + 1)).Count() > 0 ? $"{page +1}" : "", FontSize = 18, Align = TextAnchor.MiddleCenter, Color = color2
                },
                RectTransform =
                {
                  AnchorMin = $"0.44 0", AnchorMax = $"0.54 0.8"
                }
            }, "p");

            container.Add(new CuiButton
            {
                Button =
                {
                    Color = "0.89 0.81 0.70 0.5", Command =  ""
                },
                Text =
                {
                    Text = $"{page}", FontSize = 20, Align = TextAnchor.MiddleCenter, Color = color2
                },
                RectTransform =
                {
                  AnchorMin = $"0.33 0", AnchorMax = $"0.43 0.8"
                }
            }, "p");

            container.Add(new CuiButton
            {
                Button =
                {
                    Color = color3 , Command =""
                },
                Text =
                {
                    Text = page > 0 ? $"{page -1}": "", FontSize = 18, Align = TextAnchor.MiddleCenter, Color = color
                },
                RectTransform =
                {
                    AnchorMin = $"0.22 0", AnchorMax = $"0.32 0.8" 
                }
            }, "p"); 






            CuiHelper.AddUi(p, container);
        }


        private void OnServerInitialized()
        {
            PrintWarning("  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            PrintWarning($"     {Name} v{Version} loading");
            if (!ImageLibrary)
            {
                PrintError("   Install plugin: 'ImageLibrary'");
                Core.Interface.Oxide.UnloadPlugin(Name);
                return;
            }

            PrintWarning("        Plugin loaded - OK");
            PrintWarning("  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            BasePlayer.activePlayerList.ToList().ForEach(p =>
            {
                LoadImage(p.userID);
            });
        }

        void LoadImage(ulong id)
		{
            var g = GetStorage(id);
            int i = 0;
            foreach (var s in g.Shop)
            {
                
                var c = s.Item == null ? s.ImageCommand : "https://www.rustedit.io/images/imagelibrary/" + s.Item + ".png";

                 
                ImageLibrary.Call("AddImage", c, c);
            }
		}


        [ConsoleCommand("add")]
        private void CmdAdd(ConsoleSystem.Arg args)
        {
            
            switch (args.Args[0].ToLower())
            {
                case "page":
                    {
                        var player = args.Player();
                        var page = int.Parse(args.Args[1]);
                        CuiHelper.DestroyUi(player, Layer);
                        UI(player, page);
                        break;
                    }
                case "giv":
                    {
                        var player = args.Player();
                        var g = args.Args[1];
                        Give(player, g);
                        
                        break;
                    }

                case "item":
                    {
                        string user = args.Args[1];
                        ulong userid = Convert.ToUInt64(user);
                        string c = args.Args[3];
                        int count = Convert.ToInt32(c);
                        var player = BasePlayer.FindByID(userid);
                        Storage storage = GetStorage(userid);
                        
                        storage.Shop.Add(new Point 
                        {
                            key = RANDOMNUM(),
                            Item = args.Args[2],
                            CountItem = count,
                            Command = null,
                            ImageCommand = null
                        });
                        ImageLibrary.Call("AddImage", $"https://www.rustedit.io/images/imagelibrary/" + args.Args[2] + ".png", $"https://www.rustedit.io/images/imagelibrary/" + args.Args[2] + ".png");
                        SaveStorage(player);
                        break;
                    }
                case "command":
                    {
                        string user = args.Args[1];
                        ulong userid = Convert.ToUInt64(user);
                        var player = BasePlayer.FindByID(userid);
                        Storage storage = GetStorage(userid);
                        var msg = string.Empty;
                        for (var i = 3; i < args.Args.Length; i++)
                            msg = $"{msg} {args.Args[i]}";
                        storage.Shop.Add(new Point
                        {
                            key = RANDOMNUM(),
                            Item = null,
                            CountItem = 1,
                            Command = msg,
                            ImageCommand = args.Args[2]
                        });
                        ImageLibrary.Call("AddImage", args.Args[2], args.Args[2]);
                        SaveStorage(player);
                        break;
                    }
            }


        }

        void Give(BasePlayer p, string key)
        {
            Point item;
            Storage s = GetStorage(p.userID);
            foreach(var f in s.Shop)
            {
                if(f.key == key)
                {
                    
                    if(f.Item == null)
                    {

                        string command = f.Command.Replace("%steamid%", p.UserIDString);
                        rust.RunServerCommand(command);
                        s.Shop.RemoveAt(0);
                        SaveStorage(p);
                        
                        CuiHelper.DestroyUi(p, Layer);
                        
                        return;
                    }
                    rust.RunServerCommand($"inventory.giveto {p.userID} {f.Item} {f.CountItem}");
                    s.Shop.RemoveAt(0);
                    SaveStorage(p);
                    CuiHelper.DestroyUi(p, Layer);
                }
            }
        }

        private string RANDOMNUM() => UnityEngine.Random.Range(1, 99999999999999).ToString();
        private class Point
        {
            public string key;
            public string Item;
            public int CountItem;
            public string Command;
            public string ImageCommand;
        }

        class Storage
        {
            public List<Point> Shop = new List<Point>();
        }
        private Storage GetStorage(ulong userid)
        {
            Storage storage;
            if (datas.TryGetValue(userid, out storage)) return storage;

            string useridstring = userid.ToString();
            if (!Interface.Oxide.DataFileSystem.ExistsDatafile($"{Name}/{useridstring}"))
            {
                storage = new Storage();
                datas.Add(userid, storage);
                return storage;
            }

            storage = Interface.Oxide.DataFileSystem.ReadObject<Storage>($"{Name}/{useridstring}");
            datas.Add(userid, storage);
            return storage;
        }

        private void SaveStorage(BasePlayer player)
        {
            Storage storage;
            if (datas.TryGetValue(player.userID, out storage))
            {
                ServerMgr.Instance.StartCoroutine(Saving(player.UserIDString, storage));
            }
        }

        private IEnumerator Saving(string userid, Storage storage)
        {
            yield return new WaitForSeconds(1f);
            Interface.Oxide.DataFileSystem.WriteObject($"{Name}/{userid}", storage);
        }

        Dictionary<ulong, Storage> datas = new Dictionary<ulong, Storage>();

       
    }
}

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