Jump to content

Pathing issue with my bot


iamgreatbill

Recommended Posts

I'm new and need some help. I'm writing a script and need my bot to be able to walk from the Lumbridge sheep farm to the bank and then back. from everything I've read my code seems sound but for some reason about 50% the time my bot passes through the gate of Lumbridge castle(going in either direction) it randomly turns around and bolts toward the swamp for no apparent reason. I pretty sure the problem lies somewhere in path or path 4. As path2 and path 3 take place upstairs in the castle and haven't exhibited any problems.

 

I'm stumped as to what might be causing this. All my code related to walking the path follows. Any insight as to the possible root of my problem would be greatly appreciated. As would any advice on how to possibly do this better.

private Position[] path = {
            new Position(3217,3258, 0), new Position(3219,3245, 0), new Position(3229,3233, 0),
            new Position(3235,3219, 0), new Position(3218,3219, 0), new Position(3214,3219, 0),
            new Position(3215,3224, 0), new Position(3213,3228, 0), new Position(3207,3228, 0),
            new Position(3207,3228, 0)};
    private Position[] path2 = {
    	    new Position(3206,3225, 2), new Position(3206,3221, 2), new Position(3214,3219, 2),
            new Position(3208,3220, 2)};
    private Position[] path3 = {
            new Position(3214,3219, 2), new Position(3206,3221, 2), new Position(3206,3225, 2)};
    private Position[] path4 = {
    	    new Position(3207,3228, 0), new Position(3213,3228, 0), new Position(3215,3224, 0), 
            new Position(3214,3219, 0), new Position(3218,3219, 0), new Position(3235,3219, 0),
            new Position(3229,3233, 0), new Position(3219,3245, 0), new Position(3217,3258, 0)};
    
    @Override
    public int onLoop() throws InterruptedException {
    	localWalker.walk(3212,3262);
    	while(myPlayer().isMoving())
    		sleep(random(300,500));
    	sleep(random(2000,4000));
    	if(objects.closest("Gate").hasAction("Open"))
    	{
    		while (objects.closest("Gate").hasAction("Open")){
    		objects.closest("Gate").interact("Open");
    		sleep(random(500,1000));}
    	}	
    	localWalker.walkPath(path);
    	while(myPlayer().isMoving())
    		sleep(random(300,500));
    	sleep(random(1000,2000));
    	if(objects.closest("Staircase").hasAction("Climb-up"))
    	{
    		while (objects.closest("Staircase").hasAction("Climb-up")){
    			objects.closest("Staircase").interact("Climb-up");
    			sleep(random(500,1000));}
    	}
		localWalker.walkPath(path2);
    	while(myPlayer().isMoving())
    		sleep(random(300,500));
		RS2Object bankBooth = objects.closest("Bank booth");
        if (bankBooth != null) {
            if (bankBooth.interact("Bank")) {
                while (!bank.isOpen())
                    sleep(250);
                bank.depositAllExcept("Shears");
            }
        }
        sleep(random(2000,4000));
        localWalker.walkPath(path3);
    	while(myPlayer().isMoving())
    		sleep(random(300,500));
    	sleep(random(2000,4000));
    	if(objects.closest("Staircase").hasAction("Climb-down"))
    	{
    		while (objects.closest("Staircase").hasAction("Climb-down")){
    			objects.closest("Staircase").interact("Climb-down");
    			sleep(random(500,1000));}
    	}
		localWalker.walkPath(path4);
    	while(myPlayer().isMoving())
    		sleep(random(300,500));
    	sleep(random(2000,4000));
    	if(objects.closest("Gate").hasAction("Open"))
    	{
    		while (objects.closest("Gate").hasAction("Open")){
    		objects.closest("Gate").interact("Open");
    		sleep(random(500,1000));}
    	}
    	while(myPlayer().isAnimating())
    		sleep(random(300,500));
    	Area sheepFarm = new Area (3195,3273,3210,3259);
    	localWalker.walk(sheepFarm.getRandomPosition(0));
    	while(myPlayer().isMoving())
    		sleep(random(300,500));
Link to comment
Share on other sites

:o

 

the problemo is most likely with the style of code, where it fails to do one step and the rest of it is redundant.

 

Try using a statemachine system which allows you to work on 1 step at a time and if it fails it allows you to retry. This may well fix your problem.

More details on the state based system can be found here: http://osbot.org/forum/topic/58775-a-beginners-guide-to-writing-osbot-scripts-where-to-get-started-by-apaec/

 

PS Don't use while loops without a timeout (if at all!) these can cause it to get stuck.

 

Apaec

Link to comment
Share on other sites

Its good to see new scripters, but there a few points that have to be worked on :)

 

Stop using so much while loops xD

I suggest you to get rid of them or atleast add a break timer so it can't get stuck.

 

Walking to the swamp could also be in the localwalker,

since it has been walking to several wrong positions for me too lately... not sure what the issue is :s

 

Try to have a better code style,

More checks where your player is located and what to do next.

Don't just put everything back to back.

Like APA said: Use states or use some way the logic of the script improves smile.png

 

This will also give NPE's:

if(objects.closest("Staircase").hasAction("Climb-down"))
objects.closest("Staircase").interact("Climb-down");
if(objects.closest("Gate").hasAction("Open"))

You should get the Object first, then Null check it before you do anything with it.

 

Khaleesi

Edited by Khaleesi
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...