Jump to content

cutted willow


Recommended Posts

Posted (edited)

Wouldn't it be "cut" not "cutted" ?

 

It's a variable name - it could be named 'dickcheese' for all we care and it would still work smile.png

 

@OP

 

It's very hard to tell what's wrong with that line without seeing how you're manipulating the variable. Care to post some further code snippets where you change it's value?

 

lemme write some sort of example if you want to do it via exp. a message listener would probably be a better way but exp works too ;p

//global vars
private int woodCut = 0; //ini

//onstart
experienceTracker.startAll();

//global methods
private int getChoppedLogs(int expPerLog) {
    return (experienceTracker.getGainedXp(Skill.WOODCUTTING) / expPerLog);
}

//onpaint method:
graphics.drawString("Logs chopped: " + getChoppedLogs(40), 0, 0);

//where graphics is ur graphics2d, 40 is the exp per log, and 0,0 are the co-ords for string

wrote it in the reply box so sorry if there are any errors

Edited by Apaec
Posted (edited)

The way I prefer to do inventory tracking is to compare a "last inventory" with the present inventory, and compare the differences. I wrote up some quick, untested code (it's based off my full accounting code, linked at the end). If it doesn't work let me know, but basically you'll call compareItems() whenever you want to be checking for changes in items (aka during woodcutting), and resetItems() whenever you bank.

 

Code is in spoiler:

    // WARNING: Untested code
    
    /** Holds the amount of willows we have cut */
    private int willowsCut = 0;
    /** Holds the last inventory that was compared */
    private Item[] lastInv;
    
    /**
     * Simple getter
     * @return the number of willows cut
     */
    public int getWillowsCut() {
        return willowsCut;
    }
    
    /**
     * Compares your last inventory with the current inventory.
     */
    public void compareItems() {
        if (lastInv == null) {
            lastInv = getInventory().getItems();
            return; // It will be the same, no need to check
        }
        
        String item = "Willow logs";
        Item[] currInv = getInventory().getItems();
        for (int i = 0; i < 28; i++) {
            // Check for the same thing
            if ((currInv[i] == null && lastInv == null)
                    || currInv[i].getName().equals(lastInv[i].getName()))
                continue; // Its the same, continue
            
            if (currInv[i] != null) {
                // We have an item when we didn't
                if (currInv[i].getName().equals(item))
                    willowsCut++; // It was a willow log, ++
            } else {
                // We don't have an item when we did
                if (lastInv[i].getName().equals(item))
                    willowsCut--; // It was a willow log, --
            }
        }
        lastInv = currInv; // Update the inv
    }
    
    /**
     * Run this when the lastInv needs refreshing, aka after banking
     */
    public void resetItems() {
        lastInv = getInventory().getItems();
    }

 

And a link to pastebin since there is no syntax coloring here(?): http://pastebin.com/ZUYr6rEH

Edit: There is, but I'll leave this here regardless

 

And here is a link to my full accounting code (sorry its mixed in with the paint). Its used in my API so it won't be the easiest port, but the general idea is there: https://github.com/Lem0ns/OSBotAPI/blob/master/painters/GenericPainter.java#L501

Edited by Lemons
  • Like 1
Posted

It's a variable name - it could be named 'dickcheese' for all we care and it would still work smile.png

 

@OP

 

It's very hard to tell what's wrong with that line without seeing how you're manipulating the variable. Care to post some further code snippets where you change it's value?

 

lemme write some sort of example if you want to do it via exp. a message listener would probably be a better way but exp works too ;p

//global vars
private int woodCut = 0; //ini

//onstart
experienceTracker.startAll();

//global methods
private int getChoppedLogs(int expPerLog) {
    return (experienceTracker.getGainedXp(Skill.WOODCUTTING) / expPerLog);
}

//onpaint method:
graphics.drawString("Logs chopped: " + getChoppedLogs(40), 0, 0);

//where graphics is ur graphics2d, 40 is the exp per log, and 0,0 are the co-ords for string

wrote it in the reply box so sorry if there are any errors

Thanks

 

The way I prefer to do inventory tracking is to compare a "last inventory" with the present inventory, and compare the differences. I wrote up some quick, untested code (it's based off my full accounting code, linked at the end). If it doesn't work let me know, but basically you'll call compareItems() whenever you want to be checking for changes in items (aka during woodcutting), and resetItems() whenever you bank.

 

Code is in spoiler:

    // WARNING: Untested code
    
    /** Holds the amount of willows we have cut */
    private int willowsCut = 0;
    /** Holds the last inventory that was compared */
    private Item[] lastInv;
    
    /**
     * Simple getter
     * @return the number of willows cut
     */
    public int getWillowsCut() {
        return willowsCut;
    }
    
    /**
     * Compares your last inventory with the current inventory.
     */
    public void compareItems() {
        if (lastInv == null) {
            lastInv = getInventory().getItems();
            return; // It will be the same, no need to check
        }
        
        String item = "Willow logs";
        Item[] currInv = getInventory().getItems();
        for (int i = 0; i < 28; i++) {
            // Check for the same thing
            if ((currInv[i] == null && lastInv == null)
                    || currInv[i].getName().equals(lastInv[i].getName()))
                continue; // Its the same, continue
            
            if (currInv[i] != null) {
                // We have an item when we didn't
                if (currInv[i].getName().equals(item))
                    willowsCut++; // It was a willow log, ++
            } else {
                // We don't have an item when we did
                if (lastInv[i].getName().equals(item))
                    willowsCut--; // It was a willow log, --
            }
        }
        lastInv = currInv; // Update the inv
    }
    
    /**
     * Run this when the lastInv needs refreshing, aka after banking
     */
    public void resetItems() {
        lastInv = getInventory().getItems();
    }

 

And a link to pastebin since there is no syntax coloring here(?): http://pastebin.com/ZUYr6rEH

Edit: There is, but I'll leave this here regardless

 

And here is a link to my full accounting code (sorry its mixed in with the paint). Its used in my API so it won't be the easiest port, but the general idea is there: https://github.com/Lem0ns/OSBotAPI/blob/master/painters/GenericPainter.java#L501

awsome

 

off topic, but how did you learn to code? and how long did it take you?

Youtube Java coding allot of people have tuts

It's a variable name - it could be named 'dickcheese' for all we care and it would still work smile.png

 

@OP

 

It's very hard to tell what's wrong with that line without seeing how you're manipulating the variable. Care to post some further code snippets where you change it's value?

 

lemme write some sort of example if you want to do it via exp. a message listener would probably be a better way but exp works too ;p

//global vars
private int woodCut = 0; //ini

//onstart
experienceTracker.startAll();

//global methods
private int getChoppedLogs(int expPerLog) {
    return (experienceTracker.getGainedXp(Skill.WOODCUTTING) / expPerLog);
}

//onpaint method:
graphics.drawString("Logs chopped: " + getChoppedLogs(40), 0, 0);

//where graphics is ur graphics2d, 40 is the exp per log, and 0,0 are the co-ords for string

wrote it in the reply box so sorry if there are any errors

I need the exp to get it automaticly is that possible getChoppedLogs(40),

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...