### Basic README File Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md An example of a basic README file for an Oxide plugin, detailing its purpose, features, installation, usage, and dependencies. ```markdown # ExamplePlugin for Rust This plugin allows players to do XYZ in Rust. ## Features - Feature 1 - Feature 2 ## Installation 1. Download the .cs file and place it in your Oxide plugins folder. 2. Restart your Rust server. 3. The plugin will compile and load automatically. ## Usage Use `/command` in the in-game chat to do XYZ. ## Dependencies This plugin requires Oxide.Rust to work properly. ``` -------------------------------- ### Example Plugin Configuration Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/owners/configure-plugins.md A basic example of a JSON configuration file for a plugin, showing key-value pairs for settings. ```json { "EnableFeature": true, "MessageDelay": 5, "WelcomeMessage": "Welcome to our server!" } ``` -------------------------------- ### Start Development Server Source: https://github.com/oxidemod/oxide.docs/blob/main/README.md Starts the VitePress development server for live previewing of documentation changes. ```bash npm run docs:dev ``` -------------------------------- ### Rust Server Configuration Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/owners/setup-server.md Example of a server.cfg file used to manage Rust server settings like hostname, description, header image, and URL. ```txt server.hostname "My Awesome Rust Server" server.description "Welcome to my awesome Rust server! Enjoy your stay." server.headerimage "http://example.com/myheaderimage.jpg" server.url "http://example.com" ``` -------------------------------- ### Good Description Examples Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/reviewers/guidelines/attribute-definitions.md Examples of effective plugin descriptions that are concise and informative. ```text "Prevents F1 item giving notices from showing in the chat" (GOOD) Reason: Brief but contains all information required to understand what the plugin does. "Teleports players to a safe location when they violate antihack InsideTerrain." (GOOD) Reason: Contains all information needed to understand what the plugin does and when/why it does this. "Allows players to send private messages to each other." (GOOD) Reason: Brief but contains all information required to understand what the plugin does. Other features can be inferred or found in the documentation. "Splits up resources in furnaces automatically and shows useful furnace information" (GOOD) Reason: Explains core features in not too many words. ``` -------------------------------- ### Install Dependencies Source: https://github.com/oxidemod/oxide.docs/blob/main/README.md Installs project dependencies using npm. Ensure Node.js v20 or higher is installed. ```bash npm install ``` -------------------------------- ### CuiElement Preset Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/basic-cui.md Demonstrates creating a basic CuiElement with a name, parent, and a list of components including RectTransform and NeedsCursor. ```csharp new CuiElement { Name = "NameOfElement", Parent = "NameOfParent", Components = { new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 -50" }, new CuiNeedsCursorComponent(), ... } }, ``` -------------------------------- ### CuiPanel Preset Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/basic-cui.md Shows how to create a CuiPanel for displaying images or backgrounds, specifying image color and RectTransform properties. ```csharp new CuiPanel { Image = { Color = "0.3 0.3 0.3 0.8" }, RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-200 -300", OffsetMax = "200 300" }, }, ``` -------------------------------- ### Single Line Comment Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Illustrates the use of single-line comments starting with '//'. ```csharp // Increment the counter counter++; ``` -------------------------------- ### Bad Description Examples Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/reviewers/guidelines/attribute-definitions.md Examples of ineffective plugin descriptions that are too short or lack necessary detail. ```text "VPN Checker" (BAD) Reason: Too short, not descriptive enough. Alternative: Kick, Ban or run a custom command on players that connect using a VPN. "Plugin to delete F15e jets" (BAD) Reason: Too short, re-states that it is a plugin, not descriptive enough. Alternative: Delete all F15 jets through a single chat command. "This plugin allows creation of weapon that does a critical hit on scientists. Those with permissions can spawn the weapon, to sell in a shop or put in a customize vending machine." (BAD) Reason: Too long, re-states that it is a plugin. Alternative: Adds a weapon that does increased damage on scientists. ``` -------------------------------- ### Changelog Structure Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md A standard format for a plugin's changelog file, detailing changes for each version. ```markdown # Changelog ## [1.0.1] - 2023-06-20 ### Added - Added new feature XYZ. ### Fixed - Fixed bug related to feature ABC. ## [1.0.0] - 2023-06-19 - Initial release. ``` -------------------------------- ### CuiLayoutElementComponent Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/basic-cui.md Sets up a layout element component to manage flexible and minimum sizing properties for UI elements within a layout system. ```csharp new CuiLayoutElementComponent { FlexibleHeight = 0f, FlexibleWidth = 0f, IgnoreLayout = false, MinHeight = -1f, MinWidth = -1f, PreferredHeight = 0f, PreferredWidth = 0f, }, ``` -------------------------------- ### Implement CuiCountdownComponent and Initial UI Setup Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/example-countdown.md This snippet shows how to create a UI container with various elements, including a countdown timer, buttons, and text panels. It sets up the initial state of the UI, including hiding certain elements by default. ```csharp private void TestUi(BasePlayer player) { CuiElementContainer elements = new CuiElementContainer(); elements.Add(new CuiElement { Name = "UI_CountDown", Parent = "Overall", Components = { new CuiImageComponent { Sprite = "Assets/Content/UI/UI.Background.Tile.psd", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat", Color = "0 0 0 0.85", }, new CuiRectTransformComponent { AnchorMin = "0.30 0.6", AnchorMax = "0.7 0.9" , }, new CuiNeedsCursorComponent(), } }); elements.Add(new CuiButton { Button = { Color = "0.8 0.2 0.2 0.8", Command = "closeupdate" }, RectTransform = { AnchorMin = "0.91 0.90", AnchorMax = "0.98 0.98" }, Text = { Text = "Close", FontSize = 8, Align = TextAnchor.MiddleCenter }, }, "UI_CountDown", "UICloseButton"); // Hide close button by default // Note that CuiButton does not permit direct access to Update and ActiveSelf // This is why the flags are updated using a CuiElement elements.Add(new CuiElement { Name = "UICloseButton", ActiveSelf = false, Update = true, }); elements.Add(new CuiElement { Name = "SubPanel1", Parent = "UI_CountDown", Components = { new CuiTextComponent { Text = "Text element to change after countdown", FontSize = 14, Align = TextAnchor.UpperCenter, Color ="1 0 0 1" }, new CuiOutlineComponent { Distance = "1 1", Color = "0 0 0 1" }, new CuiRectTransformComponent { AnchorMin = "0.1 0.85", AnchorMax = "0.90 0.95" }, } }); elements.Add(new CuiElement { Name = "SubPanel2", Parent = "UI_CountDown", Components = { new CuiTextComponent { Text = "Text element to remove after downdown", FontSize = 14, Align = TextAnchor.UpperCenter, Color ="0 0 1 1" }, new CuiOutlineComponent { Distance = "1 1", Color = "0 0 0 1" }, new CuiRectTransformComponent { AnchorMin = "0.1 0.75", AnchorMax = "0.9 0.85" }, } }); elements.Add(new CuiElement { Name = "SubPanel3", Parent = "UI_CountDown", Components = { new CuiRectTransformComponent { AnchorMin = "0.1 0.55", AnchorMax = "0.9 0.75" }, } }); elements.Add(new CuiElement { Name = "CountDownElement", Parent = "SubPanel3", FadeOut = 2.0f, Components = { new CuiTextComponent{ Text="Time left : %TIME_LEFT%", FontSize=14, Font="RobotoCondensed-Bold.ttf", Align=TextAnchor.MiddleCenter, Color="1 1 1 1" }, new CuiCountdownComponent { TimerFormat = TimerFormat.HoursMinutesSeconds, Step = 1, EndTime = 0f, StartTime = 10f, Interval = 1f, FadeIn = 2.0f, DestroyIfDone = true, Command = "testCountDown.CountdownUi ", }, } }); CuiHelper.AddUi(player, elements); } ``` -------------------------------- ### Implement Configuration Methods Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/my-first-plugin.md Implement methods to get default configuration values, load existing configurations, load default configurations, and save the current configuration to a JSON file. ```csharp // Existing Code... private Configuration GetDefaultConfig() { return new Configuration { ReplyMessage = "Hello" }; } protected override void LoadConfig() { base.LoadConfig(); try { _configuration = Config.ReadObject(); if (_configuration == null) LoadDefaultConfig(); } catch { PrintError("Configuration file is corrupt! Check your config file at https://jsonlint.com/"); LoadDefaultConfig(); return; } SaveConfig(); } protected override void LoadDefaultConfig() => _configuration = GetDefaultConfig(); protected override void SaveConfig() => Config.WriteObject(_configuration); // Existing code... ``` -------------------------------- ### Chat Command Definition Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Example of how to register and define a chat command. Commands should be lowercase with underscores. ```csharp [ChatCommand("my_command")] private void MyCommand(BasePlayer player, string command, string[] args) { // Your code here } ``` -------------------------------- ### Example Language JSON File Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/data-storage.md This is an example of a JSON file used for storing language messages. Server owners can customize these files to override default messages. ```json { "MSG1": "English string 1", "MSG2": "English string 1" } ``` -------------------------------- ### XML Documentation Comment Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Shows how to use XML documentation comments (///) for methods, which can be parsed by IDEs and documentation generators. ```csharp /// /// This method does something interesting. /// /// The first parameter. /// Returns a string that represents something interesting. public string DoSomethingInteresting(int param1) { //... } ``` -------------------------------- ### Send a Basic GET Request Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/libraries/webrequests.md Use Enqueue to send a simple GET request to a URL. The callback handles the response or errors. ```csharp webrequest.Enqueue("http://www.google.com/search?q=umod", null, (code, response) => { if (code != 200 || response == null) { Puts($"Couldn't get an answer from Google!"); return; } Puts($"Google answered: {response}"); }, this, RequestMethod.GET); ``` -------------------------------- ### Update and Install Rust Server via SteamCMD Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/owners/setup-server.md This batch script automates the process of downloading and updating the Rust dedicated server files using SteamCMD. Replace the directory path with your desired installation location. ```batch @echo off start "" steamcmd.exe +login anonymous +force_install_dir "C:\rust_server" +app_update 258550 -beta public validate +quit ``` -------------------------------- ### C# Code Comment Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Example of using C# comments to explain complex or non-obvious code logic, such as checking player permissions. ```csharp // Checking if the player has permission to use the command if (!player.HasPermission("exampleplugin.use")) { // Send a message to the player if they do not have permission SendReply(player, "You do not have permission to use this command."); return; } ``` -------------------------------- ### Linux Rust Server Startup Script Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/owners/setup-server.md Use this bash script to start your Rust dedicated server on Linux. Ensure you replace placeholder values with your server's specific details. ```bash #!/bin/bash ./RustDedicated -batchmode +server.port 28015 +server.level "Procedural Map" +server.seed 1234 +server.worldsize 4000 +server.maxplayers 100 +server.hostname "Your Server Name" +server.description "Description Here" +server.url "http://yourwebsite.com" +server.headerimage "http://yourwebsite.com/serverimage.jpg" +server.identity "youridentity" +rcon.port 28016 +rcon.password "yourrconpassword" -logfile "output.txt" ``` -------------------------------- ### Multi-line Comment Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Demonstrates multi-line comments enclosed by '/*' and '*/'. Useful for lengthy explanations or temporarily disabling code. ```csharp /* This is a multi-line comment spanning several lines */ ``` -------------------------------- ### Add Library References Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/my-first-plugin.md Add references to the necessary Oxide Core and Unity Engine libraries at the start of your plugin file. ```csharp using Oxide.Core; using UnityEngine; ``` -------------------------------- ### Plugin Versioning with [Info] Attribute Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Specify plugin version using the [Info] attribute. This example sets the plugin name, author, and version to '1.0.0'. ```csharp [Info("ExamplePlugin", "AuthorName", "1.0.0")] public class ExamplePlugin : RustPlugin { // Your plugin code goes here... } ``` -------------------------------- ### Basic Unit Test in C# Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/best-practices.md An example of a basic unit test for a hypothetical command in a Rust plugin. It demonstrates arranging the test environment, acting by executing the command, and asserting the expected outcome. ```csharp // Example of a basic unit test in C# [TestClass] public class MyPluginTests { [TestMethod] public void TestCommandBehavior() { // Arrange var plugin = new MyPlugin(); var player = new FakePlayer(); // Act plugin.MyCommand(player, null, null); // Assert Assert.AreEqual("Expected response", player.LastMessage); } } ``` -------------------------------- ### Related Code Grouping: Init and Command Handler Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Keep related code together. This example shows an Init method registering a command handled by HelloCommand. ```csharp public void Init() { // Initialization code here... // Register the commands after initialization. AddCovalenceCommand("hello", "HelloCommand"); } private void HelloCommand(IPlayer player, string command, string[] args) { player.Message("Hello, world!"); } ``` -------------------------------- ### Example Bug Report Format Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/community/reporting-issues.md Use this format to report bugs. Include a clear title, reproducibility steps, expected and actual results, and environment details. ```text Title: Players lose inventory when using /home command near water Reproducibility: 100% reproducible using the steps below Steps to Reproduce: 1. Install Teleport plugin v2.3.4 2. Configure home teleport delay to 5 seconds 3. Have a player stand near water (within 2 blocks) 4. Have the player use the /home command 5. During the 5 second teleport delay, have the player move slightly 6. Player teleports but inventory is lost Expected Result: Player teleports with inventory intact Actual Result: Player teleports but inventory items are dropped at the original location or disappear entirely Environment: - Game Version: v2022.5.1 - Oxide Version: 2.0.5741 - Teleport Plugin Version: 2.3.4 - Config file attached in comments Additional Notes: This only happens near water, not near lava or other liquids. Log shows no errors during the process. ``` -------------------------------- ### Register a Permission Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/libraries/permissions.md Register a new permission for your plugin. The permission name must start with your plugin's name. ```csharp namespace Oxide.Plugins { [Info("MyFirstPlugin", "Author Name", "1.0.0")] public class MyFirstPlugin : RustPlugin { void Init() => permission.RegisterPermission("myfirstplugin.use", this); } } ``` -------------------------------- ### CuiCountdownComponent Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/basic-cui.md Configures a countdown timer that sends a command upon completion. It can be set to destroy itself after finishing and allows customization of its appearance and behavior. ```csharp CuiCountdownComponent Countdown = new CuiCountdownComponent { TimerFormat = TimerFormat.HoursMinutesSeconds, Step = 1, EndTime = 0f, StartTime = 100f, Interval = 1f, FadeIn=2.0f, Command = "Cmd.CountdownUi " + player.userID.ToString() }; elements.Add(new CuiElement { Name = "NameOfElement", Parent = "NameOfPanel", FadeOut = 1.0f, Components = { new CuiTextComponent{Text="Time left : %TIME_LEFT%", FontSize=14, Font="RobotoCondensed-Bold.ttf", Align=TextAnchor.MiddleCenter, Color="1.0 1.0 1.0 1.0" }, Countdown } }); ``` -------------------------------- ### Set Server Language Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/core/commands/miscellaneous.md Sets the server language using a two-letter language code. Example uses 'en' for English. ```bash oxide.lang en ``` -------------------------------- ### CUI Positioning Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/example-cui-position.md This C# code snippet creates and adds four UI elements to a player. It demonstrates different positioning techniques using CuiRectTransformComponent, including AnchorMin/Max and OffsetMin/Max, to show how they behave with varying screen resolutions. ```csharp private void TestUi(BasePlayer player) { CuiElementContainer elements = new CuiElementContainer(); elements.Add(new CuiElement { Name = "UI_Rectangle1", Parent = "Overall", Components = { new CuiImageComponent { Sprite = "Assets/Content/UI/UI.Background.Tile.psd", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat", Color = "0.7 0.7 0.7 0.3", }, new CuiRectTransformComponent { AnchorMin = "0.34 0.02", AnchorMax = "0.64 0.105" , }, } }); elements.Add(new CuiElement { Name = "UI_Rectangle2", Parent = "Overall", Components = { new CuiImageComponent { Sprite = "Assets/Content/UI/UI.Background.Tile.psd", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat", Color = "0.7 0.1 0.1 0.3", }, new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-204 -368", OffsetMax= "179 -303", }, } }); elements.Add(new CuiElement { Name = "UI_Rectangle3", Parent = "Overall", Components = { new CuiImageComponent { Sprite = "Assets/Content/UI/UI.Background.Tile.psd", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat", Color = "0.1 0.7 0.1 0.3", }, new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "435 15", OffsetMax= "80 450", }, } }); elements.Add(new CuiElement { Name = "UI_Rectangle4", Parent = "Overall", Components = { new CuiImageComponent { Sprite = "Assets/Content/UI/UI.Background.Tile.psd", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat", Color = "0.1 0.1 0.7 0.3", }, new CuiRectTransformComponent { AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-204 15", OffsetMax= "179 80", }, } }); CuiHelper.AddUi(player, elements); } ``` -------------------------------- ### C# Console Warning Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Demonstrates the good practice of using PrintWarning for non-critical error messages in C# for Oxide plugins. ```csharp // Good practice if(somethingWentWrong) { PrintWarning("Something went wrong when executing this command"); } ``` -------------------------------- ### Pooling Other Objects (Stack) Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/pooling.md Example of pooling a Stack using the FreeUnsafe method. The stack is obtained from the pool and then freed. ```csharp Stack ovenStack = Pool.Get>(); // Do some stuff with ovenStack Pool.FreeUnsafe(ref ovenStack); ``` -------------------------------- ### Observer Pattern Example with Oxide Hook Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/best-practices.md This C# snippet demonstrates the Observer pattern using an Oxide hook. The plugin 'observes' the server for the OnPlayerConnected event and reacts by printing a message. ```csharp public class MyPlugin : RustPlugin { void OnPlayerConnected(BasePlayer player) { Puts($"{player.displayName} has connected"); } } ``` -------------------------------- ### Info Attribute Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/reviewers/guidelines/attribute-definitions.md The main plugin class must include the [Info] attribute with the plugin's title, author's username, and version number. ```csharp using Oxide.Core.Plugins; namespace Oxide.Plugins { [Info("My Plugin Title", "MyUsername", "1.0.0")] [Description("A brief description of what the plugin does.")] public class MyPlugin : CovalencePlugin { // Plugin code here } } ``` -------------------------------- ### Basic JSON Language File Structure Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/owners/localization.md A simple example of a JSON language file used for localization. It maps keys to their corresponding translated string values. ```json { "Hello": "Hello", "WelcomeMessage": "Welcome to our Rust server!" } ``` -------------------------------- ### CuiContentSizeFitterComponent Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/basic-cui.md Configures a content size fitter component to control how UI elements adjust their size based on content. Useful for dynamic layouts. ```csharp new CuiContentSizeFitterComponent { HorizontalFit = ContentSizeFitter.FitMode.Unconstrained, VerticalFit = ContentSizeFitter.FitMode.Unconstrained, }, ``` -------------------------------- ### CUI Image Component Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/basic-cui.md Renders an image using a sprite, material, and color. Useful for displaying static images or icons within the UI. Specify color, fade-in time, and material. ```csharp new CuiImageComponent { Color = "0.30 0.30 0.30 1.0", FadeIn = 0.1f, Material = "assets/content/ui/uibackgroundblur.mat" }, ``` -------------------------------- ### Build for Production Source: https://github.com/oxidemod/oxide.docs/blob/main/README.md Builds the documentation for production deployment. ```bash npm run docs:build ``` -------------------------------- ### TODO Comment Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Example of using a TODO comment to mark areas of code that require future attention or implementation. ```csharp // TODO: Implement this feature ``` -------------------------------- ### Preview Production Build Source: https://github.com/oxidemod/oxide.docs/blob/main/README.md Previews the production build of the documentation locally. ```bash npm run docs:preview ``` -------------------------------- ### Windows Batch Script for Rust Server Startup Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/owners/setup-server.md A basic batch script for Windows to automate the startup of a Rust dedicated server with specified parameters. It includes settings for port, map, seed, player count, server identity, RCON, and logging. ```batch @echo off :start RustDedicated.exe -batchmode +server.port 28015 +server.level "Procedural Map" +server.seed 1234 +server.worldsize 4000 +server.maxplayers 100 +server.hostname "Your Server Name" +server.description "Description Here" +server.url "http://yourwebsite.com" +server.headerimage "http://yourwebsite.com/serverimage.jpg" +server.identity "youridentity" +rcon.port 28016 +rcon.password "yourrconpassword" -logfile "output.txt" goto start ``` -------------------------------- ### Command Shortcuts Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/owners/permissions.md Demonstrates the use of the 'o.' prefix as a shortcut for Oxide commands. ```text o.grant ``` -------------------------------- ### Advanced GET Request with Custom Headers and Timeout Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/webrequests.md Demonstrates sending a GET request with custom headers and a specific timeout. The callback function is encapsulated in a separate method. ```csharp [Command("get")] private void GetRequest(IPlayer player, string command, string[] args) { // Set a custom timeout (in milliseconds) float timeout = 200f; // Set some custom request headers (eg. for HTTP Basic Auth) Dictionary headers = new Dictionary { { "header", "value" } }; webrequest.Enqueue("http://www.google.com/search?q=umod", null, (code, response) => GetCallback(code, response, player), this, RequestMethod.GET, headers, timeout); ``` ```csharp private void GetCallback(int code, string response, IPlayer player) { if (response == null || code != 200) { Puts($"Error: {code} - Couldn't get an answer from Google for {player.Name}"); return; } Puts($"Google answered for {player.Name}: {response}"); } ``` -------------------------------- ### Send an Advanced GET Request with Custom Headers and Timeout Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/libraries/webrequests.md Demonstrates sending a GET request with custom headers and a specific timeout. The callback function processes the response. ```csharp [Command("get")] private void GetRequest(IPlayer player, string command, string[] args) { // Set a custom timeout (in milliseconds) float timeout = 200f; // Set some custom request headers (eg. for HTTP Basic Auth) Dictionary headers = new Dictionary { { "header", "value" } }; webrequest.Enqueue("http://www.google.com/search?q=umod", null, (code, response) => GetCallback(code, response, player), this, RequestMethod.GET, headers, timeout); } private void GetCallback(int code, string response, IPlayer player) { if (response == null || code != 200) { Puts($"Error: {code} - Couldn't get an answer from Google for {player.Name}"); return; } Puts($"Google answered for {player.Name}: {response}"); } ``` -------------------------------- ### Create a CuiOutlineComponent Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/basic-cui.md Sets up a CuiOutlineComponent with a specified distance, color, and graphic alpha usage. ```csharp new CuiOutlineComponent { Distance = "1.0 1.0", Color = "1 1 1 1", UseGraphicAlpha = true }, ``` -------------------------------- ### Get Group Title Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/permissions.md Retrieves the display title of a specified group. ```csharp string GroupTitle = permission.GetGroupTitle("GroupName"); ``` -------------------------------- ### Get All Registered Permissions Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/permissions.md Retrieves an array of all permission names that have been registered on the server. ```csharp string[] permissions = permission.GetPermissions(); ``` -------------------------------- ### Create and Display a Workbench Overlay UI Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/basic-cui.md This snippet demonstrates how to create a CuiElementContainer, add a panel and label components, and display the UI specifically when a workbench is open using the 'TechTree' layer. ```csharp private const string UI_WORKBENCHOVERLAY = "UI_WorkbenchOverlay"; private void WorkbenchUi(BasePlayer player) { CuiElementContainer elements = new CuiElementContainer(); string panel = elements.Add(new CuiPanel { Image = { Color = "0 0 0 0.63", Sprite = "assets/content/materials/highlight.png", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat" }, RectTransform = { AnchorMin = "0.1 0.7", AnchorMax = "0.9 0.8" } }, "TechTree", UI_WORKBENCHOVERLAY); elements.Add(new CuiLabel { Text = { Text = "Message to overlay in workbench", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" }, RectTransform = { AnchorMin = "0.02 0.5", AnchorMax = "0.98 0.98" } }, panel); elements.Add(new CuiElement { Parent = panel, Components = { new CuiTextComponent { Text = "Workbench view", FontSize = 24, Align = TextAnchor.MiddleCenter, Color ="1 0 0 1" }, new CuiOutlineComponent { Distance = "0.5 0.5", Color = "1 1 1 1" }, new CuiRectTransformComponent { AnchorMin = "0.02 0.02", AnchorMax = "0.98 0.5" }, } }); CuiHelper.AddUi(player, elements); } ``` -------------------------------- ### List All Plugins Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/core/commands/plugin.md Lists all loaded and failed plugins, showing their name, version, author, hooktime, and filename. Displays the reason for failed loads. ```text Listing 2 plugins: 01 "My awesome plugin" (1.0.0) by Oxide (0.04s) - MyAwesomePlugin.cs 02 "My second plugin" (1.5.3) by Oxide (0.55s) - MySecondPlugin.cs ``` -------------------------------- ### Get User Permissions Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/permissions.md Retrieves all permissions directly granted to a specific player, identified by their ID. ```csharp string[] UserPermissions = permission.GetUserPermissions("playerID"); ``` -------------------------------- ### Get Parent Group Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/permissions.md Retrieves the name of the parent group for a given group. This is used for permission inheritance. ```csharp string GroupParent = permission.GetGroupParent("GroupName"); ``` -------------------------------- ### Define Plugin Metadata and Class Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/my-first-plugin.md Define the namespace, plugin metadata (name, author, version) using attributes, and create a class that inherits from RustPlugin. ```csharp namespace Oxide.Plugins; [Info("MyFirstPlugin", "Author Name", "1.0.0")] public class MyFirstPlugin : RustPlugin { // Plugin logic goes here } ``` -------------------------------- ### Create a CuiTextComponent Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/basic-cui.md Initializes a CuiTextComponent with text content, font size, alignment, and color. ```csharp new CuiTextComponent { Text = "Workbench view", FontSize = 24, Align = TextAnchor.MiddleCenter, Color ="1 0 0 1" }, ``` -------------------------------- ### Required Plugin Comment Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/attributes.md Indicates a plugin dependency using a comment. The plugin will not start if a required plugin is absent. ```csharp //Requires: Backpacks ``` -------------------------------- ### Open MySQL Connection Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/database.md Establishes a new MySQL database connection. Requires server address, database name, and credentials. ```csharp Core.MySql.Libraries.MySql sqlLibrary = Interface.Oxide.GetLibrary(); Connection sqlConnection = sqlLibrary.OpenDb("localhost", 3306, "umod", "username", "password", this); ``` -------------------------------- ### Get All Groups Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/permissions.md Retrieves an array of all group names currently registered on the server. This can be used to iterate through existing groups. ```csharp string[] groups = permission.GetGroups(); ``` -------------------------------- ### Object Array Pooling with Oxide.Core.ArrayPool (Obsolete) Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/pooling.md Shows how to use the obsolete Oxide.Core.ArrayPool for creating and freeing object arrays, which avoids garbage collection. ```csharp // Note that Oxide.Core.ArrayPool is obsolete object[] objectArray = ArrayPool.Get(2); ArrayPool.Free(objectArray); object[] anotherObjectArray = ArrayPool.Get(4); ArrayPool.Free(anotherObjectArray); ``` -------------------------------- ### Monitor Player Connection Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/server-lifecycle.md The OnPlayerConnected hook allows monitoring and actions after an IPlayer is initialized. This example kicks a specific player. ```csharp void OnPlayerConnected(IPlayer player) { if (player.Name == "Calytic") { player.Kick(); } } ``` -------------------------------- ### Create a CuiButtonComponent Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/basic-cui.md Instantiates a CuiButtonComponent with specified color, command, close action, and material. ```csharp new CuiButtonComponent { Color = "0.20 0.30 0.40 1.0", Command = "CommandName", Close = "UI.ClosePanelName", Material = "assets/icons/iconmaterial.mat" }, ``` -------------------------------- ### Sample Language File Directory Structure Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/owners/localization.md Illustrates the typical location of language files within the Oxide plugin system. Language files are organized by language code in the 'oxide/lang' directory. ```txt └── server └── rustserver └── oxide └── lang └── en ├── SamplePlugin.json └── AnotherPlugin.json └── es ├── SamplePlugin.json └── AnotherPlugin.json ``` -------------------------------- ### Get Group Rank Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/permissions.md Retrieves the numerical rank of a specified group. Lower numbers typically indicate higher priority. ```csharp int GroupRank = permission.GetGroupRank("GroupName"); ``` -------------------------------- ### CuiGridLayoutGroupComponent Example Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/basic-cui/basic-cui.md Defines a grid layout group with specific cell sizes, alignment, constraints, padding, spacing, and axis/corner settings. ```csharp new CuiGridLayoutGroupComponent { CellSize = "100 100", ChildAlignment = TextAnchor.UpperLeft, Constraint = GridLayoutGroup.Constraint.Flexible, ConstraintCount = 1, Padding = "x", Spacing = "0 0", StartAxis = GridLayoutGroup.Axis.Horizontal, StartCorner = GridLayoutGroup.Corner.UpperLeft }, ``` -------------------------------- ### Implement Chat Command with Permissions Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/my-first-plugin.md This C# code snippet demonstrates how to register a chat command and enforce player permissions using Oxide's permission system. It checks if a player has the 'myfirstplugin.hello' permission before allowing them to use the /hello command. ```csharp namespace Oxide.Plugins; [Info("MyFirstPlugin", "Author Name", "1.0.0")] public class MyFirstPlugin : RustPlugin { void Init() { permission.RegisterPermission("myfirstplugin.hello", this); } [ChatCommand("hello")] private void HelloCommand(BasePlayer player, string command, string[] args) { if(!permission.UserHasPermission(player.UserIDString, "myfirstplugin.hello")) { PrintToChat(player, "You don't have permission to use this command!"); return; } PrintToChat(player, "Hello, welcome to the world of Rust modding!"); } } ``` -------------------------------- ### Basic Object Array Allocation Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/pooling.md Demonstrates the standard way of creating object arrays, which requires garbage collection. ```csharp var objectArray = new object[2]; var anotherObjectArray = new object[2]; ``` -------------------------------- ### AutoPatch and HarmonyPatch Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/attributes.md Automatically applies and removes Harmony patches when the plugin starts and stops. Used for modifying game code at runtime. ```csharp [AutoPatch] [HarmonyPatch(typeof(Planner), "DoPlace")] static class DoPlace_Process { [HarmonyPrefix] private static bool Prefix() { UnityEngine.Debug.Log($"[Harmony] Planner DoPlace "); return true; } } ``` -------------------------------- ### Language File with Placeholders Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/owners/localization.md Shows how placeholders like {0} can be used within language file strings. These placeholders are dynamically replaced with game data when the message is displayed. ```json { "WelcomeMessage": "Welcome to {0}! Enjoy your stay." } ``` -------------------------------- ### Property Naming Convention Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Demonstrates the PascalCase convention for C# properties. ```csharp public class MyClass { public string MyProperty { get; set; } } ``` -------------------------------- ### PlayerManager Class for Encapsulation Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Use classes to encapsulate related data and methods. This example shows a PlayerManager class managing a set of players. ```csharp public class PlayerManager { private HashSet playersSet = new HashSet(); public void AddPlayer(BasePlayer player) { playersSet.Add(player); } public bool HasPlayer(BasePlayer player) { return playersSet.Contains(player); } } ``` -------------------------------- ### Cache Expensive Values with Dictionary Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Cache frequently accessed, expensive-to-compute values in a dictionary to improve performance. This example caches BasePlayer instances. ```csharp private Dictionary playerCache = new Dictionary(); public BasePlayer GetPlayer(string name) { if (!playerCache.TryGetValue(name, out var player)) { player = BasePlayer.Find(name); playerCache[name] = player; } return player; } ``` -------------------------------- ### Basic .gitignore for Rust Plugins Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/best-practices.md Specify intentionally untracked files that Git should ignore. This example ignores compiled binaries and the obj directory. ```text # Ignore .dll and .pdb files *.dll *.pdb # Ignore obj directory obj/ ``` -------------------------------- ### Get Group Permissions Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/permissions.md Retrieves permissions associated with a group. The 'parents' parameter controls whether to include permissions inherited from parent groups. ```csharp // Get only direct permissions for the group string[] permissions = permission.GetGroupPermissions("GroupName", false); // Include inherited permissions from parent groups string[] allPermissions = permission.GetGroupPermissions("GroupName", true); ``` -------------------------------- ### Plugin Description with [Description] Attribute Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/plugin-guidelines.md Use the [Description] attribute to provide a brief overview of the plugin's purpose and usage. ```csharp [Info("ExamplePlugin", "AuthorName", "1.0.0")] [Description("This plugin allows players to do XYZ. Use /command to activate.")] public class ExamplePlugin : RustPlugin { // Your plugin code goes here... } ``` -------------------------------- ### Set Publicizer Output Directory Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/publicizer.md Specify a directory to write publicized assemblies to disk using the `OXIDE_PublicizerOutput` environment variable. The directory must exist beforehand. ```batch set OXIDE_PublicizerOutput=D:\Servers\Rust\Patched ``` -------------------------------- ### Show All Groups Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/owners/permissions.md Lists all available groups on the server. Useful for auditing or finding group names. ```command oxide.show groups ``` -------------------------------- ### Open SQLite Connection Source: https://github.com/oxidemod/oxide.docs/blob/main/docs/guides/developers/database.md Establishes a new SQLite database connection. The database file is located in the './oxide/data/' folder. ```csharp Oxide.Core.SQLite.Libraries.SQLite sqlLibrary = Interface.Oxide.GetLibrary(); Connection sqlConnection = sqlLibrary.OpenDb(_databaseName, this); ```