NAV
csharp lua coffeescript javascript python

Getting Started

namespace Oxide.Plugins
{
    [Info("EpicPlugin", "Unknown", 0.1)]
    [Description("Makes epic stuff happen")]

    class EpicPlugin : RustLegacyPlugin
    {
        // The rest of the code and magic
    }
}
PLUGIN.Title = "EpicPlugin"
PLUGIN.Author = "Unknown"
PLUGIN.Version = V(0, 1, 0)
PLUGIN.Description = "Makes epic stuff happen"

-- The rest of the code and magic
Title: "EpicPlugin"
Author: "Unknown"
Version: V(0, 1, 0)
Description: "Makes epic stuff happen"

# The rest of the code and magic
var EpicPlugin = {
  Title : "EpicPlugin",
  Author : "Unknown",
  Version : V(0, 1, 0),
  Description : "Makes epic stuff happen",

  // The rest of the code and magic
}
class EpicPlugin:
  def __init__(self):
    self.Title = "EpicPlugin"
    self.Author = "Unknown"
    self.Version = V(0, 1, 0)
    self.Description = "Makes epic stuff happen"

  # The rest of the code and magic

The Title variable is what defines your plugin. This should be a unique codename or short description such as Pets.

The Author variable is used to show who made the plugin. This should match your OxideMod.org username if releasing.

The Version variable is used to tell if the plugin is outdated or not, and is incremented with each release. Semantic Versioning recommended.

The Description variable helps explain to users what your plugin does, in case the title isn’t enough. Make it good, but not too long!

Universal Hooks

Available for all supported games

7 Days to Die Blockstorm Hide & Hold Out Hurtworld Reign of Kings Rust Rust Legacy The Forest Unturned

Init

void Init()
{
    Puts("Init works!");
}
function PLUGIN:Init()
    print("Init works!")
end
Init: function() {
    print("Init works!");
}
Init: ->
    print "Init works!"
def Init():
    print "Init works!"

Loaded

void Loaded()
{
    Puts("Loaded works!");
}
function PLUGIN:Loaded()
    print("Loaded works!")
end
Loaded: function() {
    print("Loaded works!");
}
Loaded: ->
    print "Loaded works!"
def Loaded():
    print "Loaded works!"

Unload

void Unload()
{
    Puts("Save files, destroy timers, etc");
}
function PLUGIN:Unload()
    print("Save files, destroy timers, etc")
end
Unload: ->
    print "Save files, destroy timers, etc."
Unload: function() {
    print("Save files, destroy timers, etc");
}
def Unload():
    print "Save files, destroy timers, etc."

LoadDefaultConfig

protected override void LoadDefaultConfig()
{
    Puts("Default configuration created");
}
function PLUGIN:LoadDefaultConfig()
    print("Default configuration created")
end
LoadDefaultConfig: ->
    print "Default configuration created"
LoadDefaultConfig: function() {
    print("Default configuration created");
}
def LoadDefaultConfig():
    print "Default configuration created"

OnFrame

void OnFrame()
{
    Puts("OnFrame works!");
}
function PLUGIN:OnFrame()
    print("OnFrame works!")
end
OnFrame: ->
    print "OnFrame works!"
OnFrame: function() {
    print("OnFrame works!");
}
def OnFrame():
    print "OnFrame works!"

OnPluginLoaded

void OnPluginLoaded(Plugin name)
{
    Puts($"Plugin '{name}' has been loaded");
}
function PLUGIN:OnPluginLoaded(name)
    print("Plugin '" .. name .. "' has been loaded")
end
OnPluginLoaded: (name) =>
    print "Plugin '#{name}' has been loaded"
OnPluginLoaded: function(name) {
    print("Plugin '" + name + "' has been loaded");
}
def OnPluginLoaded(name):
    print "OnPluginLoaded works!"

OnPluginUnloaded

void OnPluginUnloaded(Plugin name)
{
    Puts($"Plugin '{name}' has been unloaded");
}
function PLUGIN:OnPluginUnloaded(name)
    print("Plugin '" .. name .. "' has been unloaded")
end
OnPluginUnloaded: (name) =>
    print "Plugin '#{name}' has been unloaded"
