1. I created Button with CUI.

    Code:
                    elements.Add(new CuiButton
                    {
                        Button =
                        {
                            Command = ""
                            Color = "0.8 0.8 0.8 0.2"
                        },
                        RectTransform =
                        {
                            AnchorMin = $"0.76 {1 - 0.07*i + 0.006}",
                            AnchorMax = $"0.87 {1 - 0.07*(i - 1)}"
                        },
                        Text =
                        {
                            Text = "+",
                            FontSize = 22,
                            Align = TextAnchor.MiddleCenter
                        }
                    }, mainName);
                }
    What do i write in field "Command" to reference any method when i press the button?
     
  2. Wulf

    Wulf Community Admin

    You'd use a console command.
     
  3. Code:
    Command = "GUI.usewood",
    Code:
            [ConsoleCommand("GUI.usewood")]
            private void test(BasePlayer player)
            {
                player.ChatMessage("It works");
            }
    It dont work
     
  4. Wulf

    Wulf Community Admin

    Console commands do not use BasePlayer, they use ConsoleSystem.Arg for Rust.
     
  5. Code:
            [ConsoleCommand("GUI.usewood")]
            private void test(ConsoleSystem.Arg Args)
            {
                BasePlayer player = BasePlayer.FindByID(System.Convert.ToUInt64(Args.Args[0]));
                SendReply(player, "It works");
            }
    Still dont work
     
  6. Wulf

    Wulf Community Admin

    What exactly doesn't work? You can get the player from arg.Connection.player as BasePlayer by the way.
     
  7. I need to get username, who use this ConsoleCommand.
     
  8. Wulf

    Wulf Community Admin

    Okay, but what exactly isn't working about the code you previously provided which wasn't trying to do anything with the username?
     
  9. I am trying to send message to player but it dont work
     
  10. Code:
            [ConsoleCommand("GUI.usewood")]
            void YourConsoleCommand(ConsoleSystem.Arg arg)
            {
                var player = arg.Player();
                if(player == null) return;
                SendReply(player, "It Works!");
            }
     
  11. Dont work
     
  12. Maybe your doing something wrong then? Don't work isn't very descriptive. That code I gave you is nearly exact to one of my plugins I am working on.
     

  13. [DOUBLEPOST=1504465607][/DOUBLEPOST]The problem was that ConsoleCommand should be write with small letters...
     
  14. Wulf

    Wulf Community Admin

    The attribute is ConsoleCommand, lowercase will not get called. Only the command inside the quotes is case-insensitive.