26.04.2015, 09:57
Quote:
Is it possible to show me a short example how to make Player Commands with Arguments?
I tried to figure it out for a while now. Would help me out big time. |
You can create a method and tag it with [Command("commandname")]. This will create a command called /commandname and the method underneath it will be used to handle the command. Example:
PHP код:
[Command("group")] // Displays information about a group.
public static void group(Player player, string name)
{
Boolean groupFound = false;
foreach (Group group in Core.GroupList)
{
if (group.Name == name)
{
// We found a math for this group, continue!
groupFound = true;
player.SendClientMessage("[Group] " + group.Name + " (" + group.GroupType + " group)");
}
break;
}
if (!groupFound)
{
player.SendClientMessage(Color.IndianRed, "[Error] Group '" + name + "' could not be found.");
}
}
The arguments of the method will tell SampSharp what kind of arguments the command accepts! The first argument, player, will always be needed. You can add integers, strings, whatever as arguments and use them in the command! In the example above, string name is used to ask for the group name that the player wants information about.
If incorrent command arguments are given by a player, SampSharp will automatically correct the player by sending Usage: /group [name].
It cannot be simpler!
If you have any other questions, i'm more than happy to help you out.