Jump to content

My first script <3


jiggerjaw

Recommended Posts

Having some problems and also have some questions...
The biggest problem is I open the bank, then dont deposit anything...  I used getBank().depositAll();

It also seems to hang up sometimes...  Once it stopped on log("check4") without saying log("action") which kind of confused me cuz that shouldn't be possible?  Is there something I'm missing?

Also, is the random solver incorporated into onLoop, I can't seem to figure it out.

Look forward to working with you all, thanks for all the help so far  

 

import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.Interactable;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.Character;
import org.osbot.rs07.api.Bank;
import org.osbot.rs07.randoms.DismissRandom;

import java.awt.*;
import java.util.ArrayList;
 
@ScriptManifest(author = "Me", info = "My first script", name = "Maple cutter", version = 0, logo = "")
public class Main extends Script {
    
    int count=0;
    int bank_count=0;
    int super_antiban=random(0,50);
    int super_antiban2=random(0,5);
    int super_antiban3=random(0,5);
    int super_antiban4=random(0,5);
    int super_antiban5=random(0,100);
    Area pos1= new Area(2998,3376,3002,3369);
    Area pos2= new Area(2999,3360,3007,3366);
    Area pos3= new Area(3009,3357,3013,3361);
    int action=0;
        
    private enum State {
        CUT, BANK, WAIT
    };
    @Override
    public void onStart() {
        log("Hello world!");
        
    }
    private State getState() {
        Entity check = objects.closest("Maple Tree");
        if (inventory.isFull())
            return State.BANK;
        if (check != null)
            return State.CUT;
        return State.WAIT;
    }
 
    @Override
    public int onLoop() throws InterruptedException {
        log("Still looping");
        Interactable tree = null;
            tree=objects.closest("Maple tree");
        log("check3");
        boolean action=myPlayer().isAnimating();
        while(action==true)
            log("check4");
            log("check5");
            sleep(random(0,500));
            action=myPlayer().isAnimating();
            log("action");
//*        boolean rando = shouldActivate();
//        if(rando==true)
//            DismissRandom();
        switch (getState()) {
        case CUT:
            log("check1");
            tree=objects.closest("Maple tree");
            if(tree!=null)
                tree= objects.closest("Maple tree");
                tree.interact("Chop down");
            sleep(random(1000));
            log("check2");
            break;
        case BANK:
            bank_count=bank_count+1;
            if(bank_count==super_antiban2)
                tree= objects.closest("Maple tree");
                if(tree!=null)
                    tree.interact("Chop down");
                sleep(random(300));
            if(bank_count==super_antiban3)
                getWalking().walk(pos1);
                super_antiban3=super_antiban3+random(0,5);
            bank_count=bank_count+1;
            getWalking().walk(pos2);
            sleep(random(100));
            getWalking().walk(pos3);
            sleep(random(100));
            Entity bank = objects.closest("Bank booth");
            bank.interact("Bank");
            sleep(random(100));
            getBank().depositAll();
            
            getWalking().walk(pos3);
            if(bank_count==super_antiban4)
                getWalking().walk(pos2);
                super_antiban4=super_antiban4+random(0,5);
            break;
        case WAIT:
            sleep(random(3000, 7000));
            break;
        }
        count=count+1;
        if(count==super_antiban)
            sleep(random(10000,20000));
            super_antiban=super_antiban+random(50,100);
        return random(200, 300);
    }
 
    @Override
    public void onExit() {
        log("Goodbye world, you banked: "+bank_count+" inventories.");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
 
    }
 
}

Edited by jiggerjaw
Link to comment
Share on other sites

12 minutes ago, TheWind said:

You can't initialize this until the onStart() method.

so keep this:

Entity tree = null;

 

and put this in onStart() :

tree = objects.closest("Maple Tree");

You are correct sir, thank you.

 

Now the problem is "tree cannot be resolved" guessing it has something to do with it being a farming patch tree :s

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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