1. Dear coders,

    Long description:

    I'm currently trying to learn a little bit more about writing plugins for Oxide (Rust in particular) but I've made very little progress due to lack of time and lack of extensive tutorials and documentation. Currently I'm trying to figure out how to make a plugin that sends a chat message (SendReply) to a player that repairs one of his structures with the vanilla hammer for the first time (I think it should trigger on 'OnStructureRepair' if I'm not mistaking?). As far as I know it requires a data file to register if a player already repaired something before.

    However, I can not figure out how to correctly use data files and libraries in Oxide.

    I've learned a lot from other plugins and used them as good examples on how to code plugins but I can't figure this one out. This is why I would love someone to either explain this to me or write this plugin so I can use it as a textbook example of how to use the things I need.

    Any information or links to tutorials on how to write Oxide plugins would be awesome as well! (Feel free to PM me or drop me a message in this post)

    Short description:

    I require a plugin that sends a chat message to a player when he repairs his buildings for the very first time only.


    Thanks in advance,

    iShot
     
  2. Very simple write up. Get's the message to send to the player from the language file. Stores a list of players that have already repaired a structure before in the data file. Adds the player to the list when they repair something for the first time then sends them the message. I haven't tested it, but I see no reason it shouldn't work.

    Code:
    using System;
    using System.Collections.Generic;using Oxide.Core;namespace Oxide.Plugins
    {
        [Info("FirstRepairMessage", "JoeSheep", "1.0.0")]
        [Description("Simple Plugin For Displaying A Message The First Time A Player Repairs Something.")]
        class FirstRepairMessage : RustPlugin
        {
            #region Data
            void SaveData() => Interface.Oxide.DataFileSystem.WriteObject("FirstRepairMessageData", storedData);        void LoadSavedData()
            {
                storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("FirstRepairMessageData");
                if (storedData == null)
                {
                    PrintWarning("FirstRepairMessage's datafile is null. Recreating data file...");
                    storedData = new StoredData();
                    SaveData();
                    timer.Once(5, () =>
                    {
                        PrintWarning("Reloading...");
                        ConsoleSystem.Run(ConsoleSystem.Option.Server, "reload FirstRepairMessage");
                    });
                }
            }        class StoredData
            {
                public List<ulong> RepairedBefore = new List<ulong>();
                public StoredData()
                {
                }
            }        StoredData storedData;
            void OnServerSave() => SaveData();
            #endregion        #region Lang
            void LoadDefaultMessages()
            {
                lang.RegisterMessages(new Dictionary<string, string>
                {
                    {"FirstRepairMessage", "You've repaired a structure for the first time!" },
                }, this);
            }
            #endregion        #region Init/Unload
            void OnServerInitialized()
            {
                #if !RUST
                throw new NotSupportedException("This plugin does not support this game.");
                #endif            LoadSavedData();
                LoadDefaultMessages();
            }        void Unload() => SaveData();
            #endregion        #region Hook
            void OnStructureRepair(BaseCombatEntity entity, BasePlayer player)
            {
                if (!storedData.RepairedBefore.Contains(player.userID))
                {
                    storedData.RepairedBefore.Add(player.userID);
                    SaveData();
                    SendReply(player, Lang("FirstRepairMessage", player.UserIDString));
                }
            }
            #endregion        #region Functions
            string Lang(string key, string userId = null) => lang.GetMessage(key, this, userId);
            #endregion
        }
    }
    Also shouldn't I be able to attach files to thread replies?
     
  3. That is a perfect script to learn the basics of language files and data files. Thank you very much for this, it's a treasure of information!