Code:
public boolean addItem(int item, int amount, boolean dropitem) {
synchronized(c) {
if (amount < 1) {
amount = 1;
}
if(item <= 0) {
return false;
}
if ((((freeSlots() >= 1) || playerHasItem(item, 1)) && Item.itemStackable[item]) || ((freeSlots() > 0) && !Item.itemStackable[item])) {
for (int i = 0; i < c.playerItems.length; i++) {
if ((c.playerItems[i] == (item + 1)) && Item.itemStackable[item]
&& (c.playerItems[i] > 0)) {
c.playerItems[i] = (item + 1);
if (((c.playerItemsN[i] + amount) < Config.MAXITEM_AMOUNT)
&& ((c.playerItemsN[i] + amount) > -1)) {
c.playerItemsN[i] += amount;
} else {
c.playerItemsN[i] = Config.MAXITEM_AMOUNT;
}
updateInventory = true;
updateInventory();
i = 30;
return true;
}
}
for (int i = 0; i < c.playerItems.length; i++) {
if (c.playerItems[i] <= 0) {
c.playerItems[i] = item + 1;
if ((amount < Config.MAXITEM_AMOUNT) && (amount > -1)) {
c.playerItemsN[i] = 1;
if (amount > 1) {
c.getItems().addItem(item, amount - 1);
return true;
}
} else {
c.playerItemsN[i] = Config.MAXITEM_AMOUNT;
}
updateInventory = true;
updateInventory();
i = 30;
return true;
}
}
return false;
} else {
updateInventory = true;
updateInventory();
if (dropitem) {
Server.itemHandler.createGroundItem(c, item, c.absX, c.absY, amount,c.playerId);
} else {
c.sendMessage("Not enough space in your inventory.");
}
return false;
}
}
}
Without using boolean:
Code:
public boolean addItem(int item, int amount) {
synchronized(c) {
if (amount < 1) {
amount = 1;
}
if(item <= 0) {
return false;
}
if ((((freeSlots() >= 1) || playerHasItem(item, 1)) && Item.itemStackable[item]) || ((freeSlots() > 0) && !Item.itemStackable[item])) {
for (int i = 0; i < c.playerItems.length; i++) {
if ((c.playerItems[i] == (item + 1)) && Item.itemStackable[item]
&& (c.playerItems[i] > 0)) {
c.playerItems[i] = (item + 1);
if (((c.playerItemsN[i] + amount) < Config.MAXITEM_AMOUNT)
&& ((c.playerItemsN[i] + amount) > -1)) {
c.playerItemsN[i] += amount;
} else {
c.playerItemsN[i] = Config.MAXITEM_AMOUNT;
}
updateInventory = true;
updateInventory();
i = 30;
return true;
}
}
for (int i = 0; i < c.playerItems.length; i++) {
if (c.playerItems[i] <= 0) {
c.playerItems[i] = item + 1;
if ((amount < Config.MAXITEM_AMOUNT) && (amount > -1)) {
c.playerItemsN[i] = 1;
if (amount > 1) {
c.getItems().addItem(item, amount - 1);
return true;
}
} else {
c.playerItemsN[i] = Config.MAXITEM_AMOUNT;
}
updateInventory = true;
updateInventory();
i = 30;
return true;
}
}
return false;
} else {
updateInventory = true;
updateInventory();
Server.itemHandler.createGroundItem(c, item, c.absX, c.absY, amount,c.playerId);
//c.sendMessage("Not enough space in your inventory.");
return false;
}
}
}
this is simple as fuck, do not replace ur current additem with this one unless u dont care about urself and dont mind about fixing thousands of errors, just add it close to ur current one.
What this will do? if you do not have enough inventory spaces it will drop the item u added, but thats optional.
How to use it?
additem(item, amount, true/false) if you set it true it will drop the item if u do not have inventory spaces, sometimes u might want it to say you do not have enough inventory spaces instead of dropping the item so i made it optional.
Please tell me how to improve this, and if i made any mistake, didnt test but should work.