Thread: [PI] Buy/Sell x

Results 1 to 5 of 5
  1. #1 [PI] Buy/Sell x 
    Registered Member
    Join Date
    Feb 2017
    Posts
    83
    Thanks given
    5
    Thanks received
    3
    Rep Power
    11
    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;
    	}
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Feb 2017
    Posts
    113
    Thanks given
    23
    Thanks received
    29
    Rep Power
    16
    On mobile so this might look messy...

    First off. Which shop/shop id is doing this?

    This part of code is in your buy item method


    //look at that if statement on first line

    All shop ids that aren't shop 29 will go to this code...


    f (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); looks like this line right here is the Culperate it is getting 1 amount of that specific item. Change that 1 to "amount" and that should be a good start





    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) {
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Feb 2017
    Posts
    83
    Thanks given
    5
    Thanks received
    3
    Rep Power
    11
    Quote Originally Posted by Catherby OS View Post
    On mobile so this might look messy...

    First off. Which shop/shop id is doing this?

    This part of code is in your buy item method


    //look at that if statement on first line

    All shop ids that aren't shop 29 will go to this code...


    f (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); looks like this line right here is the Culperate it is getting 1 amount of that specific item. Change that 1 to "amount" and that should be a good start





    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) {
    Don't know why, but this squares the number you buy, when I change it to "amount"
    Reply With Quote  
     

  4. #4  
    Registered Member
    _Ali's Avatar
    Join Date
    Apr 2014
    Posts
    382
    Thanks given
    67
    Thanks received
    147
    Rep Power
    252
    Code:
    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;
    					}
    				}
    			}
    You need to check if the item is stackable/noted item. If so you handle the buying without a loop. You should only loop through the amounts if its non stackable. That's your problem.
    Reply With Quote  
     

  5. Thankful user:


  6. #5  
    Registered Member
    Join Date
    Feb 2017
    Posts
    83
    Thanks given
    5
    Thanks received
    3
    Rep Power
    11
    Quote Originally Posted by _Ali View Post
    Code:
    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;
    					}
    				}
    			}
    You need to check if the item is stackable/noted item. If so you handle the buying without a loop. You should only loop through the amounts if its non stackable. That's your problem.
    not sure how to go about this.
    did you post the fix?
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [PI] Buy/Sell "X" amount bug.
    By xxskylarscapexx in forum Help
    Replies: 3
    Last Post: 01-27-2016, 09:09 AM
  2. [PI] Buy/Sell From Shop
    By Issh in forum Help
    Replies: 12
    Last Post: 09-12-2013, 02:52 PM
  3. [PI]Buy/Sell by 500 from shops
    By Famouz in forum Help
    Replies: 6
    Last Post: 08-26-2013, 02:49 AM
  4. [PI] Buy & Sell Commands
    By CrazeNation in forum Snippets
    Replies: 8
    Last Post: 01-04-2013, 11:30 AM
  5. Replies: 1
    Last Post: 08-21-2010, 08:24 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •