Jump to content

Where did I go wrong?


MySQLi

Recommended Posts

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);
		    }
		}

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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);
    }
}

Link to comment
Share on other sites

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