Thread: [718/743] Grand Exchange Converting

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 [718/743] Grand Exchange Converting 
    Registered Member
    Join Date
    Aug 2016
    Posts
    16
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    I'm not the best at Java and I'm having some issues converting this Grand Exchange base to Matrix, and I could use some help.

    I have everything working now except for buying items and claiming sold items. When clicking the item to buy items, nothing happens; it just returns to the buy screen.
    However, when trying to sell items, it successfully goes through, except I get this error:

    Code:
    ERROR! THREAD NAME: World Thread
    java.lang.NullPointerException
    	at com.rs.game.grandexchange.GrandExchange$2.run(GrandExchange.java:222)
    	at com.rs.game.tasks.WorldTasksManager.processTasks(WorldTasksManager.java:18)
    	at com.rs.cores.WorldThread.run(WorldThread.java:25)
    GrandExchange.java:165-231
    Code:
    public void acceptOffer(final boolean buying) {
    		player.getInterfaceManager().closeChatBoxInterface();
    		final int box = (Integer) player.getGEAttribute("box");
    		final int itemId = (Integer) player.getGEAttribute("item");
    		final int amount = (Integer) player.getGEAttribute("amount");
    		final int price = (Integer) player.getGEAttribute("price");
    		try {
    			if (player.getGEAttribute("notEnough") != null) {
    				player.out("You do not have enough of this item to sell "
    						+ Utils.formatTypicalInteger((int) player
    								.getGEAttribute("notEnough")) + " of it.");
    				return;
    			}
    		} catch (NullPointerException e) {
    
    		}
    		if (buying) {
    			if (player.getMoneyPouch() < price * amount
    					&& player.getInventory().getNumberOf(995) < price * amount) {
    				player.out("You do not have enough gold peice"
    						+ (price == 1 ? "" : "s") + " to purchase "
    						+ (amount > 1 ? "these items." : "this item."));
    				return;
    			}
    			if (player.getMoneyPouch() >= price * amount) {
    				player.setMoneyPouch( player.getMoneyPouch() - ( price * amount ) );
    				player.refreshMoneyPouch();
    			} else {
    				player.getInventory().deleteItem(995, price * amount);
    			}
    			player.getPackets().setGe(player, box, 1, itemId, price, amount, 0);
    			WorldTasksManager.schedule(new WorldTask() {
    
    				@Override
    				public void run() {
    					player.getPackets().setGe(player, box, 5, itemId,
    							price, amount, amount);
    					player.offer[box] = new Offer(player, box, price, itemId,
    							amount, GrandExchangeOfferType.SELLING_PROGRESS
    									.getOpcode(), GrandExchangeType.BUYING,
    							Calendar.getInstance().getTime());
    					player.out("<col=006600>One or more of your GrandExchange Offers have been updated.");
    				}
    			}, 4);		} else {
    			if (player.getGEAttribute("note") != null) {
    				player.getInventory().deleteItem(
    						((int) player.getGEAttribute("note")), amount);
    			} else {
    				player.getInventory().deleteItem(itemId, amount);
    			}
    			player.getPackets().setGe(player, box, 9, itemId, price, amount, 0);
    			WorldTasksManager.schedule(new WorldTask() {
    
    				@Override
    				public void run() {
    					player.getPackets().setGe(player, box, 13, itemId,
    							price, amount, amount);
    					player.offer[box] = new Offer(player, box, price, itemId,
    							amount, GrandExchangeOfferType.SUBMITTING_BUY_OFFER
    									.getOpcode(), GrandExchangeType.SELLING,
    							Calendar.getInstance().getTime());
    					player.out("<col=006600>One or more of your GrandExchange Offers have been updated.");
    				}
    			}, 4);
    		}
    		open();
    	}
    Reply With Quote  
     

  2. #2  
    Contributor

    clem585's Avatar
    Join Date
    Sep 2013
    Posts
    3,788
    Thanks given
    706
    Thanks received
    702
    Rep Power
    570
    No, you did the right thing. Your fix should work.
    Project thread
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Aug 2016
    Posts
    16
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Sorry, I edited the post after you commented, I have a new issue (I forgot to compile those changes and everything works except for that)
    Reply With Quote  
     

  4. #4  
    Contributor

    clem585's Avatar
    Join Date
    Sep 2013
    Posts
    3,788
    Thanks given
    706
    Thanks received
    702
    Rep Power
    570
    Huh not sure, I think the "offer" var in player might be nulled. Make sure you initialized it.
    Project thread
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Aug 2016
    Posts
    16
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    I did initialize it: public transient Offer[] offer = new Offer[6];

    EDIT: This error is constantly repeated in my console as well

    It appears I had some things missing. Even after adding them in:
    Code:
    	public void acceptOffer(final boolean buying) {
    		player.getInterfaceManager().closeChatBoxInterface();
    		final int box = (Integer) player.getGEAttribute("box");
    		final int itemId = (Integer) player.getGEAttribute("item");
    		final int amount = (Integer) player.getGEAttribute("amount");
    		final int price = (Integer) player.getGEAttribute("price");
    		try {
    			if (player.getGEAttribute("notEnough") != null) {
    				player.out("You do not have enough of this item to sell "
    						+ Utils.formatTypicalInteger((int) player
    								.getGEAttribute("notEnough")) + " of it.");
    				return;
    			}
    		} catch (NullPointerException e) {
    
    		}
    		if (buying) {
    			if (player.getMoneyPouch() < price * amount
    					&& player.getInventory().getNumberOf(995) < price * amount) {
    				player.out("You do not have enough gold peice"
    						+ (price == 1 ? "" : "s") + " to purchase "
    						+ (amount > 1 ? "these items." : "this item."));
    				return;
    			}
    			if (player.getMoneyPouch() >= price * amount) {
    				player.setMoneyPouch( player.getMoneyPouch() - ( price * amount ) );
    			} else {
    				player.getInventory().deleteItem(995, price * amount);
    			}
    			player.getPackets().setGe(player, box, 1, itemId, price, amount, 0);
    			WorldTasksManager.schedule(new WorldTask() {
    
    				@Override
    				public void run() {
    					int tr = Utils.random(amount);// This was missing
    					player.getPackets().setGe(player, box,
    							tr >= amount ? 5 : 3, itemId, price, amount,
    							tr >= amount ? amount : tr);
    					player.offer[box] = new Offer(player, box, price, itemId,
    							amount, GrandExchangeOfferType.SELLING_PROGRESS
    									.getOpcode(), GrandExchangeType.BUYING,
    							Calendar.getInstance().getTime());
    					player.offer[box].setAmountTransacted(tr);// This was missing
    					player.offer[box].accept();// This was missing
    				}
    			}, 4);
    		} else {
    			if (player.getGEAttribute("note") != null) {
    				player.getInventory().deleteItem(
    						((int) player.getGEAttribute("note")), amount);
    			} else {
    				player.getInventory().deleteItem(itemId, amount);
    			}
    			player.getPackets().setGe(player, box, 9, itemId, price, amount, 0);
    			WorldTasksManager.schedule(new WorldTask() {
    
    				@Override
    				public void run() {
    					int t = Utils.random(amount); // This was missing
    					player.getPackets().setGe(player, box,
    							t >= amount ? 13 : 12, itemId, price, amount, t);
    					player.offer[box] = new Offer(player, box, price, itemId,
    							amount, GrandExchangeOfferType.SUBMITTING_BUY_OFFER
    									.getOpcode(), GrandExchangeType.SELLING,
    							Calendar.getInstance().getTime());
    					player.offer[box].setAmountTransacted(t);// This was missing
    					player.offer[box].accept();// This was missing
    				}
    			}, 4);
    		}
    		open();
    	}
    Last edited by iViscosity; 10-11-2017 at 12:30 AM. Reason: error
    Reply With Quote  
     

  6. #6  
    Contributor

    clem585's Avatar
    Join Date
    Sep 2013
    Posts
    3,788
    Thanks given
    706
    Thanks received
    702
    Rep Power
    570
    Quote Originally Posted by iViscosity View Post
    I did initialize it: public transient Offer[] offer = new Offer[6];

    EDIT: This error is constantly repeated in my console as well

    It appears I had some things missing. Even after adding them in:
    Code:
    	public void acceptOffer(final boolean buying) {
    		player.getInterfaceManager().closeChatBoxInterface();
    		final int box = (Integer) player.getGEAttribute("box");
    		final int itemId = (Integer) player.getGEAttribute("item");
    		final int amount = (Integer) player.getGEAttribute("amount");
    		final int price = (Integer) player.getGEAttribute("price");
    		try {
    			if (player.getGEAttribute("notEnough") != null) {
    				player.out("You do not have enough of this item to sell "
    						+ Utils.formatTypicalInteger((int) player
    								.getGEAttribute("notEnough")) + " of it.");
    				return;
    			}
    		} catch (NullPointerException e) {
    
    		}
    		if (buying) {
    			if (player.getMoneyPouch() < price * amount
    					&& player.getInventory().getNumberOf(995) < price * amount) {
    				player.out("You do not have enough gold peice"
    						+ (price == 1 ? "" : "s") + " to purchase "
    						+ (amount > 1 ? "these items." : "this item."));
    				return;
    			}
    			if (player.getMoneyPouch() >= price * amount) {
    				player.setMoneyPouch( player.getMoneyPouch() - ( price * amount ) );
    			} else {
    				player.getInventory().deleteItem(995, price * amount);
    			}
    			player.getPackets().setGe(player, box, 1, itemId, price, amount, 0);
    			WorldTasksManager.schedule(new WorldTask() {
    
    				@Override
    				public void run() {
    					int tr = Utils.random(amount);// This was missing
    					player.getPackets().setGe(player, box,
    							tr >= amount ? 5 : 3, itemId, price, amount,
    							tr >= amount ? amount : tr);
    					player.offer[box] = new Offer(player, box, price, itemId,
    							amount, GrandExchangeOfferType.SELLING_PROGRESS
    									.getOpcode(), GrandExchangeType.BUYING,
    							Calendar.getInstance().getTime());
    					player.offer[box].setAmountTransacted(tr);// This was missing
    					player.offer[box].accept();// This was missing
    				}
    			}, 4);
    		} else {
    			if (player.getGEAttribute("note") != null) {
    				player.getInventory().deleteItem(
    						((int) player.getGEAttribute("note")), amount);
    			} else {
    				player.getInventory().deleteItem(itemId, amount);
    			}
    			player.getPackets().setGe(player, box, 9, itemId, price, amount, 0);
    			WorldTasksManager.schedule(new WorldTask() {
    
    				@Override
    				public void run() {
    					int t = Utils.random(amount); // This was missing
    					player.getPackets().setGe(player, box,
    							t >= amount ? 13 : 12, itemId, price, amount, t);
    					player.offer[box] = new Offer(player, box, price, itemId,
    							amount, GrandExchangeOfferType.SUBMITTING_BUY_OFFER
    									.getOpcode(), GrandExchangeType.SELLING,
    							Calendar.getInstance().getTime());
    					player.offer[box].setAmountTransacted(t);// This was missing
    					player.offer[box].accept();// This was missing
    				}
    			}, 4);
    		}
    		open();
    	}
    Are you sure the player is iniated correctly? getPackets() could be nulled. Anyway, just debug and find out what is nulled. I can only take guesses until I find it at this point lol.
    Project thread
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Aug 2016
    Posts
    16
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Code:
    			WorldTasksManager.schedule(new WorldTask() {
    
    				@Override
    				public void run() {
    					System.out.println( player.offer );
    					int tr = Utils.random(amount);
    					player.getPackets().setGe(player, box,
    							tr >= amount ? 5 : 3, itemId, price, amount,
    							tr >= amount ? amount : tr);
    					player.offer[box] = new Offer(player, box, price, itemId,
    							amount, GrandExchangeOfferType.SELLING_PROGRESS
    									.getOpcode(), GrandExchangeType.BUYING,
    							Calendar.getInstance().getTime());
    					player.offer[box].setAmountTransacted(tr);
    					player.offer[box].accept();
    				}
    			}, 4);
    I'm getting "null" printed out. So you were right, 'player' was null. Could it be because I'm on a local server (as in, I'm running it from Eclipse)? How can I prevent this?


    EDIT: Fixed the nulling. Simply kept the declaration at the top of the class, and in the 'init' void, set 'offer = new Offer[6]'

    Now I'm having a different issue: aborting doesn't work. It aborts properly, but then gives money back when it should give the item back.
    Reply With Quote  
     

  8. #8  
    Contributor

    clem585's Avatar
    Join Date
    Sep 2013
    Posts
    3,788
    Thanks given
    706
    Thanks received
    702
    Rep Power
    570
    That's probably a bug in the code itself. Just modify it so it gives the correct thing back.
    Project thread
    Reply With Quote  
     

  9. #9  
    Registered Member
    Join Date
    Aug 2016
    Posts
    16
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    It seems like I can even click the claim buttons either... even if there is an item in there. I have my debug on so I can see if it is sending packets properly, but when I click the two boxes where you would claim items, nothing shows up in my console. Maybe the buttons themselves are broken?
    Reply With Quote  
     

  10. #10  
    Contributor

    clem585's Avatar
    Join Date
    Sep 2013
    Posts
    3,788
    Thanks given
    706
    Thanks received
    702
    Rep Power
    570
    Component ids for the same interface from one revision to another. If you're not using the same exact rev. has in the snippet, make sure you have the right ids.
    Project thread
    Reply With Quote  
     

Page 1 of 2 12 LastLast

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. [718] major grand exchange dupe fix
    By Bc1151 in forum Tutorials
    Replies: 23
    Last Post: 10-01-2014, 06:04 PM
  2. 718/742 grand exchange lagg fix ?
    By Stimulant in forum Help
    Replies: 23
    Last Post: 06-15-2014, 08:31 PM
  3. 718/745 Grand Exchange
    By Nice Day in forum Help
    Replies: 8
    Last Post: 01-24-2014, 06:23 AM
  4. [718] Dungeoneering & Grand Exchange
    By Root in forum Buying
    Replies: 3
    Last Post: 06-03-2013, 07:52 PM
  5. ProjectPK | 718/728 | Grand Exchange |
    By L3git in forum Projects
    Replies: 10
    Last Post: 10-02-2012, 05:18 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
  •