Skip to content

Add documentation of the oxide core hooks #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
14585bb
Code modification to use both files docs.json and docs_core.json
Lorenzo-oo Oct 1, 2024
04907ef
Documention of the oxide core hooks
Lorenzo-oo Oct 1, 2024
acbb51b
Merge branch 'OxideMod:main' into main
Lorenzo-oo Oct 3, 2024
f5ee857
More flexible Docs json file to support multiple .JSON files
Lorenzo-oo Oct 9, 2024
7c177e2
Merge branch 'OxideMod:main' into main
Lorenzo-oo Oct 9, 2024
0a854f9
-
Lorenzo-oo Oct 9, 2024
e71a543
Merge branch 'main' of https://github.com/Lorenzo-oo/Oxide.Docs
Lorenzo-oo Oct 9, 2024
482abeb
-
Lorenzo-oo Oct 9, 2024
388d4d9
Add hook ReturnType
Lorenzo-oo Oct 16, 2024
308413a
Add Hook ReturnType
Lorenzo-oo Oct 16, 2024
ce58048
Add Hook ReturnType
Lorenzo-oo Oct 16, 2024
b632d10
Merge branch 'OxideMod:main' into main
Lorenzo-oo Dec 29, 2024
be3e7da
missing return line in sample code, when return value is not void
Lorenzo-oo Dec 29, 2024
a14a886
Merge branch 'main' of https://github.com/Lorenzo-oo/Oxide.Docs
Lorenzo-oo Dec 29, 2024
54cde9e
Add documentation for Attributes and Timers
Lorenzo-oo Jan 10, 2025
d368fed
Merge branch 'OxideMod:main' into main
Lorenzo-oo Jan 10, 2025
83950b4
Add Permissions.md, Database.md, WebRequest.md
Lorenzo-oo Jan 10, 2025
54e40dd
Merge branch 'main' of https://github.com/Lorenzo-oo/Oxide.Docs
Lorenzo-oo Jan 10, 2025
9042ec1
fix typo
Lorenzo-oo Jan 12, 2025
989b8b6
missing HookMethod (was not sure if available to plugins)
Lorenzo-oo Jan 16, 2025
c5ba718
Merge branch 'OxideMod:main' into main
Lorenzo-oo Feb 5, 2025
a63ea24
Merge branch 'OxideMod:main' into main
Lorenzo-oo Mar 5, 2025
cf3cd78
minor adjustment for returnType in Usage
Lorenzo-oo Apr 1, 2025
871fa23
//reference attribute
Lorenzo-oo Apr 22, 2025
d5546cc
Merge branch 'main' of https://github.com/Lorenzo-oo/Oxide.Docs
Lorenzo-oo Apr 22, 2025
90dcc49
Merge branch 'OxideMod:main' into main
Lorenzo-oo Apr 22, 2025
cbad52d
For test webpage on https://[username].github.io/Oxide.Docs
Lorenzo-oo Apr 23, 2025
ae189c4
.
Lorenzo-oo Apr 23, 2025
5712d04
Delete .github/workflows directory
Lorenzo-oo Apr 23, 2025
1dd8443
update apr 22
Lorenzo-oo Apr 23, 2025
770bfa2
Rename Attributes.md to attributes.md
Lorenzo-oo Apr 23, 2025
934f15b
Rename Database.md to database.md
Lorenzo-oo Apr 23, 2025
8899a8b
Rename Permissions.md to permissions.md
Lorenzo-oo Apr 23, 2025
dfd56a1
Rename Timers.md to timers.md
Lorenzo-oo Apr 23, 2025
c005ea6
Rename WebRequests.md to webrequests.md
Lorenzo-oo Apr 23, 2025
42fdab4
Merge branch 'OxideMod:main' into main
Lorenzo-oo Apr 23, 2025
535f65f
Modification of section data-storage and using-plugin
Lorenzo-oo Apr 23, 2025
719ed02
Fix typo
Lorenzo-oo Apr 25, 2025
f5ef17e
Add guide for coroutines and pooling
Lorenzo-oo Apr 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions docs/guides/developers/attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
title: Attributes
after: webrequests
---
# Attributes
## Commands

Custom commands are easily implemented with minimal boilerplate for both in-game chat interfaces and conventional command-line interfaces.
## Chat commands
Chat commands are in-game commands entered via the game client's chat, prefixed by a forward slash (/).

when using covalence
```csharp
[Command("test")]
private void TestCommand(IPlayer player, string command, string[] args)
{
player.Reply("Test successful!");
}
```
when using Rustplugin
```csharp
[ChatCommand("test")]
void cmdTest (BasePlayer player, string command, string [] args)
{
Puts("Test successful!");
}
```
## Console commands
Console commands may be executed from the server console and in-game interfaces F1 (where applicable).

