Skip to content

Make a command by Unturned

FCheat edited this page Jun 30, 2018 · 1 revision

Making a command in the Unturned Commander

So, in the chat hook we've previously seen handling commands just like every other plugin out there.

But what they HAVEN'T found out, is how THE GAMES commands are registered.

This will teach you to register a command the exact same way the game does it, and this won't cost you anything major.


The game automatically assigns the command variables in UnturnedInstallFolder*language*\Server*command*.dat -

But, we do not HAVE to do this, and to avoid people needing to manually make these files or them having to be generated by the plugin, we'll just set the variables.

First, to make a new command we'll need a new inherit using SDG.Unturned.Command - For example I'll be using a "Busy" message popup command as example.

Ex

public class CommandMessageA : SDG.Unturned.Command

Then, it'll need an initializer and an override of execute(Steamworks.CSteamID executorID, string parameter) from the command class.

public class CommandMessageA : SDG.Unturned.Command
{
	public CommandMessageA()
	{
		
	}
	
	protected override void execute(Steamworks.CSteamID executorID, string parameter)
	{
		
	}
}

Now, inside the initializer we need to setup our command information

public CommandMessageA()
{
	localization = new SDG.Unturned.Local();
	_command = "MessageA"; //Set our command (This is the exact command that will need to be called)
	_info = "MessageA"; //Information on the command
	_help = "Sends the 'busy' UI alert to the caller"; //Help information on the command (/help <command>)
}

Next, we're ready to setup a function on call. For the example, I'm just going to provide you this:

protected override void execute(Steamworks.CSteamID executorID, string parameter)
{
	foreach (SDG.Unturned.SteamPlayer i in SDG.Unturned.Provider.players)
		if (i.playerID.steamID == executorID)
		{
			i.player.channel.send("askMessage", SDG.Unturned.ESteamCall.OWNER,
								  SDG.Unturned.ESteamPacket.UPDATE_UNRELIABLE_BUFFER,
								  new object[] { (byte)89 }); //89 being the message "Busy"
			return;
		}
}

Now, we can register our command to the games command list

In our init for the plugin, before the end of the plugin setup, add the following line:

SDG.Unturned.Commander.register(new CommandMessageA());

This will tell the command list "commander" to register a new instance of our command.

Now, we should be able to use /help MessageA - and /MessageA to execute our command.

P.S. It's not case sensitive, all commands including you using them get forced to lowercase before check.

Clone this wiki locally