Plugin Structure
General Layout
- Metadata (
[Info]
,[Description]
) - REQUIRED BEFORE CLASS - Configuration (Settings, Default Values)
- Data Storage (Saving/Loading)
- Hooks (Rust & Oxide/Carbon Events)
- Commands (Chat & Console Commands)
- Helper Methods (Utility Functions)
note
This order is only a suggestion! Everyone has preferences that help them read their own code.
Example Plugin Structure
namespace Oxide.Plugins;
[Info("PluginName", "Author", "1.0.0")]
[Description("Short description of what the plugin does.")]
public class PluginName : RustPlugin
{
#region Configuration
private void LoadDefaultConfig() { }
#endregion
#region Data Storage
private Dictionary<string, int> playerScores = new();
private void SaveData() { }
private void LoadData() { }
#endregion
#region Hooks
private void OnPlayerConnected(BasePlayer player) { }
private void OnEntityDeath(BaseEntity entity, HitInfo info) { }
#endregion
#region Commands
[ChatCommand("score")]
private void CmdShowScore(BasePlayer player, string command, string[] args) { }
#endregion
#region Helper Methods
private void LogMessage(string message) => Puts($"[PluginName] {message}");
#endregion
}
Why This Order?
- Metadata comes first for easy identification.
- Configuration & Data should load early.
- Hooks & Commands define plugin behavior.
- Helper Methods stay at the bottom for reusability. Following this structure keeps your plugin organized, readable, and easy to modify.