when using covalence
```csharp
[Command("test")]
private void TestCommand(IPlayer player, string command, string[] args)
{
player.Reply("Test successful!");
}
```
when using Rustplugin
```csharp
[ConsoleCommand("test")]
private void cmdTest((ConsoleSystem.Arg arg))
{
Puts("Test successful!");
}
```
## Command permissions
Easily restrict command usage to players who have a permission assigned to them.
```csharp
[Command("test"), Permission("epicstuff.use")]
private void TestCommand(IPlayer player, string command, string[] args)
{
player.Reply("Test successful!");
}
```
## Info
Information about the plugin. plugin name (with spaces between words), Developper or maintainer name, and a 3 digit version number.
```csharp
[Info("Plugin name", "Developper/Maintainer", "1.0.0")]
```
## Description
A short description of what the plugin does
```csharp
[Description("A short description of the plugin")]
```
## PluginReference
Reference to other plugin, when this plugin need to use functions from other plugins.

```csharp
[PluginReference] private Plugin Vanish, Backpacks;
```
Note: when a plugin is required by this plugin, this line should appear at the top.
```csharp
//Requires: Backpacks
```
If required plugin is absent from plugin folder, this plugin will not start

## OnlinePlayers
Auto manage an Hashtable of online players.

see Bank and Trade plugin for usage example
```csharp
class OnlinePlayer
{
public BasePlayer Player;
public OnlinePlayer (BasePlayer player)
{
}
}

[OnlinePlayers]
Hash<BasePlayer, OnlinePlayer> onlinePlayers = new Hash<BasePlayer, OnlinePlayer> ();
```
## HookMethod
Indicates that the specified method should be a handler for a hook
```csharp
[HookMethod("OnPlayerConnected")]
private void base_OnPlayerConnected(BasePlayer player) => AddOnlinePlayer(player);
```

## AutoPatch
Used with HarmonyPatch to automatically install the patch when plugin start, and uninstall it, when plugin terminate
```csharp
[AutoPatch]
[HarmonyPatch(typeof(Planner), "DoPlace")]
static class DoPlace_Process
{
[HarmonyPrefix]
private static bool Prefix()
{
UnityEngine.Debug.Log($"[Harmony] Planner DoPlace ");
return true;
}
}
```
Note: see harmony documentation for info about harmony patches

## Reference
Add the ablility to reference additionnal DLL files to be used by the plugin
```csharp
//Reference: System.Drawing
```

90 changes: 90 additions & 0 deletions docs/guides/developers/coroutines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: Coroutines
after: pooling
---

# Coroutines ( Unity )

Coroutines are usefull for tasks that run across multiple frames. Like waiting to HTTP transfers,
Remember that coroutines are not threads. coroutines operation execute on the main thread of the game.

see [Unity documentation about coroutine](https://docs.unity3d.com/6000.1/Documentation/Manual/coroutines.html)

Example of coroutine sending http message to Discord

```csharp
private class DiscordComponent : MonoBehaviour
{
private readonly Queue<object> _queue = new Queue<object>();
// URL generated in Discord
private string _url;
// coroutine busy status flag
private bool _busy = false;

public DiscordComponent Configure(string url)
{
if (url == null) throw new ArgumentNullException(nameof(url));
_url = url;
return this;
}

// Add a message to a queue
public DiscordComponent SendTextMessage(string message, params object[] args)
{
message = args.Length > 0 ? string.Format(message, args) : message;
return AddQueue(new MessageRequest(message));
}

private DiscordComponent AddQueue(object request)
{
_queue.Enqueue(request);
if (!_busy)
StartCoroutine(ProcessQueue());
return this;
}

// Coroutine to process message queue
private IEnumerator ProcessQueue()
{
if (_busy) yield break;
_busy = true;
while (_queue.Count!=0)
{
var request = _queue.Dequeue();
yield return ProcessRequest(request);
}
_busy = false;
}

private IEnumerator ProcessRequest(object request)
{
// Code to send message to discord
byte[] data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(request));
UploadHandlerRaw uh = new UploadHandlerRaw(data) { contentType = "application/json" };
UnityWebRequest www = UnityWebRequest.PostWwwForm(_url, UnityWebRequest.kHttpVerbPOST);
www.uploadHandler = uh;
yield return www.SendWebRequest();

if (www.result == UnityWebRequest.Result.ConnectionError ||
www.result == UnityWebRequest.Result.ProtocolError)
print($"ERROR: {www.error} | {www.downloadHandler?.text}");

www.Dispose();

// Wait 2 second between message to avoid spamming Discord
yield return new WaitForSeconds(2.0f);
}
}

private class MessageRequest
{
[JsonProperty("content")]
public string Content { get; set; }

public MessageRequest(string content)
{
if (content == null) throw new ArgumentNullException(nameof(content));
Content = content;
}
}
```
Loading