OK, i hope to make this tutorial short.
I will be working on fixing the smelting x5 x10 thing, working with erasedpkz.
Ok now we look at the method and it looks fine, but when clicking smelt 5 it only makes one bar. I looked at how the method works and it uses smeltAmount.
so If smeltAmount is greater than 0 then it will smelt, that means if we click smelt 5 and it doesn't make any bars or just makes one bar, that means the smeltAmount value has changed when clicking on Smelt 5.Code:public void smelt(int barType) { if (c.smeltAmount > 0) { c.getPA().closeAllWindows(); if (hasOres(barType)) { c.getItems().deleteItem(oreId, c.getItems().getItemSlot(oreId), 1); if (oreId2 > 0) c.getItems().deleteItem(oreId2, c.getItems().getItemSlot(oreId2), 1); c.getItems().addItem(barId,1); c.getPA().addSkillXP(exp * Config.SMITHING_EXPERIENCE, c.playerSmithing); c.getPA().refreshSkill(c.playerSmithing); c.smeltAmount--; c.smeltTimer = 1; } else { c.sendMessage("You do not have the required ores to smelt this."); c.getPA().removeAllWindows(); } } else { c.getPA().resetVariables(); } }
Once i find out the problem, i look for the cause.
In eclipse you can right click smeltAmount and click Open Call Heirarchy to view where smelthAmount is used.
I look for smeltAmount = 0 and find it in resetVariables() function.
Now we want to find out what uses resetVariables(). To do that we put a breakpoint on it, like soCode:public void resetVariables() { c.getCrafting().resetCrafting(); c.usingGlory = false; c.smeltInterface = false; c.smeltType = 0; c.smeltAmount = 0; c.woodcut[0] = c.woodcut[1] = c.woodcut[2] = 0; c.mining[0] = c.mining[1] = c.mining[2] = 0; }
[SPOILER="setting breakpoints images"]
[/SPOILER]
If you can't see images then in Eclipse, once selected the method resetVariables(), look at the outline box on the right side and right click resetVariables and click Toggle Method Breakpoint
Now we run the server in debug mode(F11), but for now disable the breakpoint.
Once you open up the smelting interface enable the breakpoint and click Smelt 5
The client should freeze, but it's ok. Go to Eclipse window and you should see something like this
[SPOILER="Hit breakpoint"]
[/SPOILER]
On the image we can see what used the resetVariable, what led up to it.
Click on each one of them and examine them, those in the debug Box. This is what i see, Smithing.smelt() method used c.getPA().closeAllWindows(); and closeAllWindows() function that i had contained declineTrade()
and declineTrade() has declineTrade(true) which leads to this function hereCode:public void closeAllWindows() { //synchronized(c) { if(c.getOutStream() != null && c != null) { c.getOutStream().createFrame(219); c.flushOutStream(); c.isBanking = false; c.isShopping = false; c.getTradeAndDuel().declineTrade(); c.getTradeAndDuel().declineDuel(); } //} }
[SPOILER="declineTrade(boolean tellOther)"][/SPOILER]Code:public void declineTrade(boolean tellOther) { c.getPA().removeAllWindows(); Client o = (Client) Server.playerHandler.players[c.tradeWith]; if (o == null) { return; } if(tellOther){ o.getTradeAndDuel().declineTrade(false); o.getTradeAndDuel().c.getPA().removeAllWindows(); } for(GameItem item : offeredItems) { if(item.amount < 1) { continue; } if(item.stackable) { c.getItems().addItem(item.id, item.amount); } else { for(int i = 0; i < item.amount; i++) { c.getItems().addItem(item.id, 1); } } } c.canOffer = true; c.tradeConfirmed = false; c.tradeConfirmed2 = false; offeredItems.clear(); c.inTrade = false; c.tradeWith = 0; }
declineTrade(boolean tellOther) method, which contains c.getPA().removeAllWindows(); and if we look at removeAllWindows()
we can see it has resetVariables() call and resetVariables sets the smeltAmount to Zero! ok we found our cause now!Code:public void removeAllWindows() { //synchronized(c) { if(c.getOutStream() != null && c != null) { c.getPA().resetVariables(); c.getOutStream().createFrame(219); c.flushOutStream(); } //} }
Things we can do is, either remove declineTrade from the closeAllWindows() method or change couple things.
You can try changing it to look something like this
Problem Solved!Code:public void closeAllWindows() { //synchronized(c) { if(c.getOutStream() != null && c != null) { c.getOutStream().createFrame(219); c.flushOutStream(); c.isBanking = false; c.isShopping = false; if(c.tradeStatus == 1) c.getTradeAndDuel().declineTrade(); if(c.duelStatus >= 1 && c.duelStatus <= 4) // lol made a mistake here, put the || instead of the && c.getTradeAndDuel().declineDuel(); } //} }
Please tell me how i can improve this tutorial :)






Reply With Quote![Fixing any errors in Eclipse[Debugging Tut]](http://ragezone.com/hyper728.png)