OnPluginUnloaded: function(name) {
    print("Plugin '" + name + "' has been unloaded");
}
def OnPluginUnloaded(name):
    print "OnPluginUnloaded works!"

OnServerInitialized

void OnServerInitialized()
{
    Puts("OnServerInitialized works!");
}
function PLUGIN:OnServerInitialized()
    print("OnServerInitialized works!")
end
OnServerInitialized: ->
    print "OnServerInitialized works!"
OnServerInitialized: function() {
    print("OnServerInitialized works!");
}
def OnServerInitialized():
    print "OnServerInitialized works!"

OnServerSave

void OnServerSave
{
    Puts("OnServerSave works!");
}
function PLUGIN:OnServerSave()
    print("OnServerSave works!")
end
OnServerSave: ->
    print "OnServerSave works!"
OnServerSave: function() {
    print("OnServerSave works!");
}
def OnServerSave():
    print "OnServerSave works!"

OnUserPermissionGranted

void OnUserPermissionGranted(string id, string perm)
{
    Puts($"User '{id}' granted permission: {perm}");
}
function PLUGIN:OnUserPermissionGranted(id, perm)
    print("User '" .. id .. "' granted permission: " .. perm)
end
OnUserPermissionGranted: (id, perm) =>
    print "User '#{id}' granted permission: #{perm}"
OnUserPermissionGranted: function(id, perm) {
    print("User '" + id + "' granted permission: " + perm);
}
def OnUserPermissionGranted(name, perm):
    print "OnUserPermissionGranted works!"

OnUserPermissionRevoked

void OnUserPermissionRevoked(string id, string perm)
{
    Puts($"User '{id}' revoked permission: {perm}");
}
function PLUGIN:OnUserPermissionRevoked(id, perm)
    print("User '" .. id .. "' revoked permission: " .. perm)
end
OnUserPermissionRevoked: (id, perm) =>
    print "User '#{id}' revoked permission: #{perm}"
OnUserPermissionRevoked: function(id, perm) {
    print("User '" + id + "' revoked permission: " + perm);
}
def OnUserPermissionRevoked(id, perm):
    print "OnUserPermissionRevoked works!"

OnUserGroupAdded

void OnUserGroupAdded(string id, string name)
{
    Puts($"User '{id}' added to group: {name}");
}
function PLUGIN:OnUserGroupAdded(id, name)
    print("User '" .. id .. "' added to group: " .. name)
end
OnUserGroupAdded: (id, name) =>
    print "User '#{id}' added to group: #{name}"
OnUserGroupAdded: function(id, name) {
    print("User '" + id + "' added to group: " + name);
}
def OnUserGroupAdded(id, name):
    print "OnUserGroupAdded works!"

OnUserGroupRemoved

void OnUserGroupRemoved(string id, string name)
{
    Puts($"User '{id}' removed from group: {name}");
}
function PLUGIN:OnUserGroupRemoved(id, name)
    print("User '" .. id .. "' removed from group: " .. name)
end
OnUserGroupRemoved: (id, name) =>
    print "User '#{id}' removed from group: #{name}"
OnUserGroupRemoved: function(id, name) {
    print("User '" + id + "' removed from group: " + name);
}
def OnUserGroupRemoved(id, name):
    print "OnUserGroupRemoved works!"

OnGroupPermissionGranted

void OnGroupPermissionGranted(string name, string perm)
{
    Puts($"Group '{name}' granted permission: {perm}");
}
function PLUGIN:OnGroupPermissionGranted(name, perm)
    print("Group '" .. name .. "' granted permission: " .. perm)
end
OnGroupPermissionGranted: (name, perm) =>
    print "Group '#{name}' granted permission: #{perm}"
OnGroupPermissionGranted: function(name, perm) {
    print("Group '" + name + "' granted permission: " + perm);
}
def OnGroupPermissionGranted(name, perm):
    print "OnGroupPermissionGranted works!"

OnGroupPermissionRevoked

void OnGroupPermissionRevoked(string name, string perm)
{
    Puts($"Group '{name}' revoked permission: {perm}");
}
function PLUGIN:OnGroupPermissionRevoked(name, perm)
    print("Group '" .. name .. "' revoked permission: " .. perm)
end
OnGroupPermissionRevoked: (name, perm) =>
    print "Group '#{name}' revoked permission: #{perm}"
