Jump to content

Where did I go wrong?


Recommended Posts

Posted

So... This script will work.. kind of. If I start at the yew tree in East Varrock, it'll cut the yew, but after the yew is cut down, it'll run to the next closest yew on the other side of the castle. If I start it anywhere other then that yew tree, it won't walk to it. Can anyone tell me what's wrong with this.. 

 

Spoiler

				
			import org.osbot.rs07.api.map.Area;
		import org.osbot.rs07.api.model.RS2Object;
		import org.osbot.rs07.script.Script;
		import org.osbot.rs07.script.ScriptManifest;				
			@ScriptManifest(name = "MyYewCutter", author = "MySQLi", version = 1.0, info = "Cuts yews in East Varrock", logo = "")				
			public class Main extends Script {				
		    private State state;
		    Area WC = new Area(3247,3472,0,0);
		    Area Bank = new Area(3253,3420,0,0);
		    
		    private enum State{
		        CUT, WALKTOBANK, BANK, WALKTOTREE
		    }
		    
		    private State getState(){
		        if(getInventory().isFull() && Bank.contains(myPlayer())){
		            return State.BANK;
		        }
		        if(getInventory().isFull() && !Bank.contains(myPlayer())){
		            return State.WALKTOBANK;
		        }
		        if(!getInventory().isFull() && WC.contains(myPlayer())){
		            return State.CUT;
		        }
		        if(!getInventory().isFull() && !WC.contains(myPlayer())){
		            return State.WALKTOTREE;
		        }
		        return State.BANK;
		    }
		    
		    public void onStart(){
		        
		    }
		    
		    public int onLoop() throws InterruptedException{
		        state = getState();
		        switch (state){
		        
		        case BANK:
		            if(!getBank().isOpen()){
		                getBank().open();
		            }else{
		                getBank().depositAll();
		            }
		        case WALKTOBANK:
		            getWalking().webWalk(Bank);
		            break;
		            
		        case CUT:
		            if (myPlayer().isAnimating()){
		            }else{
		                if(!myPlayer().isAnimating()){
		                }
		                RS2Object yew = getObjects().closest("Yew");
		                if (yew != null){
		                    yew.interact("Chop down");
		                }
		            }
		            break;
		            
		        case WALKTOTREE:
		            getWalking().webWalk(WC);
		            
		            break;
		            
		        }
		        return random(150,175);
		    }
		}

 

Posted (edited)
33 minutes ago, MySQLi said:

I do not, it's equipped on my character. 

You are just calling myPlayer.

I think you need to do myPlayer.getPosition()

Like this v

if(!getInventory().isFull() && WC.contains(myPlayer.getPosition())){
	return State.CUT;
}

Reason is, you want to check the yew area against your players current position.

Edited by Visty
Posted
2 minutes ago, Visty said:

You are just calling myPlayer.

I think you need to do myPlayer.getPosition()


if(!getInventory().isFull() && WC.contains(myPlayer.getPosition())){
		            return State.CUT;
		        }

But WC has a stored x,y position, so wouldn't the client realize my current x,y and the x,y it should be at and move it there?

 

Posted (edited)

Also, to make your player only cut the yew trees within the area you have selected, you have to do this v

RS2Object yew = getObjects().closest(WC, "Yew");

As you can see, you are telling the bot to check the closest tree in the WC area, against the tree "Yew"

Edited by Visty
Posted
2 minutes ago, Visty said:

Also, to make your player only cut the yew trees within the area you have selected, you have to do this v


RS2Object yew = getObjects().closest(WC, "Yew");

As you can see, you are telling the bot to check the closest tree in the WC area, against the tree "Yew"

Thank you, that fixes that, but with your other suggestion, it still won't walk to the Woodcutting location... I don't understand why it's not working. 

Posted
2 minutes ago, MySQLi said:

But WC has a stored x,y position, so wouldn't the client realize my current x,y and the x,y it should be at and move it there?

Yes, in your WalkToTree method, say something like v

if (!WC.contains(myPlayer.getPosition()) {
  getWalking.walk(yew);
}

In this, you are saying if the player isn't in the WC area, let's walk to it.

Posted
3 minutes ago, Visty said:

Yes, in your WalkToTree method, say something like v


if (!WC.contains(myPlayer.getPosition()) {
  getWalking.walk(yew);
}

In this, you are saying if the player isn't in the WC area, let's walk to it.

 

3 minutes ago, Visty said:

Yes, in your WalkToTree method, say something like v


if (!WC.contains(myPlayer.getPosition()) {
  getWalking.walk(yew);
}

In this, you are saying if the player isn't in the WC area, let's walk to it.

I tried this, it still won't walk to the yew tree. I don't understand why. 

Posted
4 minutes ago, Visty said:

Show me the code you have written

 

	import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
	@ScriptManifest(name = "MyYewCutter", author = "MySQLi", version = 1.0, info = "Cuts yews in East Varrock", logo = "")
	public class Main extends Script {
    private State state;
    Area WC = new Area(3247,3472,0,0);
    Area Bank = new Area(3253,3420,0,0);
    
    private enum State{
        CUT, WALKTOBANK, BANK, WALKTOTREE
    }
    
    private State getState(){
        if(getInventory().isFull() && Bank.contains(myPlayer())){
            return State.BANK;
        }
        if(getInventory().isFull() && !Bank.contains(myPlayer())){
            return State.WALKTOBANK;
        }
        if(!getInventory().isFull() && WC.contains(myPlayer().getPosition())){
            return State.CUT;
        }
        if(!getInventory().isFull() && !WC.contains(myPlayer().getPosition())){
            return State.WALKTOTREE;
        }
        return State.BANK;
    }
    
    public void onStart(){
        
    }
    
    public int onLoop() throws InterruptedException{
        state = getState();
        switch (state){
        
        case BANK:
            if(!getBank().isOpen()){
                getBank().open();
            }else{
                getBank().depositAll();
            }
        case WALKTOBANK:
            getWalking().webWalk(Bank);
            break;
            
        case CUT:
            if (myPlayer().isAnimating()){
            }else{
                if(!myPlayer().isAnimating()){
                }
                RS2Object yew = getObjects().closest(WC, "Yew");
                if (yew != null){
                    yew.interact("Chop down");
                }
            }
            break;
            
        case WALKTOTREE:
            getWalking().webWalk(WC);
            
            break;
            
        }
        return random(150,175);
    }
}

Posted (edited)
10 minutes ago, MySQLi said:

Yes, inventory is empty, and I checked the coordinates too. 

I'm thinking it's because of your states. They all have the same if statements. I can't really identify the problem without logging each statement, and see where the issue is. If you want, I can help you via teamviewer.

Edited by Visty

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...