[Easy] Adding a Free PKSet Using Armour Sets
Before I start, this is for beginners who will hopefully read and not just cp and leech. Please don't flame me for this, or say that it's already been released. The other tutorials are just armour sets like rs has, these are different.
[Only registered and activated users can see links. Click Here To Register...]
Purpose: Teaching you to add in item sets from GE item set boxes, stops pkset abusers
Difficulty: 2/10 if you're just starting
Assumed Knowledge: How to find the ItemOnItem class, and Commands class
Classes Modified: ItemOnItem, Commands
Tested On: z517, not too hard to convert you pali if you know what you're doing and want it.
Ok lets start off with Commands, we will just be adding a pkset command which is very easy.
Code:
if (cmd[0].equals("pkset")) {
Engine.playerItems.addItem(p, 11816, 1);//Bronze Armour Set Skirt
Engine.playerItems.addItem(p, 2347, 1);//Hammer
p.getActionSender().sendMessage(p, "Use the hammer and box together for your PK Set!");
}
What that does:
First it gets the command (cmd[0] refers to the first thing you type in after the colons.
Engine.playerItems.addItem ---how you add items. It can be changed as you will see in the next step.
And finally p.getActionSender().sendMessage( ---the way you send messages to the player in a z5-- source.
So that code tells your server that when a player types in pkset it should give them a pkset box, and a hammer to open it. Then tell them how to open it.
Now go to your ItemOnItem class, and find this code, it should be at the top if you're using a source without much added to it.
Code:
public void handlePacket(Player player, int packetId, int packetSize) {
if (player == null)
return;
int usedWith = player.stream.readSignedWordBigEndian();
int itemUsed = player.stream.readSignedWordA();
PlayerItems pi = new PlayerItems();
That is where you will be adding the rest of the code.
Start by declaring a boolean just above the public void in the code box, I use hammered.
Code:
boolean hammered = false;
public void handlePacket(Player player, int packetId, int packetSize) {
if (player == null)
return;
int usedWith = player.stream.readSignedWordBigEndian();
int itemUsed = player.stream.readSignedWordA();
PlayerItems pi = new PlayerItems();
Next, you need to add a check to see if the player is using a hammer, or using something on the hammer. This is so that instead of having to use the hammer on the box, or the box on the hammer, they player can do it in whatever order they want.
Code:
boolean hammered = false;
public void handlePacket(Player player, int packetId, int packetSize) {
if (player == null)
return;
int usedWith = player.stream.readSignedWordBigEndian();
int itemUsed = player.stream.readSignedWordA();
PlayerItems pi = new PlayerItems();
if ((itemUsed == 2347) || (usedWith == 2347)) {
hammered = true;
}
So if the hammer is being used, or something is being used on the hammer, hammered will become true.
Now to use the hammered boolean. Add this in inside of the handlePacket void's brackets.
Code:
/**
* Item Sets
* By Mr Steve of RuneServer
*/
//PKSET (Bronze skirt set)
if(hammered && (usedWith == 11816 || itemUsed == 11816)) {
pi.deleteItem(player, 11816, pi.getItemSlot(player, 11816), 1);
pi.deleteItem(player, 2347, pi.getItemSlot(player, 2347), 1);
//pi.deleteItem(player, 995, pi.getItemSlot(player, 995), AMOUNT-OF-GOLD-TO-BE-DELETED-GOES-HERE);//Optional, this takes away an amount of gp from a players inventory when they open the pkset, you may want to add a warning when they use the pkset command or log in.
pi.addItem(player, 10828, 1);//helm
pi.addItem(player, 10551, 1);//body
pi.addItem(player, 1079, 1);//legs
pi.addItem(player, 8850, 1);//defender
pi.addItem(player, 11732, 1);//boots
pi.addItem(player, 7462, 1);//gloves
pi.addItem(player, 10637, 1);//cape
pi.addItem(player, 1725, 1);//Ammy
pi.addItem(player, 6735, 1);//Ring
pi.addItem(player, 4151, 1);//Whip
pi.addItem(player, 5698, 1);//DDS
pi.addItem(player, 560, 200);//Death
pi.addItem(player, 9075, 400);//Astral
pi.addItem(player, 557, 1000);//Earth
hammered = false;
}
What it does:
if(hammered = true ---Checks to see if hammered is true, if not it doesn't do anything.
&& (itemUsed == 11816 || usedWith == 11816)) ---If hammered is true and the itemUsed is a bronze skirt box set, or usedWith is a bronze skirt set.
pi.deleteItem ---Deletes the items specified, I have it delete both the box, and the hammer. I make it delete the hammer so that the player doesn't have to drop it, it also makes it a tiny bit harder to keep on opening pksets just to sell the items in them.
hammered = false; ---Makes it so that the player has to use a hammer again, otherwise any item would work to open the box.
pi.addItem ---This is just like the addItem that you put in the Commands class, it's different because Codeusa added this in.
Code:
PlayerItems pi = new PlayerItems();
To add a timer.
Open Player.java and search for process(). Underneath that add in
Code:
if (boxTimer > 0) {
boxTimer--;
}
And above process declare a public int boxTimer. Save that we're done with it. Then in ItemOnItem add
Code:
if(player.boxTimer == 0) {
and
Code:
} else {
player.getActionSender().sendMessage(player, "You may only open one pkset a minute.");
hammered = false;
}
And your code should now look like this.
Code:
//PKSET (Bronze skirt set)
if(hammered && (usedWith == 11816 || itemUsed == 11816)) {
if(player.boxTimer == 0) {
pi.deleteItem(player, 11816, pi.getItemSlot(player, 11816), 1);
pi.deleteItem(player, 2347, pi.getItemSlot(player, 2347), 1);
pi.addItem(player, 10828, 1);//neit helm
pi.addItem(player, 10551, 1);//fighter torso
pi.addItem(player, 1079, 1);//rune legs
pi.addItem(player, 8850, 1);//rune defender
pi.addItem(player, 11732, 1);//dragon boots
pi.addItem(player, 7462, 1);//barrow gloves
pi.addItem(player, 10637, 1);//fire cape
pi.addItem(player, 1725, 1);//str Ammy
pi.addItem(player, 6735, 1);//warrior Ring
pi.addItem(player, 4151, 1);//Whip
pi.addItem(player, 5698, 1);//DDS
pi.addItem(player, 560, 200);//Death
pi.addItem(player, 9075, 400);//Astral
pi.addItem(player, 557, 1000);//Earth
player.boxTimer = 60;
} else {
player.getActionSender().sendMessage(player, "You may only open one pkset a minute.");
hammered = false;
}
}
There's a small anti leech, please don't post the answer it's very easy. You can change the 60 in player.boxTimer to what ever you want.
Hopefully you got that to work, to test it just log on any account and try the pkset command three times, first use the hammer on the box, then the box on the hammer, and then one of the other items on the box (a earth rune for example). The first two should open the box, and the last shouldn't. Good luck using this to add to your server. Feel free to post any questions.