In this tutorial i will be explaining about the basics of different types of commands, with additions of what you can do and linking them with voids and other bits.
Difficulty 2/10 - you need to be able to intake what im telling you. I will not spoon feed you.
well most commands are in a certain structure, which basicly is:
Code:
if(command.equals("######")) {
teleX = ####;
teleY = ####;
}
in that bit of coding, it is basicly saying if you type in the command ::###### it will tele you to the X: #### Y: ####
In this command we can add certain lines which will enable certain things. for example, if you wanted the command only able for administrators only, it would be:
Code:
if(command.equals("######") && playerRights >= 2) {
teleX = ####;
teleY = ####;
}
so basicly if you type in the command and your playerrights are equal to or higher than 2, you are able to use the command. Now if you didn't have the correct rights you could add an else for something to happen if requirements are not met. In this example i will show you the sendmessage coding for the else:
Code:
if(command.equals("######") && playerRights >= 2) {
teleX = ####;
teleY = ####;
} else {
sendMessage("##########");
}
in sendmessage, whatever you typed into the ######## area, it will appear only to you in the chatbox.
now we can start making the commands give items or exp by adding these lines:
Items:
Code:
addItem(xxxx, xxxxxx);
the first xxxx is the ItemdID the second is the amount of the item.
Exp:
Code:
addSkillXP(xxxx, xxxxx);
the first xxxx is the amount of exp it will give, the second xxx is the ID of the skill.
so a command with these added could look like this:
Code:
if(command.equals("######") && playerRights >= 2) {
teleX = ####;
teleY = ####;
addItem(xxx, xxxx);
addSkillXP(xxx, xxx);
} else {
sendMessage("##########");
}
now if you wanted the command to do an animation you would add this line:
Code:
stillgfx(xxx, absY, absX);
the xxxx is just the ID of the gfc animation you are adding.
Now if you wanted the command to shout out something, as if you were typing it you would add this line:
in the ### you would add the text it would say. now implimenting the two new things i mentioned, a command could look like this:
Code:
if(command.equals("######") && playerRights >= 2) {
teleX = ####;
teleY = ####;
addItem(xxx, xxxx);
addSkillXP(xxx, xxx);
stillgfx(xxx, absY, absX);
txt4 = "######";
} else {
sendMessage("##########");
}
now if you wanted the command to send a message to everyone in their chatbox, you would add this line:
Code:
PlayerHandler.messageToAll = ("############");
in the ###### area you would add the message that will send to everyone. If, in the text you wanted to impliment the playersname into it, you could add it like this:
Code:
PlayerHandler.messageToAll = (playerName + "#######");
which would make it show that the person who did the message first with the message added to it.
now the command could lok like this:
Code:
if(command.equals("######") && playerRights >= 2) {
teleX = ####;
teleY = ####;
addItem(xxx, xxxx);
addSkillXP(xxx, xxx);
stillgfx(xxx, absY, absX);
txt4 = "######";
} else {
sendMessage("##########");
PlayerHandler.messageToAll = (playerName + "#######");
}
* I am adding them randomly around to give you an idea on what you could do.*
then you could also change it so that the command could take an item of you. the lines you would use for this is:
Code:
if (playerHasItem(xxxx1, xxxx2)) {
deleteItem(xxxx1, xxxx2);
change the xxxx1 to the item id and xxxx2 to the amount of the item. in a command you could do it like this *with other command elements added*
Code:
if(command.equals("######") && playerRights >=2) {
if (playerHasItem(xxxx1, xxxx2)) {
deleteItem(xxxx1, xxxx2);
} else {
sendMessage("#########");
}
}
another thing you could do is make the command run a void and the line used is:
change the #### to void name then add:
Code:
public void #####()
{
}
inbetween the {} you can add bits of coding, some of which are used in commands, so it could look like:
Code:
public void #######()
{
sendMessage("###########");
addItem(xxxx, xxxxx);
}
then in the command you would add the void name in the format shown before so it would look something like this:
Code:
if(command.equals("######") && playerRights >=2) {
######();
} else {
sendMessage("#########");
}
there you go, just some of the basics to commands, have fun!!
credits: 100% me