Fix "Failed to run command '/give'" IndexOutOfRangeException (Oxide)
The chat command handler reads args[0] (or a later index) on a call where the player typed no arguments, so the array is empty. Check args.Length before indexing, or use a safe helper, and reply with usage text instead of throwing.
Failed to run command '/give' on plugin 'GiveCommand'. (IndexOutOfRangeException: Index was outside the bounds of the array.) at Oxide.Plugins.GiveCommand.CmdGive (BasePlayer player, System.String command, System.String[] args) [0x00008] in <8f3c1a2b4d5e4f6a9b0c1d2e3f4a5b6c>:0
Why it happens
Oxide splits the chat line on spaces and passes only the words after the command name as string[] args. Typing /give with nothing after it produces an empty array, not an array with one empty string. Any direct args[0], args[1] or args.Length > 1 shortcut that then indexes beyond the end throws IndexOutOfRangeException, and Oxide wraps it as Failed to run command '/give' on plugin 'GiveCommand'. The command still runs, the exception is logged with a stack trace, and nothing else in the handler executes. Common triggers: a player testing the command bare, a keybind that sends only the command name, arg.Args being null in a console command variant called with no parameters, or a helper that assumes N parameters and is called from several places with different argument counts. Parsing numbers with int.Parse(args[1]) on a missing slot throws the same way.
How to fix it
- Open the command method named in the stack trace (
CmdGivein the example). - List every
args[...]access inside it and inside helpers it calls. - Before each access, check
args != null && args.Length > index. For convenience add one guard at the top that handles the no-argument case. - When arguments are missing, send usage text back with
SendReplyand return immediately; never fall through into the parsing code. - For optional trailing arguments, use a helper like
args.Length > 1 ? args[1] : "default"so the index is only read when it exists. - Save the file, wait for
Loaded plugin GiveCommand v1.0.0 by RustPluginGenerator, then run/givewith no arguments, with a partial argument list and with a full one. The console should show your usage line and noFailed to run commandentry.
Before and after
using System.Collections.Generic;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("GiveCommand", "RustPluginGenerator", "1.0.0")]
[Description("Gives a player an item by shortname and amount")]
public class GiveCommand : RustPlugin
{
[ChatCommand("give")]
private void CmdGive(BasePlayer player, string command, string[] args)
{
if (player == null) return;
// Reads args[0] without checking that any argument was supplied.
string shortname = args[0];
int amount = int.Parse(args[1]);
Item item = ItemManager.CreateByName(shortname, amount);
if (item == null)
{
SendReply(player, "Unknown item: " + shortname);
return;
}
player.GiveItem(item);
SendReply(player, "Gave " + amount + " x " + shortname);
}
}
}using System.Collections.Generic;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("GiveCommand", "RustPluginGenerator", "1.0.0")]
[Description("Gives a player an item by shortname and amount")]
public class GiveCommand : RustPlugin
{
private const string PermGive = "givecommand.give";
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["Usage"] = "Usage: /give <shortname> [amount]",
["UnknownItem"] = "Unknown item: {0}",
["Gave"] = "Gave {0} x {1}",
["NoPermission"] = "You do not have permission to use this command.",
["BadAmount"] = "Amount must be a whole number above zero."
}, this);
}
private string Msg(string key, string userId = null, params object[] args)
=> string.Format(lang.GetMessage(key, this, userId), args);
private void Init()
{
permission.RegisterPermission(PermGive, this);
}
[ChatCommand("give")]
private void CmdGive(BasePlayer player, string command, string[] args)
{
if (player == null) return;
if (!permission.UserHasPermission(player.UserIDString, PermGive))
{
SendReply(player, Msg("NoPermission", player.UserIDString));
return;
}
// Guard the array before any index access.
if (args == null || args.Length < 1 || string.IsNullOrEmpty(args[0]))
{
SendReply(player, Msg("Usage", player.UserIDString));
return;
}
string shortname = args[0];
int amount = 1;
// Second argument is optional; only read it when it exists.
if (args.Length > 1 && !int.TryParse(args[1], out amount) || amount <= 0)
{
SendReply(player, Msg("BadAmount", player.UserIDString));
return;
}
Item item = ItemManager.CreateByName(shortname, amount);
if (item == null)
{
SendReply(player, Msg("UnknownItem", player.UserIDString, shortname));
return;
}
player.GiveItem(item);
SendReply(player, Msg("Gave", player.UserIDString, amount, shortname));
}
}
}FAQ
Does Oxide pass an empty string when I type the command with no arguments?
No. The args array is empty (Length == 0), and it can be null in rare paths. args[0] on an empty array always throws. Treat missing arguments as a normal case and reply with usage.
Why does the plugin stay loaded after this exception?
Command exceptions are caught per call. Oxide logs Failed to run command ... and keeps the plugin loaded; only the current invocation is aborted. Other commands and hooks in the same plugin keep working.
Should I use int.TryParse or catch the exception?
Check args.Length first, then int.TryParse(args[0], out var amount). Catching IndexOutOfRangeException hides bugs and costs performance in hot commands; validating the length is clearer and never throws.
The stack trace says [0x00008] in a generated file name. Is that my code?
Yes. Oxide compiles your .cs to a temporary assembly and the offset points into the CmdGive method body. The line number is not preserved, but the method name is, so search the file for CmdGive and check its argument reads.
Different error?
Paste the full console output and get the cause and a fix in plain English.
Open the error explainerSkip the debugging
Generated plugins are compiled before you get them, and compiler errors are fixed automatically.
Generate a plugin2 free plugins a month, no card.
Last updated Oct 26, 2026.
Get plugins that compile first time
Generate