OnGroupPermissionRevoked: function(name, perm) {
    print("Group '" + name + "' revoked permission: " + perm);
}
def OnGroupPermissionRevoked(name, perm):
    print "OnGroupPermissionRevoked works!"

Server Hooks

OnRunCommand

void OnRunCommand(ConsoleSystem.Arg arg, bool reply)
{
    Puts("OnRunCommand works!");
}
function PLUGIN:OnRunCommand(arg, reply)
    print("OnRunCommand works!")
end
OnRunCommand: (arg, reply) =>
    print "OnRunCommand works!"
OnRunCommand: function(arg, reply) {
    print("OnRunCommand works!");
}
def OnRunCommand(self, arg, reply):
    print "OnRunCommand works!"

OnDatablocksInitialized

void OnDatablocksInitialized()
{
    Puts("OnDatablocksInitialized works!");
}
We need a Lua example here
We need a JavaScript example here
We need a Python example here

OnResourceNodeLoaded

void OnResourceNodeLoaded(ResourceTarget resource)
{
    Puts("OnResourceNodeLoaded works!");
}
function PLUGIN:OnResourceNodeLoaded(resource)
    print("OnResourceNodeLoaded works!")
end
OnResourceNodeLoaded: (resource) =>
    print "OnResourceNodeLoaded works!"
OnResourceNodeLoaded: function(resource) {
    print("OnResourceNodeLoaded works!");
}
def OnResourceNodeLoaded(self, resource):
    print "OnResourceNodeLoaded works!"

Player Hooks

OnUserApprove

