1. I am very new to the scene of development, and even through research have yet to understand the correct use of the OnPlayerChat hook.

    What I plan on doing is as follows:
    When a player says a specific trigger word in chat, a bot prefixed [FriendBot] will reply with a message.

    I've tried doing things like

    function PLUGIN:OnPlayerChat(arg)
    -- here you will get the name of the player, and on second the steamid of the player
    print(arg.connection.player.displayName .. " - " .. rust.UserIDFromPlayer(arg.connection.player) .. ": Tried to talk but was muted")
    -- he you will get the full line of what he was trying to say
    print("He tried to say: " .. arg:GetString(0, "text"))

    -- return false = cancel the message
    return false
    end

    however, my Visual Studio Code underlined nearly the entire thing in red. I've tried taking pieces out, and starting with smaller bits, but no matter what, it always ends in tons of errors.

    Thanks.
     
  2. Wulf

    Wulf Community Admin

    That is Lua code you are trying to use, which will not work in a C# plugin.
     
  3. I see...
     
  4. Wulf

    Wulf Community Admin

  5. Problem is, I get a error saying I may be missing a reference assembly from the ConsoleSystem part. Below are the references I use.
     

    Attached Files:

  6. Wulf

    Wulf Community Admin

    Facepunch.Console.dll
     
  7. Thanks, I'll do a little more playing around with it.
     
  8. Ended up doing this. Thread Solved. (I can't figure out how to put solved in the title)

    Code:
    public class MrLonely : RustPlugin
        {
           
            [ChatCommand("lonely")]
            //Lonely Command
            void LonelyCommand(BasePlayer player)
            {
                SendMessage(player, "[FriendBot]: Hey, " + player.displayName + ", there is no reason to feel alone. I will always be here for you.");
            }
            void SendMessage(BasePlayer player, string msg, params object[] args)
            {
                PrintToChat(player, msg, args);
            }        private Dictionary<string, string> _phrases = new Dictionary<string, string>
            {
                ["I'm lonely"] = "/lonely"
            };        private void OnUserChat(IPlayer player, string message)
            {
                var basePlayer = player.Object as BasePlayer;
                basePlayer.SendConsoleCommand("chat.say \"/lonely\"");
            }
     
  9. Wulf

    Wulf Community Admin

    Something like this would make more sense and less cobbled together:
    Code:
    void OnPlayerChat(ConsoleSystem.Arg arg)
    {
       BasePlayer player = arg.Connection.player as BasePlayer;
       if (arg.Args.Contains("lonely"))
       {
           PrintToChat(player, "[FriendBot]: Hey, " + player.displayName + ", there is no reason to feel alone. I will always be here for you.");
       }
    }
     
  10. This code resulted in this error when attempting to load into the game.
    Code:
    Error while compiling: MrLonely.cs(69,13): error CS1514: Unexpected symbol `}', expecting `.' or `{'
    I'm not sure what causes it but there are no errors present in Microsoft Visual Studio.
    EDIT: I had it outside of public class...