The result:
http://tinypic.com/player.php?v=avsfbo&s=5
Description: In this tutorial, you will be creating the Destroy item option.
Difficulty: 2/10
Assumed Knowledge: How to read.
Tested Server: Palidino76's 508
Files Modified: Player.java, PacketManager.java, DropItem.java.
Procedure
Step one.
First, you need to add your untradable items that you want to be able to be destroyed, to the 'untradable' array, which is located in items.java. If you do not know where items.java is, then look for it yourself.
The array will look something like this:
Code:
untradable[] = {####, ####};
It is obvious that the '####' should be the item Id's that need to be placed in there, so add any item Id's in there, that you wish to be untradable.
For example the Firecape Id, is 6570. I have that in my Untradable array.
Step two.
In player.java, you now need to declare the destroy Item arrays:
Code:
/**
* Destroy item arrays
*/
public int[] destroyItem = new int[28];
public int[] destroyItemAmt = new int[28];
And the variable:
Code:
/**
* Destroy item variable
*/
public int destroyItemInt;
Step three
You now need to open up DropItem.java.
You will see this:
Code:
if (!Engine.items.isUntradable(itemId)) {
The codes below that, until the closing bracket of that 'if' statement, are for items that are not in the 'untradable' array.
So find the closing bracket for that specific 'if' statement (It will be in line with it if you are having trouble finding it).
Once you have found it, replace it with this:
Code:
} else if (Engine.items.isUntradable(itemId)) {
for (int i = 0; i < p.items.length; i++) {
p.destroyItem[i] = itemId;
p.destroyItemAmt[i] = 1;
p.destroyItemInt = itemId;
p.frames.showChatboxInterface(p, 94);
p.frames.setString(p, "Clicking yes will permanently delete this item.", 94, 11);
p.frames.setString(p, "", 94, 10);
p.frames.setString(p, "If you want to keep this item click no.", 94, 12);
p.frames.setString(p, ""+ Engine.items.getItemName(itemId) +"", 94, 13);
p.frames.setItems(p, 94, 0, 1, p.destroyItem, p.destroyItemAmt);
}
}
The 'else if' statement is the statement that allows us to place codes for items that Are in the 'untradable' array.
Code:
for (int i = 0; i < p.items.length; i++) {
^ This Is the loop through all the items in the inventory.
Code:
p.destroyItem[i] = itemId;
^ This is making the Loop variable (i) in the destroyItem array, equal the item Id that you are trying to destroy/drop.
Code:
p.destroyItemAmt[i] = 1;
^ This is making the Amount of the item being destroyed, 1, since nearly all destroyable items are Unstackable.
Code:
p.frames.showChatboxInterface(p, 94);
^ This is showing the Destroy Item interface in the chatbox area.
Code:
p.frames.setString(p, "Clicking yes will permanently delete this item.", 94, 11);
p.frames.setString(p, "", 94, 10);
p.frames.setString(p, "If you want to keep this item click no.", 94, 12);
Those three lines are setting the strings of the text on the chatbox interface.
Code:
p.frames.setString(p, ""+ Engine.items.getItemName(itemId) +"", 94, 13);
That line is setting the string of the item you are trying to destroy.
And finally:
Code:
p.frames.setItems(p, 94, 0, 1, p.destroyItem, p.destroyItemAmt);
That is setting the item that is going to be destroyed, onto the interface, along with the Amount of the item (1).
Step five.
We now have the full destroy item interface showing in the Chatbox, but the buttons do not do anything yet, so that is what we are going to add next.
Now head over to PacketManager.java.
Go down to packet 63.
If you do not already have it, this is a simple example of the packet that you can add:
Code:
case 63:
p.frames.removeChatboxInterface(p);
break;
First off, add these to the packet:
Code:
int clickId = p.stream.readUnsignedWord();
int clickId2 = p.stream.readUnsignedWord();
Those will be used to section off the options.
Now you need to make a switch statement out of that integer:
Code:
switch (clickId2) {
In this switch statement, there needs to be two 'cases'; Case 1024 and Case 1280.
Case 1024 is the 'Yes' Option on the destroy Item interface.
Case 1280 is the 'No' Option on the destroy Item interface, and will remove the chatbox interface.
Here are the two Cases:
Case 1024:
Code:
case 1024: // Yes option
if (p.destroyItemInt > 0) {
Server.engine.playerItems.deleteItem(p, p.destroyItemInt, Server.engine.playerItems.getItemSlot(p, p.destroyItemInt), 1);
p.destroyItemInt = 0;
p.frames.removeChatboxInterface(p);
}
break;
This will get the item slot of the item to be destroyed, and delete that item. (This is incase the player has two of the item). It will also reset the 'destroyItemInt' integer.
Case 1280:
Code:
case 1280: // No option
p.destroyItemInt = 0;
p.frames.removeChatboxInterface(p);
break;
That will simply remove the chatbox interface, and reset the 'destroyItemInt' integer.
Finally you need to add a closing bracket to end the switch statement.
Now you can save all the files you have edited, compile, and run.
Once more, the result:
http://tinypic.com/player.php?v=avsfbo&s=5
Enjoy.