void OnUserApprove(ClientConnection connection, uLink.NetworkPlayerApproval approval, ConnectionAcceptor acceptor)
{
    Puts("OnUserApprove works!");
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

CanClientLogin

void CanClientLogin(ClientConnection connection, uLink.NetworkPlayerApproval approval)
{
    Puts("CanClientLogin works!");
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

OnPlayerConnected

void OnPlayerConnected(NetUser netUser)
{
    Puts("OnPlayerConnected works!");
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

OnPlayerDisconnected

void OnPlayerDisconnected(uLink.NetworkPlayer networkPlayer)
{
    Puts("OnPlayerDisconnected works!");
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

OnPlayerSpawn

void OnPlayerSpawn(PlayerClient client, bool usecamp, RustProto.Avatar avatar)
{
    Puts("OnPlayerSpawn works!");
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

OnPlayerChat

void OnPlayerChat(NetUser netUser, string message)
{
    Puts("OnPlayerChat works!");
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

OnPlayerVoice

void OnPlayerVoice(NetUser netUser, List<uLink.NetworkPlayer> players)
{
    Puts("OnPlayerVoice works!");
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

OnItemCraft

void OnItemCraft(CraftingInventory inventory, BlueprintDataBlock blueprint, int amount, ulong startTime)
{
    Puts("OnItemCraft works!");
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

OnBlueprintUse

void OnBlueprintUse(BlueprintDataBlock blueprint, IBlueprintItem item)
{
    Puts("OnBlueprintUse works!");
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

OnResearchItem

void OnResearchItem(ResearchToolItem<T> item, IInventoryItem otherItem)
{
    Puts("OnResearchItem works!");
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

Entity Hooks

OnAirdrop

void OnAirdrop(Vector3 position)
{
    Puts("OnAirdrop works!");
}
PLUGIN:OnAirdrop(position)
    print("OnAirdrop works!")
end
OnAirdrop: (position) =>
    print "OnAirdrop works!"
OnAirdrop: function(position) {
    print("OnAirdrop works!");
}
def OnAirDrop(self, position):
    print "OnAirDrop works!"

OnHurt

void OnHurt(TakeDamage damage, DamageEvent evt)
{
    Puts("OnHurt works!");
}
PLUGIN:OnHurt(damage, evt)
    print("OnHurt works!")
end
OnHurt: (damage, evt) =>
    print "OnHurt works!"
OnHurt: function(damage, evt) {
    print("OnHurt works!");
}
def OnHurt(self, damage, evt):
    print "OnHurt works!"

OnKilled

void OnKilled(TakeDamage damage, DamageEvent evt)
{
    Puts("OnKilled works!");
}
PLUGIN:OnKilled(damage, evt)
    print("OnKilled works!")
end
OnKilled: (damage, evt) =>
    print "OnKilled works!"
OnKilled: function(damage, evt) {
    print("OnKilled works!");
}
def OnKilled(self, damage, evt):
    print "OnKilled works!"

Item Hooks

OnItemAdded

void OnItemAdded(Inventory inventory, int slot, IInventoryItem item)
{
    Puts("OnItemAdded works!");
}
function PLUGIN:OnItemAdded(inventory, slot, item)
    print("OnItemAdded works!")
end
OnItemAdded: (inventory, slot, item) =>
    print "OnItemAdded works!"
OnItemAdded: function(inventory, slot, item) {
    print("OnItemAdded works!");
}
def OnItemAdded(self, inventory, slot, item):
    print "OnItemAdded works!"

OnItemRemoved

void OnItemRemoved(Inventory inventory, int slot, IInventoryItem item)
{
    Puts("OnItemRemoved works!");
}
function PLUGIN:OnItemRemoved(inventory, slot, item)
    print("OnItemRemoved works!")
end
OnItemRemoved: (inventory, slot, item) =>
    print "OnItemRemoved works!"
OnItemRemoved: function(inventory, slot, item) {
    print("OnItemRemoved works!");
}
def OnItemRemoved(self, inventory, slot, item):
    print "OnItemRemoved works!"

OnItemDeployed

void OnItemDeployed(DeployableObject deployable, IDeployableItem item)
{
    Puts("OnItemDeployed works!");
}
function PLUGIN:OnItemDeployed(deployable, item)
    print("OnItemDeployed works!")
end
OnItemDeployed: (deployable, item) =>
    print "OnItemDeployed works!"
OnItemDeployed: function(deployable, item) {
    print("OnItemDeployed works!");
}
def OnItemDeployed(self, deployable, item):
    print "OnItemDeployed works!"

Structure Hooks

OnStructureBuilt

void OnStructureBuilt(StructureComponent component, IStructureComponentItem item)
{
    Puts("OnStructureBuilt works!");
}
function PLUGIN:OnStructureBuilt(component, item)
    print("OnStructureBuilt works!")
end
OnStructureBuilt: (component, item) =>
    print "OnStructureBuilt works!"
OnStructureBuilt: function(component, item) {
    print("OnStructureBuilt works!");
}
def OnStructureBuilt(self, component, item):
    print "OnStructureBuilt works!"

OnStructureDecay

void OnStructureDecay(StructureMaster master)
{
    Puts("OnStructureDecay works!");
}
We need a Lua example here
We need a CoffeeScript example here
We need a JavaScript example here
We need a Python example here

OnDoorToggle

void OnDoorToggle(BasicDoor door, ulong timestamp, Controllable controllable)
{
    Puts("OnDoorToggle works!");
}
function PLUGIN:OnDoorToggle(door, timestamp, controllable)
    print("OnDoorToggle works!")
end
OnDoorToggle: (door, timestamp, controllable) =>
    print "OnDoorToggle works!"
OnDoorToggle: function(door, timestamp, controllable) {
    print("OnDoorToggle works!");
}
def OnDoorToggle(self, door, timestamp, controllable):
    print "OnDoorToggle works!"

Library Functions

There are a few functions that have been added to wrap Rust Legacy functions, creating aliases of sorts to make your life easier during initial coding as well as during upgrades.

BroadcastChat

void OnPlayerConnected(NetUser netUser)
{
    PrintToChat($"{netUser.displayName} has joined the server"));
}
function PLUGIN:OnPlayerConnected(netUser)
    rust.BroadcastChat(netUser.displayName .. " has joined the server")
end
We need a CoffeeScript example here
OnPlayerConnected: function(netUser) {
    rust.BroadcastChat(netUser.displayName + " has joined the server");
}
def OnPlayerConnected(self, netUser):
    rust.BroadcastChat(netUser.displayName + " has joined the server")

Sends a chat message to all players.

rust.BroadcastChat(string message, object[] args)

BroadcastConsole

void OnPlayerConnected(NetUser netUser)
{
    PrintToConsole($"{netUser.displayName} has joined the server");
}
function PLUGIN:OnPlayerConnected(netUser)
    rust.BroadcastConsole(netUser.displayName .. " has joined the server")
end
We need a CoffeeScript example here
OnPlayerConnected: function(netUser) {
    rust.BroadcastConsole(netUser.displayName + " has joined the server");
}
def OnPlayerConnected(self, netUser):
    rust.BroadcastConsole(netUser.displayName + " has joined the server")

Prints a message to all players’ in-game console

rust.BroadcastConsole(string message, object[] args)

FindPlayer

[ChatCommand("ex")
void Example(NetUser netUser, string command, string[] args)
{
    NetUser target = rust.FindPlayer(args[0]);
}
function PLUGIN:Init()
    cmd.AddChatCommand("ex",  self.Plugin, "Example")
end
function PLUGIN:Example(netUser, command, args)
    target = rust.FindPlayer(args[0])
end
We need a CoffeeScript example here
Init: function() {
    cmd.AddChatCommand("ex",  self.Plugin, "Example");
},
Example: function(netUser, command, args) {
    target = rust.FindPlayer(args[0]);
}
def Init(self):
    cmd.AddChatCommand("ex",  self.Plugin, "Example")
def Example(self, netUser, command, args):
    target = rust.FindPlayer(args[0])

Searches for an online player by name, steam id or ip. Returns a netUser if a player is found, otherwise null is returned.

rust.FindPlayer(string nameOrSteamIdOrIp)

PrivateBindingFlag

This should not be used in C# plugins, Reflection should be used instead
We need a Lua example here
We need a CoffeeScript example here
We need a JavaScript example here
We need a Python example here

Used to get/set private methods, fields, and properties through Reflection.

rust.PrivateBindingFlag()

QuoteSafe

var message = "Use /kick \"playername\" to kick player";
message.QuoteSafe();
rust.QuoteSafe("Use /kick \"playername\" to kick player")
We need a CoffeeScript example here
rust.QuoteSafe("Use /kick \"playername\" to kick player");
rust.QuoteSafe("Use /kick \"playername\" to kick player")

Used to safely save text or send a message that contains quotation marks.

rust.QuoteSafe(message)

SendChatMessage

void OnPlayerSpawn(NetUser netUser)
{
    var message = "You've respawned from a terrible death";
    rust.SendChatMessage({ netUser, message });
}
function PLUGIN:OnPlayerSpawn(player)
    rust.SendChatMessage(netUser, "You've respawned from a terrible death")
end
We need a CoffeeScript example here
OnPlayerSpawn: function(netUser) {
    rust.SendChatMessage(netUser, "You've respawned from a terrible death");
}
def OnPlayerSpawn(self, player):
    rust.SendChatMessage(netUser, "You've respawned from a terrible death")

Sends a chat message to specified player.

rust.SendChatMessage(NetUser netUser, string message, object[] args)

SendConsoleMessage

void OnPlayerSpawn(NetUser netUser)
{
    var message = "You've respawned from a terrible death";
    rust.SendConsoleMessage({ netUser, message });
}
function PLUGIN:OnPlayerSpawn(player)
    rust.SendConsoleMessage(netUser, "You've respawned from a terrible death")
end
We need a CoffeeScript example here
OnPlayerSpawn: function(netUser) {
    rust.SendConsoleMessage(netUser, "You've respawned from a terrible death");
}
def OnPlayerSpawn(self, player):
    rust.SendConsoleMessage(netUser, "You've respawned from a terrible death")

Sends a console message to specified player’s console.

rust.SendConsoleMessage(NetUser netUser, string message, object[] args)

UserIDFromPlayer

[ChatCommand("id")]
void ChatId(NetUser netUser, string command, string[] args)
{
    SendReply(netUser, "Your ID is: " + netUser.userID.ToString());
}
function PLUGIN:Init()
    cmd.AddChatCommand("steamid",  self.Plugin, "ChatId")
end
function PLUGIN:ChatId(netUser, command, arg)
    rust.SendChatMessage(netUser, "Your ID is: " .. rust.UserIDFromPlayer(netUser))
end
We need a CoffeeScript example here
Init: function() {
    cmd.AddChatCommand("steamid",  self.Plugin, "ChatId");
},
ChatId: function(netUser, command, arg) {
    rust.SendChatMessage(netUser, "Your ID is: " + rust.UserIDFromPlayer(netUser));
}
def Init(self):
    cmd.AddChatCommand("steamid",  self.Plugin, "cmdSteamId")
def cmdSteamId(self, netUser, command, arg):
    rust.SendChatMessage(netUser, "Your Steam ID is: " + rust.UserIDFromPlayer(netUser))

Gets the user ID (64-bit SteamID) as a string of an online player.

rust.UserIDFromPlayer(NetUser netUser)

Notice

[ChatCommand("notice")]
void cmdNotice(NetUser netUser, string command, string[] args)
{
    var message = "Notice Demo";
    var icon = "!";
    var duration = 4f;
    rust.Notice(netUser, message, icon, duration);
}
function PLUGIN:Init()
    cmd.AddChatCommand("notice",  self.Plugin, "cmdNotice")
end
function PLUGIN:cmdNotice(netUser, command, arg)
    rust.Notice(netUser, "Notice Demo", "!", 4);
end
We need a CoffeeScript example here
Init: function() {
    cmd.AddChatCommand("notice",  self.Plugin, "cmdNotice");
},
cmdNotice: function(netUser, command, arg) {
    rust.Notice(netUser, "Notice Demo", "!", 4);
}
def Init(self):
    cmd.AddChatCommand("notice",  self.Plugin, "cmdNotice")
def cmdNotice(self, netUser, command, arg):
    rust.Notice(netUser, "Notice Demo", "!", 4);

Sends a notice to the player at the top of the screen.

rust.Notice(NetUser netUser, string message, string icon, float duration)

InventoryNotice

[ChatCommand("notice")]
void cmdNotice(NetUser netUser, string command, string[] args)
{
    var message = "InventoryNotice Demo";
    rust.InventoryNotice(netUser, message);
}
function PLUGIN:Init()
    cmd.AddChatCommand("notice",  self.Plugin, "cmdNotice")
end
function PLUGIN:cmdNotice(netUser, command, arg)
    rust.InventoryNotice(netUser, "InventoryNotice Demo");
end
We need a CoffeeScript example here
Init: function() {
    cmd.AddChatCommand("notice",  self.Plugin, "cmdNotice");
},
cmdNotice: function(netUser, command, arg) {
    rust.InventoryNotice(netUser, "InventoryNotice Demo");
}
def Init(self):
    cmd.AddChatCommand("notice",  self.Plugin, "cmdNotice")
def cmdNotice(self, netUser, command, arg):
    rust.InventoryNotice(netUser, "InventoryNotice Demo");

Sends a notice to the player on the right side of the screen right above the player’s health bar.

rust.InventoryNotice(NetUser netUser, string message)

Timers (Basic)

Timers are great for delaying code, allowing it to be run later.

Single timer

timer.Once(3f, () =>
{
    Puts("Hello world!")
});
timer.Once(3, function()
    print("Hello world!")
end)
timer.Once 3, ->
    print "Hello world!"
timer.Once(3, function() {
    print("Hello world!");
});
def my_callback_func():
    print("Hello world!")

timer.Once(3, Action(my_callback_func), self.Plugin)

Executes the specified function once after the specified delay.

Repeating timer

timer.Repeat(5f, 0, () =>
{
    Puts("Hello world!")
});
timer.Repeat(5, 0, function()
    print("Hello world!")
end, self.Plugin)
timer.Repeat 5, 0, (->
    print "Hello world!"
), @Plugin
timer.Repeat(5, 0, function() {
    print("Hello world!");
}, this.Plugin);
def my_callback_func():
    print("Hello world!")

timer.Repeat(5, 0, Action(my_callback_func), self.Plugin)

Executes the specified function every “delay” seconds.

If “repeats” is specified, the function will only be called “repeats” times.

Next frame timer

NextFrame(() =>
{
    Puts("Hello world!");
});
timer.NextFrame(function()
    print("Hello world!")
);
timer.NextFrame ->
    print "Hello world!"
timer.NextFrame(function() {
    print("Hello world!");
});
timer.NextFrame((lambda:
    print("Hello world!")
), self.Plugin)

Executes the specified function at the next frame.

Web Requests

Web requests allow you to send a HTTP GET or POST to a specified URL.

The request will return true if the web request was sent, false if not. The callback is called with 2 parameters - an integer HTTP response code and a string response.

Basic Get method

using Oxide.Core.Libraries.Covalence;

namespace Oxide.Plugins
{
    [Info("EpicPlugin", "Unknown", 1.0)]
    [Description("This example illustrates how to use a GET WebRequest")]

    class EpicPlugin : CovalencePlugin
    {
        [Command("get")]
        void GetRequest(IPlayer player, string command, string[] args)
        {
            webrequest.EnqueueGet("http://www.google.com/search?q=oxide", (code, response) => GetCallback(code, response, player), this);
        }

        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}");
        }
    }
}
webrequest.EnqueueGet("http://www.google.com/search?q=oxide", function(code, response)
    if response == nil or code ~= 200 then 
        print("Couldn't get an answer from Google!") 
        return 
    end
    print("Google answered: " .. tostring(response))
end, self.Plugin)
webrequests.EnqueueGet("http://www.google.com/search?q=oxide", function(code, response) {
    if (response == null || code != 200) {
        print("Couldn't get an answer from Google!");
        return
    }
    print("Google answered: " + response);
}.bind(this), this.Plugin);
We need a CoffeeScript example here
from System import Action, Int32, String
def response_handler(code, response):
    if response == None or code != 200:
        print "Couldn't get an answer from Google!" 
        return 
    print "Google answered: " + response
webrequest.EnqueueGet("http://www.google.com/search?q=oxide", Action[Int32,String](response_handler), self.Plugin);

This uses the raw connection to a web page as you would on your browser.

Basic POST method

using Oxide.Core.Libraries.Covalence;

namespace Oxide.Plugins
{
    [Info("EpicPlugin", "Unknown", 1.0)]
    [Description("This example illustrates how to use a POST WebRequest")]

    class EpicPlugin : CovalencePlugin
    {
        [Command("post")]
        void PostRequest(IPlayer player, string command, string[] args)
        {
            webrequest.EnqueuePost("http://www.google.com/search?q=oxide", "param1=value1&param2=value2", (code, response) => PostCallback(code, response, player), this);
        }

        void PostCallback(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);
        }
    }
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

Advanced GET method

using Oxide.Core.Libraries.Covalence;

namespace Oxide.Plugins
{
    [Info("EpicPlugin", "Unknown", 1.0)]
    [Description("This example illustrates how to use a GET WebRequest")]

    class EpicPlugin : CovalencePlugin
    {
        [Command("get")]
        void GetRequest(IPlayer player, string command, string[] args)
        {
            // Set a custom timeout (in milliseconds)
            var timeout = 200f;

            // Set some custom request headers (eg. for HTTP Basic Auth)
            var headers = new Dictionary<string, string> { { "header", "value" } };

            webrequest.EnqueueGet("http://www.google.com/search?q=oxide", (code, response) => GetCallback(code, response, player), this, headers, timeout);
        }

        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}");
        }
    }
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

Advanced POST method

using Oxide.Core.Libraries.Covalence;

namespace Oxide.Plugins
{
    [Info("EpicPlugin", "Unknown", 1.0)]
    [Description("This example illustrates how to use a POST WebRequest")]

    class EpicPlugin : CovalencePlugin
    {
        [Command("post")]
        void PostRequest(IPlayer player, string command, string[] args)
        {
            // Set a timeout (in milliseconds)
            var timeout = 200f;

            // Set some custom request headers (eg. for HTTP Basic Auth)
            var headers = new Dictionary<string, string> { { "header", "value" } };

            webrequest.EnqueuePost("http://www.google.com/search?q=oxide", "param1=value1&param2=value2", (code, response) => PostCallback(code, response, player), this, headers, timeout);
        }

        void PostCallback(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);
        }
    }
}
We need a Lua example here
We need a JavaScript example here
We need a CoffeeScript example here
We need a Python example here

Plugin API

Oxide allows you to expose methods in your plugin and make them available to other plugins. This allows you to access objects or properties from other plugins without having to replicate functionality yourself.

Exposing an API method

namespace Oxide.Plugins
{
    [Info("EpicPlugin", "Unknown", 0.1)]
    [Description("Makes epic stuff happen")]

    class EpicPlugin : CovalencePlugin
    {
        // Plugin methods can be a simple bool that is returned
        public bool GetReturn()
        {
            return true;
        }

        // Plugin methods can take parameters and return simple types
        public string TakeParam(string param, int secondParam)
        {
            if (param == "first parameter") return param;
            else return "First parameter didn't match!";
        }

        // To return complex types, they should first be converted
        // into builtin types (e.g. JSON.net types like JObject, JArray, etc. or builtin
        // collections like System.Collections.Generic.Dictionary)
        public JObject ReturnObject()
        {
            var myObject = new JObject();
            myObject["key"] = "value";
            myObject["array"] = new JArray();
            return myObject;
        }

        // Plugin methods don't have to return something
        public void SendMessage()
        {
            Puts("You just called the 'SendMessage' method!");
        }
    }
}
We need a Lua example here
We need a CoffeeScript example here
We need a javascript example here
from System.Collections.Generic import Dictionary
from System.Collections.Generic import List

class EpicPlugin:
    def __init__(self):
        self.Title = "EpicPlugin"
        self.Description = "Makes epic stuff happen"
        self.Author = "Unknown"
        self.Version = V(0, 1, 0)

    # Plugin methods can be a simple bool that is returned
    def GetReturn(self):
        return True

    # Plugin methods can take parameters and return simple types
    def TakeParam(self, param, secondParam):
        if param == "first parameter":
            return param
        else:
            return "First parameter didn't match!"

    # To return complex types, they should first be converted
    # into C# builtin types (e.g. System.Collections.Generic.Dictionary)
    def ReturnObject(self):
        myObject = Dictionary[str, object]()
        myObject["key"] = "value"
        myObject["array"] = List[object]()
        return myObject

    # Plugin methods don't have to return something
    def SendMessage(self):
        print("You just called the 'SendMessage' method!")

Exposing an API method allows other plugins to call that method.

For example, you could write a plugin that does some player management, then allow other plugins to “query” it via an API method to get a list of players who have certain privileges set in the original plugin.

Calling an API method

namespace Oxide.Plugins
{
    [Info("SecondEpicPlugin", "Unknown", 0.1)]
    [Description("Makes more epic stuff happen")]

    class SecondEpicPlugin : CovalencePlugin
    {
        // First, add a reference to the plugin you are trying to call
        // The name of this field needs to be the exact name of the desired plugin
        // eg. We are referencing the example plugin above which is called 'EpicPlugin'
        [PluginReference] Plugin EpicPlugin;

        // It's a good idea to check if the plugin you're trying to call
        // has been loaded by oxide (otherwise you can't call the method)
        void OnServerInitialized()
        {
            // Note: Trying to do this check in the plugin Init() method may
            // fail, as the plugin load order may be different each time
            if (EpicPlugin == null)
            {
                PrintWarning("Plugin 'EpicPlugin' was not found!");
            }
        }

        void CallApi()
        {
            // Plugin methods return objects, so cast the API call to the type
            // you're expecting
            var getTypedReturn = (bool)EpicPlugin?.Call("GetReturn");

            // Send parameters through as variables after the method name
            var takeParam = (string)EpicPlugin?.Call("TakeParam", "param1", 1024);

            // Use JSON.net to process the returned object
            var returnedObject = EpicPlugin?.Call("ReturnObject");

            // Call a plugin to do some work without returning anything
            EpicPlugin?.Call("SendMessage");
        }
    }
}
We need a Lua example here
We need a CoffeeScript example here
We need a javascript example here
class SecondEpicPlugin:
    def __init__(self):
        self.Title = "SecondEpicPlugin"
        self.Description = "Makes more epic stuff happen"
        self.Author = "Unknown"
        self.Version = V(0, 1, 0)

    def Init(self):
        self.EpicPlugin = plugins.Find("EpicPlugin")

    def CallApi(self):
        if self.EpicPlugin is None:
            return

        # Python is dynamically typed, so casting is not necessary:
        # the structure of the type matters, not the name
        getReturn = self.EpicPlugin.Call("GetReturn")

        # Send parameters through as variables after the method name
        takeParam = self.EpicPlugin.Call("TakeParam", "param1", 1024)

        # Access returned object like dictionary
        returnedObject = self.EpicPlugin.Call("ReturnObject")

        # Call a plugin to do some work without returning anything
        self.EpicPlugin.Call("SendMessage")

Calling an API method allows you to access results from another plugin.