Registering a chat command?Solved
So I'm working on making my first plugin and I'm running into some issues. Didn't know where else to post this since there doesn't seem to be a plugin development thread. So the goal of this is to be a simple plugin to add as many /commands as you would like that you may have to do on wipeday for example. Such as /kits resetdata and whatever else. The goal is to limit it to one simple command /wipeday. Instead of running around resetting the data for multiple plugins each time. The part I am stuck on, should be really simple but after looking through the documentation for UMod I know how to make a command for everything except other commands. Here is what I have so far:
 private void RegisterPermissions()
        {
            string[] names = new string[] { "wipeday" };
            foreach (var name in names)
                permission.RegisterPermission("wipeday.use");
        }
private void Init() => cmd.Wipeday("wipeday", this, wipeday);

private void CommandItself(BasePlayer player, string wipeday, string[] args)
{
    ChatCommand
}
[ChatCommand("wipeday")]
"
}​

Would appreciate any help, thanks!
  1. The foreach loop to register the same permission is pointless, as is the string[] names; just register the single permission in Init()
  2. cmd.AddChatCommand("wipeday", this, "CommandItself"); in Init() to register the command
  3. Remove the [ChatCommand] at the bottom of the code, or add it above CommandItself instead of the manual cmd registration

Without attribute, manual registration:
private void Init()
{
    cmd.AddChatCommand("wipeday", this, "CommandItself");
    permission.RegisterPermission("wipeday.use");
}

private void CommandItself(BasePlayer player, string wipeday, string[] args)
{
    if (permission.UserHasPermission(player.UserIDString, "wipeday.use"))
    {
        // Do stuff here
    }
}​


or with attribute:

private void Init()
{
    permission.RegisterPermission("wipeday.use");
}

[ChatCommmand("wipeday")]
private void CommandItself(BasePlayer player, string wipeday, string[] args)
{
    if (permission.UserHasPermission(player.UserIDString, "wipeday.use"))
    {
        // Do stuff here
    }
}


or as a universal plugin (CovalencePlugin) with attribute:

[Command("wipeday"), Permission("wipeday.use")]
private void CommandItself(IPlayer player, string wipeday, string[] args)
{
    if (player.HasPermission("wipeday.use"))
    {
        // Do stuff here
    }
}


or universal with manual registration:

private void Init()
{
    AddCovalenceCommand("wipeday", this, "CommandItself");
    permission.RegisterPermission("wipeday.use");
}

private void CommandItself(IPlayer player, string wipeday, string[] args)
{
    if (player.HasPermission("wipeday.use"))
    {
        // Do stuff here
    }
}
In response to Wulf ():
The foreach loop to register the same permission is pointless, as is the string[] names; just regis...
I suppose there would be no reason not to make this a Covalence plugin, makes sense. So with the last one you recommended:
private void Init()
{
    AddCovalenceCommand("wipeday", this, "CommandItself");
    permission.RegisterPermission("wipeday.use");
}

private void CommandItself(IPlayer player, string wipeday, string[] args)
{
    if (player.HasPermission("wipeday.use"))
    {
        // Do stuff here
    }
}​

The part i'm stuck on is the //Do stuff here lol.   Not all of it, just not sure how to tell the plugin to run a command. So for example to have it run /kit resetdata it would be: cmd.Something "kit resetdata" ?? Am I on the right track here?

In response to Oddyseous ():
I suppose there would be no reason not to make this a Covalence plugin, makes sense. So with the las...
So just to be clear, you're just trying to make this plugin run a command on another plugin?
Right, the goal is to have it run commands for whatever various plugins you may be running and delete files as well as be configurable via config file /kit resetdata is just an example. 

Merged post

Actually I guess Timed Execute should have a good example of this.
In response to Oddyseous ():
Right, the goal is to have it run commands for whatever various plugins you may be running and delet...
As a CovalencePlugin:

server.Command("command and args here");

or

server.Command("command", "args");
In response to Wulf ():
As a CovalencePlugin:

server.Command("command and args here");

or

s...
Ah perfect thanks for all the help Wulf. Thanks I appreciate the help!!!
In response to Oddyseous ():
Ah perfect thanks for all the help Wulf. Thanks I appreciate the help!!!
Do keep in mind that only works with console commands, chat commands generally expect a player.
Is there a way to call or force a chat command server-side? Would something as simple as say "/ChatCommand" work?
In response to Oddyseous ():
Is there a way to call or force a chat command server-side? Would something as simple as say "/ChatC...
You can try using something like "chat.say /chatcommand", but no guarantees as most chat commands expect a player.
In response to Wulf ():
You can try using something like "chat.say /chatcommand", but no guarantees as most chat commands ex...
Okay cool thanks Wulf!
Locked automatically