For a while I've had problems getting specific mods I'm working on for Rust to implement a chat command.
I've worked with AI analyzing and suggesting code, so for a long while I just suspected that it failed to properly structure the code.
Also something simple like this also yields no result in server console:
o.commands
According to AI, this should show all oxide registered commands, but no response.
o.load
o.unload
I have tried to completely clean-install Rust server and with newest oxide and use the most basic test code for a chat command...
The game still just says: no such command.
The test mod loads fine and I also tried loading ONLY a test mod... still same problem...
When other mods are loaded, their commands work just fine, but even providing AI with example of mod where it works, can fix the problem in other mods...
// File: TestCommand.cs
using Oxide.Core.Plugins;
using Rust;
using Oxide.Core.Libraries.Covalence;
namespace Oxide.Plugins
{
[Info("TestCommand", "LordHellFire666, Gemini", "1.0.0")]
[Description("A simple test plugin to check chat command registration.")]
public class TestCommand : CSharpPlugin
{
[Command("test")]
private void TestChatCommand(IPlayer player, string command, string[] args)
{
player.Reply("Test successful!");
}
}
}I tried getting Oxide to use verbose logging, but still nothing happens, when I use /test in chat ingame.
The solution appears!!
After a little fiddling with AI, it reasoned that there is an issue with attribute based commands in Oxide.
I had to manually tell the AI what code the working mod was using to register the command; THEN it could reason out what was happening and replicate working code. AI has it's limitations...
So even though the above method is an example of use based on instructions from the Oxide website, it does not work!
And AI was apparently unable to reason out the specific registration method used in the working mod it was given as an example; thus unable to replicate it and just kept looping around in its own machinations.
Also tried using BasePlayer instead of IPlayer... same problem.
This was the solution, because this was actually what some of the other mods used (I didn't notice untill I scrutinized more in detail, because I rarely program; just use AI to do most of the work):
// File: TestCommand.cs
using Oxide.Core;
using Oxide.Core.Plugins;
using Rust; // Required for BasePlayer
using Oxide.Core.Libraries.Covalence; // Required for IPlayer if you prefer to use it, though BasePlayer is used here
namespace Oxide.Plugins
{
[Info("TestCommand", "LordHellFire666, Gemini", "1.0.0")]
[Description("A simple test plugin to check chat command registration.")]
public class TestCommand : RustPlugin // CHANGED: Inherit from RustPlugin
{
void Init()
{
// Register the chat command programmatically instead of using [ChatCommand]
cmd.AddChatCommand("testcommand", this, "TestChatCommand"); // Registering the command
Puts("TestCommand plugin initialized. Attempting to register /testcommand.");
}
// REMOVED [ChatCommand("testcommand")] attribute
void TestChatCommand(BasePlayer player, string command, string[] args)
{
player.ChatMessage("Hello from TestCommand! Your command was recognized.");
Puts($"[TestCommand] Player {player.displayName} used /testcommand.");
}
}
}