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

FREE Kamycz3q_dc_code : 1.0.1 1.0.1

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

namespace Oxide.Plugins
{
    [Info("Kamycz3q_dc_code", "Kamycz3q", "1.0.1")]
    [Description("Discord Entrace Code with GUI")]

    
    
    class Kamycz3q_dc_code : RustPlugin
    {
        //classes 

        private class PluginConfig
        {
            public string UIMessage;
            public string code;
            public int UIMessageFontSize;
            public int CodeFontSize;
        }
        private class StoredData
        {
            public List<ulong> approvedPlayers = new List<ulong>();

            public StoredData()
            {

            }
        }

        //global vars
        private string UIName = "DiscordCodePanel";
        private PluginConfig config;
        private StoredData storedData;



        private void ShowCodeUIForPlayer(BasePlayer player)
        {
            CuiElementContainer container = new CuiElementContainer();

            container.Add(new CuiPanel
            {
                Image = { Color = "0.0 0.0 0.0 0.95"},
                RectTransform =
                {
                    AnchorMin = "0.0 0.0",
                    AnchorMax = "1.0 1.0",
                },
                CursorEnabled = true,
                KeyboardEnabled = true,
                
                
            }, "Overlay", UIName);

            container.Add(new CuiElement
            {
                Name = "CodeInput",
                Parent = UIName,
                Components =
                {
                    new CuiInputFieldComponent
                    {
                        Command = "ui.receivedccode",
                        Text = "Enter discord code...",
                        FontSize = config.CodeFontSize,
                        Color = "1 1 1 1",
                        Align = TextAnchor.MiddleCenter
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0.4 0.3",
                        AnchorMax = "0.6 0.4"
                    }
                }
            });



            container.Add(new CuiLabel
            {
                Text =
                {
                    Text = config.UIMessage,
                    FontSize = config.UIMessageFontSize,
                    Align = TextAnchor.MiddleCenter,
                    Color = "1 1 1 1"
                },
                RectTransform =
                {
                    AnchorMin = "0.2 0.5",
                    AnchorMax = "0.8 0.7"
                }



            }, UIName);

            CuiHelper.DestroyUi(player, UIName);
            CuiHelper.AddUi(player, container);
        }

        [ConsoleCommand("ui.receivedccode")]
        private void UIReceiveCode(ConsoleSystem.Arg arg)
        {
            BasePlayer plr = arg.Player();
            if (arg.HasArgs())
            {
                string code = arg.GetString(0);

                if (code == config.code)
                {
                    if (!storedData.approvedPlayers.Contains(plr.userID))
                    {
                        storedData.approvedPlayers.Add(plr.userID);
                    }
                    CuiHelper.DestroyUi(plr, UIName);
                }
            }

        }

        //mehcanics hooks
        void OnPlayerSleepEnded(BasePlayer player)
        {
            if (!storedData.approvedPlayers.Contains(player.userID))
            {
                ShowCodeUIForPlayer(player);

            }
        }

        void OnServerSave()
        {
            Interface.Oxide.DataFileSystem.WriteObject("ApprovedPlayers", storedData);
        }

        void Unload()
        {
            Interface.Oxide.DataFileSystem.WriteObject("ApprovedPlayers", storedData);
        }

        //initialization & close

        private PluginConfig GetDefaultConfig()
        {
            return new PluginConfig
            {
                UIMessage = "To play on our server you need to enter code from our discord\nCode is on the #xyz channel\nDiscord invite: discord.gg/123456",
                code = "1234",
                CodeFontSize = 15,
                UIMessageFontSize = 24,

            };
        }
 

        protected override void LoadDefaultConfig()
        {
            Config.WriteObject(GetDefaultConfig(), true);

        }

        private void Init()
        {
            Puts("Kamycz3q Discord Code Runned!");
            config = Config.ReadObject<PluginConfig>();

            //load db
            try
            {
                storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("ApprovedPlayers");
            } catch
            {
                storedData = new StoredData();
                storedData.approvedPlayers = new List<ulong>();
                Interface.Oxide.DataFileSystem.WriteObject("ApprovedPlayers", storedData);
            }
        }

    }
}

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