1. Hello, guys, i want add my button to players gui, when they join on server.
    I tried to use hooks "onServInitialz..." and "onPlayerInitializ..." but button don`t adding to my gui after loggin on server. plz Help. how i can add this button for all players? This`s code without init.

    Code of plugin:
    Code:
    using Oxide.Game.Rust.Cui;
    using UnityEngine;
    namespace Oxide.Plugins{
        [Info("Enjamegui", "Enjame", "1.0.0")]
        class Enjamegui : RustPlugin
                {
                      [ChatCommand("cui")]
                      private void cmdCui(BasePlayer player, string command, string[] args){ 
                           var elements = new CuiElementContainer();
                           var myButton = new CuiButton
                               {
                               Button =
                               {
                               Command = "someCommand",
                               Color = "0.8 0.8 0.8 0.2"
                               },
                               RectTransform =
                              {
                               AnchorMin = "0.85 0.25",
                               AnchorMax = "0.99 0.30"
                              },
                              Text =
                              {
                               Text = "someButton",
                               FontSize = 22,
                               Align = TextAnchor.MiddleCenter
                              }
                              };
                               elements.Add(myButton);
                                CuiHelper.AddUi(player, elements);
                }
        }
    }
     

    Attached Files:

  2. Im not really that good with CUI's. But why are you requesting for "string command, string[] args)" when from what I can see its just sending the CUI to a player. And try using like
    Code:
    void OnPlayerInit(BasePlayer player)
    {
        cmdCUI(player);
    }[ChatCommand("chatCommand")]
    private void cmdCui(BasePlayer player)
    { 
        var elements = new CuiElementContainer();
        var myButton = new CuiButton
        {
            Button =
            {
                Command = "someCommand",
                Color = "0.8 0.8 0.8 0.2"
             },
             RectTransform =
             {
                AnchorMin = "0.85 0.25",
                AnchorMax = "0.99 0.30"
             },
             Text =
             {
                Text = "someButton",
                FontSize = 22,
                Align = TextAnchor.MiddleCenter
             }
        };
    elements.Add(myButton);
    CuiHelper.AddUi(player, elements);
    }
    
    [DOUBLEPOST=1458466064][/DOUBLEPOST]That solve your problem?
     
  3. thx, but button don`t added(, i can add button only with chatCommand

    Code:
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using UnityEngine;
    using Newtonsoft.Json;
    using Oxide.Core;
    using Oxide.Core.Plugins;
    using Oxide.Game.Rust.Cui;namespace Oxide.Plugins{
        [Info("Enjamegui", "Enjame", "1.0.0")]
         class Enjamegui : RustPlugin
                 {
                 void OnPlayerInit(BasePlayer player)
                {
                   cmdCui(player);
                }
                void OnServerInitialized()
                {
                     foreach (var player in BasePlayer.activePlayerList)
                  {
                     cmdCui(player);
                  }              }            [ChatCommand("enjkit")]
                private void cmdCui(BasePlayer player)
                {
                    var elements = new CuiElementContainer();
                    var myButton = new CuiButton
                    {
                     Button =
                     {
                       Command = "chat.say /help",
                     Color = "0.8 0.8 0.8 0.2"
                     },
                     RectTransform =
                     {
                     AnchorMin = "0.85 0.25",
                     AnchorMax = "0.99 0.30"
                     },
                     Text =
                     {
                     Text = "Button",
                     FontSize = 22,
                     Align = TextAnchor.MiddleCenter
                     }
                    };
                        elements.Add(myButton);
                        CuiHelper.AddUi(player, elements);
                }             }
         }
    [DOUBLEPOST=1458468515][/DOUBLEPOST]but after restart plugin button has been added to gui
    [DOUBLEPOST=1458477456,1458468302][/DOUBLEPOST]void OnServerInitialized() - work,
    void OnPlayerInit(BasePlayer player) - don`t work, connected players don`t recieve this button
     
  4. Its because OnPlayerInit is called when someone is joining. Try a foreach loop that detects every player online.
    [DOUBLEPOST=1458504313,1458493225][/DOUBLEPOST]So like,
    Code:
    void OnServerInitialized()
    {
        startTimer();
    }void startTimer()
    {
         timer.Once(1000, () =>
        {
            foreach(BasePlayer player in BasePlayer.activePlayerList)
            {
                cmdCui(player);
                startTimer();
            }
        }
    }
     
  5. DylanSMR - just use OnPlayerSleepEnded. But remember to destroy active GUI before redrawing it OnPlayerSleep otherwise it could stack up multiple UIs when Teleporting.
     
  6. @LaserHydra Ah true, never thought of using OnPlayerSleepEnded :p.