I followed a tutorial on this, and it works. HOWEVER, it buys every item 1 at a time, and it takes FOREVER. How would I go about fixing this?
BankX2.java
Code:
case 3900:
if (Xamount <= 2000) {
c.getShops().buyItem(c.xRemoveId, c.xRemoveSlot, Xamount);
}
else {
c.sendMessage("You cannot buy more than 2000 at a time.");
}
break;
case 3823:
if (Xamount <= 2000) {
c.getShops().sellItem(c.xRemoveId , c.xRemoveSlot, Xamount);
}
else {
c.sendMessage("You cannot sell more than 2000 at a time.");
}
break;
also figured this might be important
Code:
int Xamount = c.getInStream().readDWord();
if (Xamount < 0)// this should work fine
{
Xamount = c.getItems().getItemAmount(c.xRemoveId);
}
if (Xamount == 0) {
Xamount = 1;
}
buyitem method
Code:
public boolean buyItem(int itemID, int fromSlot, int amount) {
if (Server.getMultiplayerSessionListener().inAnySession(c))
return false;
if (c.myShopId == 14) {
skillBuy(itemID);
return false;
} else if (c.myShopId == 15) {
buyVoid(itemID);
return false;
}
if (itemID != itemID) {
return false;
}
if (!shopSellsItem(itemID))
return false;
if (amount > 0) {
if (amount > ShopHandler.ShopItemsN[c.myShopId][fromSlot]) {
amount = ShopHandler.ShopItemsN[c.myShopId][fromSlot];
}
// double ShopValue;
// double TotPrice;
int TotPrice2 = 0;
// int Overstock;
int Slot = 0;
int Slot1 = 0;// Tokkul
if (c.myShopId == 80) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 34) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 12 || c.myShopId == 49 || c.myShopId == 50) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 44) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 79) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 9) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 32) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 33) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 34) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 10) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 23) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 77) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 64) {
handleOtherShop(itemID, amount);
return false;
}
if (c.myShopId == 75) {
handleOtherShop(itemID, amount);
return false;
}
for (int i = amount; i > 0; i--) {
TotPrice2 = (int) Math.floor(getItemShopValue(itemID, 0, fromSlot));
Slot = c.getItems().getItemSlot(995);
Slot1 = c.getItems().getItemSlot(6529);
if (Slot == -1 && c.myShopId != 29) {
c.sendMessage("You don't have enough coins.");
break;
}
if (Slot1 == -1 && (c.myShopId == 29)) {
c.sendMessage("You don't have enough tokkul.");
break;
}
if (TotPrice2 <= 1) {
TotPrice2 = (int) Math.floor(getItemShopValue(itemID, 0, fromSlot));
TotPrice2 *= 1.66;
}
if (c.myShopId != 29) {
if (c.playerItemsN[Slot] >= TotPrice2) {
if (c.getItems().freeSlots() > 0) {
c.getItems().deleteItem(995, c.getItems().getItemSlot(995), TotPrice2);
c.getItems().addItem(itemID, 1);
ShopHandler.ShopItemsN[c.myShopId][fromSlot] -= 1;
ShopHandler.ShopItemsDelay[c.myShopId][fromSlot] = 0;
if ((fromSlot + 1) > ShopHandler.ShopItemsStandard[c.myShopId]) {
ShopHandler.ShopItems[c.myShopId][fromSlot] = 0;
}
} else {
c.sendMessage("You don't have enough space in your inventory.");
break;
}
} else {
c.sendMessage("You don't have enough coins.");
break;
}
}
if (c.myShopId == 29) {
if (c.playerItemsN[Slot1] >= TotPrice2) {
if (c.getItems().freeSlots() > 0) {
c.getItems().deleteItem(6529, c.getItems().getItemSlot(6529), TotPrice2);
c.getItems().addItem(itemID, 1);
ShopHandler.ShopItemsN[c.myShopId][fromSlot] -= 1;
ShopHandler.ShopItemsDelay[c.myShopId][fromSlot] = 0;
if ((fromSlot + 1) > ShopHandler.ShopItemsStandard[c.myShopId]) {
ShopHandler.ShopItems[c.myShopId][fromSlot] = 0;
}
} else {
c.sendMessage("You don't have enough space in your inventory.");
break;
}
} else {
c.sendMessage("You don't have enough tokkul.");
break;
}
}
}
c.getItems().resetItems(3823);
resetShop(c.myShopId);
updatePlayerShop();
return true;
}
return false;
}
sellitem method
Code:
public boolean sellItem(int itemID, int fromSlot, int amount) {
if (Server.getMultiplayerSessionListener().inAnySession(c)) {
return false;
}
if (itemID == 863 || itemID == 11230 || itemID == 6585 || itemID == 6586 || itemID == 869 || itemID == 868 || itemID == 867 || itemID == 866 || itemID == 4740 || itemID == 9244
|| itemID == 11212 || itemID == 892 || itemID == 9194 || itemID == 9243 || itemID == 9242 || itemID == 9241 || itemID == 9240
|| itemID == 9239 || itemID == 882 || itemID == 884 || itemID == 886 || itemID == 888 || itemID == 890) {
c.sendMessage("You can't sell this item.");
return false;
}
if (c.myShopId == 14)
return false;
if (c.myShopId == 3 || c.myShopId == 4 || c.myShopId == 5 || c.myShopId == 6 || c.myShopId == 8 || c.myShopId == 47 || c.myShopId == 48
|| c.myShopId == 111 || c.myShopId == 113)
return false;
if (c.myShopId == 21)
return false;
if (c.myShopId == 22)
return false;
if (c.myShopId == 23)
return false;
if (c.myShopId == 77)
return false;
if (c.myShopId == 64)
return false;
if (c.myShopId == 75)
return false;
if (c.myShopId != 12 && c.myShopId != 49 && c.myShopId != 50 && c.myShopId != 26 && c.myShopId != 20) {
return false;
}
/*
* if (c.myShopId == 47) return false; if (c.myShopId == 48) return
* false;
*/
/*
* if (c.myShopId == 8) return false;
*/
if (c.myShopId == 9 || c.myShopId == 32 || c.myShopId == 33 || c.myShopId == 34)
return false;
for (int i : Config.ITEM_SELLABLE) {
if (i == itemID) {
c.sendMessage("You can't sell " + ItemAssistant.getItemName(itemID).toLowerCase() + ".");
return false;
}
}
if (c.getRights().isAdministrator() && !Config.ADMIN_CAN_SELL_ITEMS) {
c.sendMessage("Selling items as an admin has been disabled.");
return false;
}
if (amount > 0 && itemID == (c.playerItems[fromSlot] - 1)) {
if (ShopHandler.ShopSModifier[c.myShopId] > 1) {
boolean IsIn = false;
for (int i = 0; i <= ShopHandler.ShopItemsStandard[c.myShopId]; i++) {
if (itemID == (ShopHandler.ShopItems[c.myShopId][i] - 1)) {
IsIn = true;
break;
}
}
if (IsIn == false) {
c.sendMessage("You can't sell " + ItemAssistant.getItemName(itemID).toLowerCase() + " to this store.");
return false;
}
}
if (amount > c.playerItemsN[fromSlot]
&& (Item.itemIsNote[(c.playerItems[fromSlot] - 1)] == true || Item.itemStackable[(c.playerItems[fromSlot] - 1)] == true)) {
amount = c.playerItemsN[fromSlot];
} else if (amount > c.getItems().getItemAmount(itemID) && Item.itemIsNote[(c.playerItems[fromSlot] - 1)] == false
&& Item.itemStackable[(c.playerItems[fromSlot] - 1)] == false) {
amount = c.getItems().getItemAmount(itemID);
}
// double ShopValue;
// double TotPrice;
int TotPrice2 = 0;
int TotPrice3 = 0;
// int Overstock;
for (int i = amount; i > 0; i--) {
TotPrice2 = (int) Math.floor(getItemShopValue(itemID, 1, fromSlot));
TotPrice3 = (int) Math.floor(getSpecialItemValue(itemID));
if (c.myShopId == 26) {
TotPrice2 *= 0.667;
}
if (c.getItems().freeSlots() > 0 || c.getItems().playerHasItem(995)) {
if (Item.itemIsNote[itemID] == false) {
c.getItems().deleteItem(itemID, c.getItems().getItemSlot(itemID), 1);
} else {
c.getItems().deleteItem(itemID, fromSlot, 1);
}
if (c.myShopId == 12 || c.myShopId == 49 || c.myShopId == 50) {
c.getItems().addItem(2996, (int) Math.ceil(TotPrice3 *= 0.65));
} else if (c.myShopId != 12 && c.myShopId != 29 && c.myShopId != 49 && c.myShopId != 50) {
c.getItems().addItem(995, TotPrice2);
} else if (c.myShopId == 29) {
c.getItems().addItem(6529, TotPrice2);
}
// addShopItem(itemID, 1);
} else {
c.sendMessage("You don't have enough space in your inventory.");
break;
}
}
c.getItems().resetItems(3823);
resetShop(c.myShopId);
updatePlayerShop();
return true;
}
return true;
}