Thread: CollectItems Method (Grand Exchange)

Results 1 to 2 of 2
  1. #1 CollectItems Method (Grand Exchange) 
    Registered Member
    Join Date
    May 2015
    Posts
    158
    Thanks given
    52
    Thanks received
    5
    Rep Power
    11
    I'm trying to collect items from the grand exchange.
    For example, these sharks; As you can see I have a full inventory, however, I have SHOULD be able to collect these sharks as I have some noted in my inventory already.

    Picture: https://prnt.sc/nti1qn

    Code:
    public boolean collectItems(int slot, int option) {
    		if (getOwner() == null)
    			return false;
    		int freeSlots = getOwner().getInventory().getFreeSlots();
    		if (freeSlots == 0) {
    			getOwner().getPackets().sendGameMessage("You don't have enough room in your inventory.");
    			return false;
    		}
    		Item item = receivedItems.get(slot);
    		if (item == null)
    			return false;
    		ItemDefinitions defs = item.getDefinitions();
    		if (defs.isStackable() && getOwner().getInventory().getNumberOf(item.getId()) + item.getAmount() < 0) {
    			Item add = new Item(item.getId(), Integer.MAX_VALUE - getOwner().getInventory().getNumberOf(item.getId()));
    			Item add1 = new Item(item.getId(), Integer.MAX_VALUE);
    			receivedItems.remove(add);
    			getOwner().getInventory().deleteItem(add1);
    			getOwner().getInventory().addItem(add1);
    			getOwner().getPackets().sendGameMessage("You don't have enough room in your inventory.");
    		} else if (!defs.isStackable() && option == (item.getAmount() == 1 ? 0 : 1)) {
    			Item add = new Item(item.getId(), item.getAmount() > freeSlots ? freeSlots : item.getAmount());
    			getOwner().getInventory().addItem(add);
    			receivedItems.remove(add);
    		} else {
    			getOwner().getInventory().addItem(new Item(defs.certId != -1 ? defs.certId : item.getId(), item.getAmount()));
    			receivedItems.remove(item);
    		}
    		update();
    		return true;
    	}
    Reply With Quote  
     

  2. #2  
    Registered Member
    TheChosenOne's Avatar
    Join Date
    Jan 2013
    Posts
    967
    Thanks given
    47
    Thanks received
    161
    Rep Power
    366
    It appears the message in your picture doesn't match the one in your code.
    So either you've updated something between taking that screenshot and posting the code, or your code isn't getting executed.

    But even if it were executed, you still do a check for free slots before you know if it is stackable (or noteable).
    So it could be something like this instead:
    Code:
    boolean added = false;
    if(stackable){
       if(playerHasRoom for stackables){
          addStackables
          added = true
       }
    } else {
       if(playerHasRoom for items){
          addItems
          added = true
       } else if(itemIsNoteable){
          if(playerHasRoom for notes){
             addNotes
             added = true
          }
       }
    }
    if(!added){
       message
       return
    }
    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. Online grand exchange
    By Rhys in forum Show-off
    Replies: 75
    Last Post: 10-06-2009, 07:35 AM
  2. ~~Base of Grand Exchange~~
    By green0981 in forum Tutorials
    Replies: 30
    Last Post: 10-24-2008, 02:30 PM
  3. Grand Exchange
    By Z in forum RS2 Server
    Replies: 41
    Last Post: 07-01-2008, 11:37 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •