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
  • getModelColor


    choucter

    Recommended Posts

    Posted

    Hi All, I’m hoping someone can explain getModelColor to me. Javadocs shows

    public short[] getModelColors()

    which tells me the rock color is a short rather than an int. That helps, but the short[] part makes me think there's a built-in enum (or array) I can use, but I can’t find any information on it. Do I have to build my own color enum inside my script or is there an existing one in DB3?

    Posted

    To explain the issue in more detail, I have this code:

    public void mineThisOre(String oreName, short oreColor) {
    
    rock = GameObjects.closest(obj -> obj != null
            && obj.getModelColors() != null
            && obj.getName().equals("Rocks")
            && obj.getModelColors()[0] == oreColor);
    
    if (rock != null && rock.getModelColors() != null) {
        if (!player.isAnimating()) {
            if (rock.interact("Mine")) {
                sleepUntil(() -> player.isAnimating(), 2000);
            }
        }
    
       There’s more code below to handle dialogues, full inventory, etc.
    
    The 'mineThisOre' method above is called from:
    
    private void mining() {
    
        switch (setNumber) {
    
            case (0): // Tin and Copper
        	    if (Inventory.count("Tin ore") < tinOreAmount) {
            	mineThisOre("Tin ore", (short) 53);
        	    } else {
            	mineThisOre("Copper ore", (short) 4645);
    	    }
                break;
    
            case (1): // Iron 
                mineThisOre("Iron ore", (short) 2576);
                break;
    
       The ‘tinOreAmount’ variable is set at 14.
       The ‘setNumber’ variable is set when I select the ore to mine.
       There more code below for the other metals.

    The code works fine for tin and copper, but not for iron. When I try to mine iron, it randomly mines tin, copper and iron. If I use 2576 instead of oreColor when mining iron, it works fine. But that means adding a lot of extra lines to the code for each metal, rather than a single method that handles all of them.

    I think I’ve learned a lot about java and dreambot scripting in the last six months, but this one has me stumped. Since oreColor is declared as a short, why does it not pass 2576 when mining iron?

    Any ideas?

     

    Posted

    Hey there, you can view the model colors with our Game Explorer in the Game Objects tab, there are multiple model colors depending on how many parts of the model there are.

    IIRC, the first (index 0) model color changes for different types of ore and also if it's depleted.

    I believe the colors are the same across different rock models, but you might need to double check that with the Game Explorer.

    Posted

    Thanks! I found the problem. I have a variable that stores the enum ordinal for the rock to be mined, and it was losing it's value when I used it in the mining method. I made it a static variable and now everything is functioning correctly. 

    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.