Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Count itens collected


    marola

    Recommended Posts

    Posted

    Well, i have a trouble, how i make a code to count how many saltpetre i have digged?

     

    i made alot of thinks, but i cant count because i dont know use sleepUntil(new Condition()) pretty good yet

     

    i tried to do int count += 1, every time when the method "digSaltpetre" is in action, but it will count only 1 per loop, and in 1 loop i digg like 15-26 saltpetres...

     

    how i fix my problem? help me plz guys

    Posted
    @Override
        public void onItemChange(Item[] items) {
            for (Item item : items) {
                if (item.getName().equals("Saltpetre")) {
                   amount +=1;
                }
            }
        }
    

    i gues you could use the onItemChange method.

    Posted

    int temp = getInventory().count("item");

    action of digging

    int digged += (getInventory().count("item") - temp);

     

    think that shoud do it

    Posted

    thank you guys, ill post feedback


    Id keep the code but change

    amount += 1; to amount += item.getAmount(); simply because when you lag you might get 2 and it would only add one.

    Note that you need to implement the InventoryListener for this to work

     

    Edit: also make sure that i.getAmount() > 0 because when you bank It will give you a negative number because you have 'lost' the item

    can you explain me more about inventory listner, im having trouble, bcuz im so confuse where i put this method, my method to dig saltepetre is on a node called saltpetre that do somethings like dig, bank and walk back to dig spot, i need to implement the inventoryListener on Main class or NODE class?

    Posted

    Main

     

    Can you teach me 1 more time plz :P

    Well, i tried to make the Override method, but when i created it on MAIN classe, it says "REMOVE OVERRIDE ANOTATTION"

     

    i made what you guys said, but still having trouble, im newb on dreambot api,  but  im working for be good and help dreambot users

    	@Override
    	public void onItemChange(Item[] items) {
    		for (Item item : items) {
    			if (item.getName().equals("Saltpetre") && item.getAmount() > 0) {
    				saltpetreCount += item.getAmount();
    			}
    		}
    	}
    
    Posted

     

    Can you teach me 1 more time plz :P

    Well, i tried to make the Override method, but when i created it on MAIN classe, it says "REMOVE OVERRIDE ANOTATTION"

     

    i made what you guys said, but still having trouble, im newb on dreambot api, but im working for be good and help dreambot users

    @Override	public void onItemChange(Item[] items) {		for (Item item : items) {			if (item.getName().equals("Saltpetre") && item.getAmount() > 0) {				saltpetreCount += item.getAmount();			}		}	}

    you did not implement InventoryListener, it goes at the top of your script right after extends AbstractScript

     

    public class LavaDragons extends AbstractScript implements InventoryListener {

    Posted

    you did not implement InventoryListener, it goes at the top of your script right after extends AbstractScript

     

    public class LavaDragons extends AbstractScript implements InventoryListener {

     

    thank you ;) they solved my problem on discord, whatever, thank you again

     

     

    and here is my feedback

     

    i implemented InventoryListener like you guys said and made it 

    	@Override
    	public void onItemChange(Item[] items) {
    		for (Item item : items) {
    			if (item != null && item.getName().contains("Saltpetre") && item.getAmount() > 0) {
    				saltpetreCount += item.getAmount();
    			}
    		}
    	}
    

    now its working, thank you alot guys

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.