No, you did the right thing. Your fix should work.
|
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:
GrandExchange.java:165-231Code: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)
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(); }
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)
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
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?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);
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.
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?
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |