Solved SendReply to player

Discussion in 'Rust Development' started by Reynostrum, Jan 24, 2016.

  1. Hi. I am trying to do something like this on C#:

    Code:
    SendReply(Reynostrum, "Something");
    This should send a message to Reynostrum.

    Is this possible?

    Thank you.
     
  2. Wulf

    Wulf Community Admin

    If via a command, this would work:
    Code:
    arg.ReplyWith(player, "message");
    There are also PrintToChat, SendReply, and other options via Oxide, but you'd need to have their player, not just their name. If you don't have the player, you'd need to loop through the BasePlayer.activePlayerList to get their player.
     
  3. Thanks again Wulf.

    I get this: "error CS0103: The name `arg' does not exist in the current context".
     
  4. Wulf

    Wulf Community Admin

    The name 'arg' only exists if you provide it, ie. view chat or console commands.

    Example: Rust
     
  5. Thanks Wulf.
    I did this and it's working like a charm:

    Code:
    foreach (BasePlayer player in BasePlayer.activePlayerList)
      {
      if (player.displayName.ToString() == Defensor)
      {
      SendReply(player, "something");
      }
      }
    
    Is there any way to make it "cleaner"?
     
  6. you should make the name a variable in the method instead of writing a method that will only ever work on 1 name

    Code:
    void MethodName(string name)
            {
                foreach (var player in BasePlayer.activePlayerList)
                {
                    if (player.displayName.ToLower() == name)
                        SendReply(player, "message");
                }
            }
    then say your method runs from a chat command ex. /testchat name

    Code:
    [ChatCommand("testchat")]
            void cmdtest(BasePlayer player, string command, string[] args)
            {
                if (args.Length == 0)
                    SendReply(player, "You need to enter a name");
                if (args.Length == 1)
                {
                    MethodName(args[0].ToLower());
                }
              
            }
    or a console command ex. testchat name

    Code:
    [ConsoleCommand("testchat")]
            void consoletest(ConsoleSystem.Arg arg)
            {
                if (arg.Args.Length == 0)
                    SendReply(arg, "You need to enter a name");
                if (arg.Args.Length == 1)
                {
                    MethodName(arg.Args[0].ToLower());
                }
              
            }
    i used the '.ToLower()' to change it to lowercase to account for if it is typed like; Name, name, NAME, NaMe etc otherwise it would case-sensitive
    also you dont need a .ToString() after displayname as it should already be a string
     
    Last edited by a moderator: Jan 24, 2016