Player Equipment & Items:
Difficulty: 5
Packages Modified: net.varek.rs2d.model, net.varek.rs2d.packethandler, net.varek.rs2d.test, net.varek.rs2d.net
Process:
We are going to add the ability to Equip items, in this tutorial I will be not only giving you the proper source code
to add Equipment to your Rs2d server, I will also be teaching you how everything works. So before we begin please plan
to spend a good 30 Minutes to an hour on this.
Package: net.varek.rs2d.model.
First, we are going to create an Equipment class, if you have an existing Equipment class, delete it.
[PHP]
package net.varek.rs2d.model;
import net.varek.rs2d.model.EquipmentSlot;
public class Equipment {
private Player player;
private ItemModel[] items = new ItemModel[14];
public Equipment(Player p) {
this.player = p;
}
public int getId(int type) {
if(!isEquipped(type)) return -1;
return items[type].getItemId();
}
public int getAmount(int type) {
if(!isEquipped(type)) return -1;
return items[type].getAmount();
}
public boolean isEquipped(int type) {
return items[type] != null;
}
/**
* Thanks newbiehacker for the next few methods.
*/
public void equip(int type, int id, int amount) {
if(id == -1)
return;
if(isEquipped(EquipmentSlot.getSlot(id)))
player.getInventory().add(getId(EquipmentSlot.getS lot(id)), getAmount(EquipmentSlot.getSlot(id)));
items[EquipmentSlot.getSlot(id)] = new ItemModel(id, amount);
player.getAppearance().setChanged(true);
player.getActionSender().sendEquipment(EquipmentSl ot.getSlot(id));
}
public void unequip(int type) {
items[type] = null;
player.getAppearance().setChanged(true);
player.getActionSender().sendEquipment(type);
}
public void setId(int type, int id) {
if(items[type] != null) items[type].setItemId(id);
player.getActionSender().sendEquipment(type);
}
public void setAmount(int type, int amount) {
if(items[type] != null) items[type].setAmount(amount);
player.getActionSender().sendEquipment(type);
}
public static final int HAT=0, CAPE=1, AMULET=2, WEAPON=3,
TORSO=4, SHIELD=5, LEGS=7, HANDS=9, FEET=10,
RING=12, ARROWS=13;
}
[/PHP]
Now, as you can see, we have quite a few methods, I'll go over the main ones.
[PHP]
public void equip(int type, int id, int amount) {
if(id == -1)
return;
if(isEquipped(EquipmentSlot.getSlot(id)))
player.getInventory().add(getId(EquipmentSlot.getS lot(id)), getAmount(EquipmentSlot.getSlot(id)));
items[EquipmentSlot.getSlot(id)] = new ItemModel(id, amount);
player.getAppearance().setChanged(true);
player.getActionSender().sendEquipment(EquipmentSl ot.getSlot(id));
}
[/PHP]
The above method is used to Equip an item, what it does is check if an item is already equiped in the current slot
and if so, removes that item, than equips the new item.
[PHP]
public void unequip(int type) {
items[type] = null;
player.getAppearance().setChanged(true);
player.getActionSender().sendEquipment(type);
}
[/PHP]
This method sets the current slot (Integer: type) to a null value, than lets the client know that it has
changed.
Alright, enough about the Equipment class, next we need to make: EquipmentSlot.java, if you already have this class
remove it.
[PHP]
package net.varek.rs2d.model;
public class EquipmentSlot {
public static int getSlot(int itemIndex){
int slot = 3;
if(isPlate(itemIndex)) slot = 4;
if(isFullHelm(itemIndex)) slot = 0;
if(isFullMask(itemIndex)) slot = 0;
if(isCape(itemIndex)) slot = 1;
if(isBoot(itemIndex)) slot = 10;
if(isGlove(itemIndex)) slot = 9;
if(isShield(itemIndex)) slot = 5;
if(isHat(itemIndex)) slot = 0;
if(isAmulet(itemIndex)) slot = 2;
if(isArrow(itemIndex)) slot = 13;
if(isRing(itemIndex)) slot = 12;
if(isBody(itemIndex)) slot = 4;
if(isLeg(itemIndex)) slot = 7;
return slot;
}
public static boolean isPlate(int itemID)
{
for (int i = 0; i <platebody.length; i++)
if (platebody[i] == itemID)
return true;
return false;
}
public static boolean isFullHelm(int itemID)
{
for (int i = 0; i < fullHelm.length; i++)
if (fullHelm[i] == itemID)
return true;
return false;
}
public static boolean isFullMask(int itemID)
{
for (int i = 0; i < fullMask.length; i++)
if (fullMask[i] == itemID)
return true;
return false;
}
public static boolean isCape(int itemID)
{
for (int i = 0; i < capes.length; i++)
if (capes[i] == itemID)
return true;
return false;
}
public static boolean isBoot(int itemID)
{
for (int i = 0; i < boots.length; i++)
if (boots[i] == itemID)
return true;
return false;
}
public static boolean isGlove(int itemID)
{
for (int i = 0; i < gloves.length; i++)
if (gloves[i] == itemID)
return true;
return false;
}
public static boolean isShield(int itemID)
{
for (int i = 0; i < shields.length; i++)
if (shields[i] == itemID)
return true;
return false;
}
public static boolean isHat(int itemID)
{
for (int i = 0; i < hats.length; i++)
if (hats[i] == itemID)
return true;
return false;
}
public static boolean isAmulet(int itemID)
{
for (int i = 0; i < amulets.length; i++)
if (amulets[i] == itemID)
return true;
return false;
}
public static boolean isArrow(int itemID)
{
for (int i = 0; i < arrows.length; i++)
if (arrows[i] == itemID)
return true;
return false;
}
public static boolean isRing(int itemID)
{
for (int i = 0; i < rings.length; i++)
if (rings[i] == itemID)
return true;
return false;
}
public static boolean isBody(int itemID)
{
for (int i = 0; i < body.length; i++)
if (body[i] == itemID)
return true;
return false;
}
public static boolean isLeg(int itemID)
{
for (int i = 0; i < legs.length; i++)
if (legs[i] == itemID)
return true;
return false;
}
public static int capes[] = {7783, 7648, 7626, 7628, 7630, 7632, 7634, 7636, 7638, 7640, 7645, 7646, 7647, 7650, 7652, 7656, 7675, 7676, 7677, 7678, 7679, 7681, 3759, 6959, 3761,3763,3765,3777,3779,3781,3783,3785,3787,3789, 4041,4042,4514,4516,6111,6570,6568,1007,1019,1021, 1023,1027,1029,1031,1052,2412,2413,2414,4304,4315, 4317,4319,4321,4323,4325,4327,4329,4331,4333,4335, 4337,4339,4341,4343,4345,4347,4349,4351,4353,4355, 4357,4359,4361,4363,4365,4367,4369,4371,4373,4375, 4377,4379,4381,4383,4385,4387,4389,4391,4393,4395, 4397,4399,4401,4403,4405,4407,4409,4411,4413,4514, 4516,6070,6568,6570};
public static int boots[] = {6666,6377,6367,6357,3393,1837,1846,3105,3107,3700 ,3791,5064,7159,88,6619,7114,6328,6920,6349,7596,6 061,6106,88,89,626,628,630,632,634,1061,1837,1846, 2577,2579,2894,2904,2914,2924,2934,3061,3105,3107, 3791,4097,4107,4117,4119,4121,4123,4125,4127,4129, 4131,4310,5064,5345,5557,6069,6106,6143,6145,6147, 6328};
public static int gloves[] = {6379,6369,6359,1495,1580,6068,3391,6629,6330,6922 ,7595,7462,2491,1065,2487,2489,3060,1495,775,777,7 78,6708,1059,1063,1065,1580,2487,2489,2491,2902,29 12,2922,2932,2942,3060,3799,4095,4105,4115,4308,55 56,6068,6110,6149,6151,6153};
public static int shields[] = {7810, 7787,6889,746,747,1203,1205,1207,1209,1211,1213,12 15,1217,2997,746,7332,7334,7336,7338,7340,7342,734 4,7346,7348,7350,7352,7354,7356,7358,7360,6631,663 3,7053,1171,1173,1175,1177,1179,1181,1183,1185,118 7,1189,1191,1193,1195,1197,1199,1201,1540,2589,259 7,2603,2611,2621,2629,2659,2667,2675,2890,3122,348 8,3758,3839,3840,3841,3842,3843,3844,4072,4156,422 4,4225,4226,4227,4228,4229,4230,4231,4232,4233,423 4,4507,4512,6215,6217,6219,6221,6223,6225,6227,622 9,6231,6233,6235,6237,6239,6241,6243,6245,6247,624 9,6251,6253,6255,6257,6259,6261,6263,6265,6267,626 9,6271,6273,6275,6277,6279,6524};
public static int hats[] = {7797, 1506,6548,6547,7319,7321,7323,7325,7327,6885,6886, 6887,2645,2647,2649,7534,7539,3327,3329,3331,3333, 3335,3337,3339,3341,3343,74,6621,6623,7394,7396,71 12,7124,7130,7136,7594,6856,6858,6860,6862,6326,74 00,6656,4856,4857,4858,4859,4880,4881,4882,4883,49 04,4905,4906,4907,4928,4929,4930,4931,4952,4953,49 54,4955,4976,4977,4978,4979,4732,4753,4611,6188,61 82,4511,4056,4071,4724,2639,2641,2643,2665,6109,55 25,5527,5529,5531,5533,5535,5537,5539,5541,5543,55 45,5547,5549,5551,74,579,656,658,660,662,664,740,1 017,1037,1038,1040,1042,1044,1046,1048,1050,1053,1 055,1057,1137,1139,1141,1143,1145,1147,1149,1151,1 153,1155,1157,1159,1161,1163,1165,1949,2422,2581,2 587,2595,2605,2613,2619,2627,2631,2633,2635,2637,2 651,2657,2673,2900,2910,2920,2930,2940,2978,2979,2 980,2981,2982,2983,2984,2985,2986,2987,2988,2989,2 990,2991,2992,2993,2994,2995,3057,3385,3486,3748,3 749,3751,3753,3755,3797,4041,4042,4071,4089,4099,4 109,4164,4302,4506,4511,4513,4515,4551,4567,4708,4 716,4724,4745,4753,4856,4857,4858,4859,4880,4881,4 882,4883,4904,4905,4906,4907,4952,4953,4954,4955,4 976,4977,4978,4979,5013,5014,5554,5574,6109,6128,6 131,6137,6182,6188,6335,6337,6339,6345,6355,6365,6 375,6382,6392,6400,6918};
public static int amulets[] = {6581,6577,1716,1722,1718,1724,6857,6859,6861,6863 ,7803,6585,86,87,295,421,552,589,1478,1692,1694,16 96,1698,1700,1702,1704,1706,1708,1710,1712,1725,17 27,1729,1731,4021,4081,4250,4677,6040,6041,6208};
public static int arrows[] = {78,598,877,878,879,880,881,882,883,884,885,886,88 7,888,889,890,891,892,893,942,2532,2533,2534,2535, 2536,2537,2538,2539,2540,2541,2866,4160,4172,4173, 4174,4175,4740,5616,5617,5618,5619,5620,5621,5622, 5623,5624,5625,5626,5627,6061,6062};
public static int rings[] = {6735,6731,6737,6575,6347,773,1635,1637,1639,1641, 1643,1645,2550,2552,2554,2556,2558,2560,2562,2564, 2566,2568,2570,2572,4202,4657,6465};
public static int body[] = {4712,14,7784, 6065,430,75,6371,6361,6351,6341,581,3793,577,546,5 44,5026,5028,6394,6402,426,5030,5032,5034,3767,376 9,3771,3773,3775,6617,6615,7134,7110,7122,7128,113 1,1133,1135,1129,6322,7362,7364,2896,2906,2916,292 6,2936,1844,636,638,640,642,644,7592,6129,4298,113 5,2499,2501,6654,7374,4091,7376,7370,7372,6139,250 3,7399,7390,7392,5575,6916,1035,540,5553,4757,1833 ,6388,6384,2501,2499,1355,4111,4101,6186,6184,6180 ,3058,4509,4504,4069,4728,4736,6107,2661,3140,1101 ,1103,1105,1107,1109,1111,1113,1115,1117,1119,1121 ,1123,1125,1127,1129,1131,1133,1135,2499,2501,2583 ,2591,2599,2607,2615,2623,2653,2669,3387,3481,4720 ,4728,4749,4892,4893,4894,4895,4916,4917,4918,4919 ,4964,4965,4966,4967,6107,6133,6322};
public static int legs[] = {5044,5042,5046,6067,6353,6363,6373,6343,548,428,5 42,6625,6627,7116,7126,7132,7138,1095,1097,1099,63 24,7366,7368,2898,2908,2918,2928,2938,1845,646,648 ,650,652,654,7593,4300,1835,538,6655,1033,6141,613 5,7382,7384,7378,7380,5555,7386,7388,7398,4759,638 6,6390,2497,2495,2493,1099,4113,4103,4093,6924,618 7,6185,6181,3059,4510,4505,4070,6108,538,542,548,1 011,1013,1015,1067,1069,1071,1073,1075,1077,1079,1 081,1083,1085,1087,1089,1091,1093,2585,2593,2601,2 609,2617,2625,2655,2663,2671,3059,3389,3472,3473,3 474,3475,3476,3477,3478,3479,3480,3483,3485,3795,4 087,4585,4714,4722,4730,4738,4751,4759,4874,4875,4 876,4877,4898,4899,4900,4901,4922,4923,4924,4925,4 946,4947,4948,4949,4970,4971,4972,4973,4994,4995,4 996,4997,5048,5050,5052,5576,6107,6130,6187,6390,6 386,6390,6396,6404,6809};
public static int platebody[] = {75,6371,6361,6351,6341,3793,577,581,546,544,426,3 767,3769,3771,3773,3775,6617,6322,2896,2906,2916,2 926,2936,1844,636,638,640,642,644,5575,6129,6139,4 298,7399,6916,7390,5032,5034,5030,1035,540,5553,47 57,1833,1835,6388,6384,1355,4111,4101,4868,4869,48 70,4871,4892,4893,4894,4895,4916,4917,4918,4919,49 40,4941,4942,4943,4964,4965,4966,4967,4988,4989,49 90,49914091,6186,6184,6180,3058,4509,4504,4069,472 8,4736,4712,6107,2661,3140,1115,1117,1119,1121,112 3,1125,1127,2583,2591,2599,2607,2615,2623,2653,266 9,3481,4720,4728,4749,2661};
public static int fullHelm[] = {7797, 7534,4551,4745,6623,5574,7112,7124,7130,7136,7594, 6326,4732,4753,6188,4511,4056,4071,4724,6109,2665, 1153,1155,1157,1159,1161,1163,1165,2587,2595,2605, 2613,2619,2627,2657,2673,3486,6402,6394};
public static int fullMask[] = {1506,6326,4732,4708,4724,4716,4732,5554,4611,6188 ,3507,4511,4056,4071,4724,2665,6109,1053,1055,1057 };
}
[/PHP]
There's not a whole lot to explain about this class, however I will go over one of the methods.
[PHP]
public static boolean isBody(int itemID)
{
for (int i = 0; i < body.length; i++)
if (body[i] == itemID)
return true;
return false;
}
[/PHP]
This is a Boolean Method, what it does is loop through the body array, and check to see if it is equal
to integer itemID, if it is, it returns True, otherwise it will return false. (This is a great way to get an
understanding on the use of For Loops.)
Now, close and Save EquipmentSlot.java, you will now be creating, or Replacing: Inventory.java.
[PHP]
package net.varek.rs2d.model;
public class Inventory {
private Player player;
public ItemModel[] items = new ItemModel[28];
public int id;
public Inventory(Player p) {
this.player = p;
}
public int getAmount(int id) {
for (ItemModel item : items) {
if (item == null) continue;
if (item.getItemId() == id)
return item.getAmount();
}
return 0;
}
public boolean add(int id, int amount) {
if(!ItemModel.itemStackable[id]){
amount = 1;
}
if ((id < 0 || id > 7955) || (amount < 0)) return false;
for (ItemModel item : items) {
if (item == null) continue;
if (item.getItemId() == id && item.itemStackable[id]) {
item.setAmount(item.getAmount() + amount);
player.getActionSender().sendInventory();
return true;
}
}
for (int i = 0; i < 28; i++) {
if (items[i] != null) continue;
items[i] = new ItemModel(id, amount);
player.getActionSender().sendInventory();
return true;
}
return false;
}
public boolean remove(int id, int amount, int slot) {
if (items[slot].getItemId() == id && items[slot].getAmount() >= amount) {
if (items[slot].getAmount() - amount > 0)
items[slot].setAmount(items[slot].getAmount() - amount);
else
items[slot] = null;
player.getActionSender().sendInventory();
return true;
}
return false;
}
public boolean remove(int id, int amount) {
for (int i = 0; i < 28; i++) {
if (items[i] == null) continue;
if (remove(id, amount, i))
return true;
}
return false;
}
public boolean removeAll(int id) {
for (int i = 0; i < 28; i++) {
if (items[i] == null) continue;
if (remove(id, items[i].getAmount(), i))
return true;
}
return false;
}
public int freeSlots() {
int freeItemSlots = 0;
for (int i = 0; i < items.length; i++) {
if(items[i] == null) freeItemSlots++;
}
return freeItemSlots;
}
public void setAmount(int id, int amount) {
if (amount < 0) amount = 0;
for (int i = 0; i < items.length; i++) {
if (items[i] == null) continue;
if (items[i].getItemId() == id) {
items[i].setAmount(amount);
if (items[i].getAmount() <= 0)
items[i] = null;
break;
}
}
}
public void moveItems(int from, int to, int interfaceId) {
if(interfaceId == 3724) {
ItemModel tempI;
ItemModel tempN;
tempI = items[from];
items[from] = items[to];
items[to] = tempI;
}
}
public int getId(int type) {
return items[type].getItemId();
}
public ItemModel[] getItems() {
return items;
}
}
[/PHP]
Again, another self explanatory class, this one manages all Items in the players inventory, I will explain
a method from it.
[PHP]
public boolean add(int id, int amount) {
if(!ItemModel.itemStackable[id]){
amount = 1;
}
if ((id < 0 || id > 7955) || (amount < 0)) return false;
for (ItemModel item : items) {
if (item == null) continue;
if (item.getItemId() == id && item.itemStackable[id]) {
item.setAmount(item.getAmount() + amount);
player.getActionSender().sendInventory();
return true;
}
}
for (int i = 0; i < 28; i++) {
if (items[i] != null) continue;
items[i] = new ItemModel(id, amount);
player.getActionSender().sendInventory();
return true;
}
return false;
}
[/PHP]
This is what I am sure you were focused on, this method works by looping through all of the items, and checking to see
if the item is equal to the one you wish to add, if so it checks if the item stacks or not, finally it will
send the information to the client, which shows you the item.
Now, this class makes references to ItemModel.java, so create that class now.
[PHP]
package net.varek.rs2d.model;
import java.io.*;
public class ItemModel {
private int itemId, amount;
public static boolean[] itemStackable = new boolean[10000];
private boolean stackable, bankable, tradeable;
public ItemModel(int id, int a) {
this.itemId = id;
this.amount = a;
}
public int getItemId() {
return itemId;
}
public void setItemId(int itemId) {
this.itemId = itemId;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public void setStackable(boolean can) {
this.stackable = can;
}
public boolean isStackable() {
return stackable;
}
public void setBankable(boolean can) {
this.bankable = can;
}
public boolean isBankable() {
return bankable;
}
public void setTradeable(boolean can) {
this.tradeable = can;
}
public boolean isTradeable() {
return tradeable;
}
static {
int counter = 0;
int c;
try {
FileInputStream dataIn = new FileInputStream(new File("data/stackable.dat"));
while ((c = dataIn.read()) != -1) {
if (c == 0)
itemStackable[counter] = false;
else
itemStackable[counter] = true;
itemStackable[6570] = false;
counter++;
}
dataIn.close();
} catch (IOException e) {
System.out.println("Error Loading Stackable Item Data.");
}
}
}
[/PHP]
This class mainly consists of Get and Set methods, which are commonly used throughout the Java programming
language, however you will notice at the end, I ripped a peice of code from a wL server, this is fine because
it does the job, and properly. However I reccommend loading the Stackable information from an XML file
or an Sql database. for now make sure to create a folder in the root directory of your server entitled
'data' and place 'stackable.dat' in the file, I will include a download link at the bottom.
Now, we are going to be doing some modifications to your Player class, in the same package.
in the Player class, declare the following.
[PHP]
private Equipment equipment = new Equipment(this);
private Inventory inventory = new Inventory(this);
[/PHP]
You will also need to create a get and set method for each, I will provide the methods below.
[PHP]
public Equipment getEquipment() {
return equipment;
}
public void setEquipment(Equipment equipment) {
this.equipment = equipment;
}
public Inventory getInventory() {
return inventory;
}
public void setInventory(Inventory inventory) {
this.inventory = inventory;
}
[/PHP]
You can now close the Player class, and navigate to the: net.varek.rs2d.test Package.
Open the class: Main.java
Add the following import:
[PHP]
import net.varek.rs2d.packethandler.Equipment;
[/PHP]
Now, locate your packet Ids, they will look something like the following:
[PHP]
handleIds = new int[][] {
{ 0, 86, 210, 121, 3 },
knownIds,
{ 164, 98, 248 },
{ 185 },
{ 4 },
{ 101 },
{ 214 },
{ 87 },
{ 236 },
{ 41, 145 },
{ 103 },
{ 128 },
{ 132, 252, 70 }
};
[/PHP]
Add a comma to your last { ### } and add:
[PHP]
{ 41, 145 }
[/PHP]
Scroll down a bit untill you see what should look like:
[PHP]
handlers = new PacketHandler[] {
new QuietPacketHandler(),
new DebuggingPacketHandler(packetNames),
new Walking(),
new ActionButton(),
new PublicChat(),
new PlayerDesign(),
new ItemSlotChange(),
new DropItem(),
new PickupItem(),
new Equipment(),
new Command(),
new Combat(),
new Object()
};
}
[/PHP]
add a comma to your last new ClassNameHere(). Now add:
[PHP]
new Equipment()
[/PHP]
You can now close this class, and create the: Equipment.java class in the: net.varek.rs2d.packethandler package.
[PHP]
package net.varek.rs2d.packethandler;
import net.varek.rs2d.model.Player;
import net.varek.rs2d.net.Packet;
import net.varek.rs2d.packethandler.*;
import org.apache.mina.common.IoSession;
public class Equipment implements PacketHandler {
//Bank bank = null;
public void handlePacket(Packet p, IoSession session) {
Player player = (Player) session.getAttachment();
switch (p.getId()) {
case 41: // Equip
int id = p.readShort();
int slot = p.readShortA();
int interfaceID = p.readShortA();
player.getInventory().removeAll(id);
player.getEquipment().equip(slot, id, 1);
break;
case 145: // Unequip
interfaceID = p.readShortA();
slot = p.readShortA();
id = p.readShortA();
if (interfaceID == 1688)
player.getInventory().add(id, 1);
switch (interfaceID) {
case 1688: player.getEquipment().unequip(slot); break;
//case 5064: player.getBank().deposit(id, 1); break;
//case 5382: player.getBank().withdraw(id, 1); break;
}
break;
}
}
}
[/PHP]
The above class, to put it in lame mans terms, recieves packet data, and tells the server what you are equipping or unequipping.
Close and save the above class, now last navigate to: net.varek.rs2d.net. Open the class: ActionSender.java.
In this class you will be replacing an already existing method aswell as adding one, navigate to the method:
sendEquipment(int)
and replace it with:
[PHP]
public void sendEquipment(int type) {
int itemId = 0, amount = 0;
if (player.getEquipment().isEquipped(type)) {
itemId = player.getEquipment().getId(type);
amount = player.getEquipment().getAmount(type);
} else {
itemId = -1;
amount = 0;
}
StaticPacketBuilder packet = new StaticPacketBuilder().setId(34)
.addShort(1688)
.addByte((byte)type)
.addShort(itemId + 1);
if(amount > 254)
packet.addByte((byte)255).addInt(amount);
else packet.addByte((byte)amount);
packet.setSize(Packet.Size.VariableShort);
player.getIoSession().write(packet.toPacket());
}
public void sendInventory() {
StaticPacketBuilder packet = new StaticPacketBuilder().setId(53)
.addShort(3214)
.addShort(28);
for (ItemModel item : player.getInventory().getItems()) {
if (item == null) {
packet.addByte((byte) 0).addLEShortA(0);
} else {
if(item.getAmount() > 254)
packet.addByte((byte)255).addInt2(item.getAmount() );
else packet.addByte((byte)item.getAmount());
packet.addLEShortA(item.getItemId() + 1);
}
}
packet.setSize(Packet.Size.VariableShort);
player.getIoSession().write(packet.toPacket());
}
[/PHP]
Now, to equip an item use the below statement:
[PHP]
player.getEquipment().equip(slot, itemIndex, amount);
[/PHP]
and to add an item to your players inventory simply:
[PHP]
player.getInventory().add(itemIndex, amount);
[/PHP]
Also, you will need the data folder, with the stackable.dat inside, You MUST place it in the Root folder of your server, so put it
in the same folder that the folder: net is in.
Here is stackable.dat:
[Only registered and activated users can see links. Click Here To Register...]
Credits: Newbiehacker, Varek, winterLove, Misc people.
Edit: Some methods you may need in: StaticPacketBuilder.java class.
[PHP]
public StaticPacketBuilder addShort(int val) {
ensureCapacity(curLength + 2);
addByte((byte) (val >> 8), false);
addByte((byte) val, false);
return this;
}
public StaticPacketBuilder addLEShort(int val) {
ensureCapacity(curLength + 2);
addByte((byte) val, false);
addByte((byte) (val >> 8), false);
return this;
}
public StaticPacketBuilder addLEShortA(int i) {
ensureCapacity(curLength + 2);
addByte((byte)(i + 128), false);
addByte((byte)(i >> 8), false);
return this;
}
public StaticPacketBuilder setShort(int val, int offset) {
payload[offset++] = (byte) (val >> 8);
payload[offset++] = (byte) val;
if(curLength < offset+2) {
curLength += 2;
}
return this;
}
[/PHP]
Also, in ActionSender.java, you need to import:
[PHP]
import net.varek.rs2d.model.Inventory;
import net.varek.rs2d.model.ItemModel;
[/PHP]
Also in Packet.java (net.varek.rs2d.net):
add:
[PHP]
public short readShortA() {
return (short) ((short) ((pData[caret++] & 0xff) << 8) | (short) (pData[caret++] - 128 & 0xff));
}
[/PHP]
Thank's I Jonas I.
