Jump to content

Multiple path walking


Recommended Posts

Posted (edited)

Hi guys, 

 

Can someone explain or show me how I can use a switch to walk random paths.

 

how can I add arrays to this.

public void Walkpath() throws InterruptedException {
		switch (random(1, 5)) {
		case 1:
                         //path1
			break;
		case 2:
                         //path2
			break;
		case 3:
                      
		break;
		}
		sleep(random(700, 1800));
	
	}
Edited by herojord
Posted

 

Hi guys, 

 

Can someone explain or show me how I can use a switch to walk random paths.

 

how can I add arrays to this.

public void Walkpath() throws InterruptedException {
		switch (random(1, 5)) {
		case 1:
                         //path1
			break;
		case 2:
                         //path2
			break;
		case 3:
                      
		break;
		}
		sleep(random(700, 1800));
	
	}
public void Walkpath() throws InterruptedException {
        switch (random(1, 5)) {
        case 1:
            getLocalWalker().walk(new Position(x, y, z));
            break;
        case 2:
            getLocalWalker().walk(new Position(x, y, z));
            break;
        case 3:

        break;
        }
        sleep(random(700, 1800));
    
    }

Not sure what else you mean, perhaps try to explain it a bit better?

  • Like 1
Posted (edited)

If you want to walk multiple paths, you could have a data structure like so:

public class Path {
    private List<Position> path;

    public Path(List<Position> ourPath) {
        path = ourPath;
    }

    public List<Position> getPath() {
        return path;
    }
}

And then you can have something like this:

List<Path> ourPaths = new ArrayList<Path>();
ourPaths.add(new Path(Arrays.asList(new Position[]{ new Position(x, y, z), new Position(x, y, z) }));

Then, you wouldn't even need a switch/case selection. You could just do:

getLocalWalker().walkPath(ourPaths.get(random(1, 5)).getPath());
Edited by Bobrocket
  • Like 3
Posted (edited)

 

If you want to walk multiple paths, you could have a data structure like so:

public class Path {
    private List<Position> path;

    public Path(List<Position> ourPath) {
        path = ourPath;
    }

    public List<Position> getPath() {
        return path;
    }
}

And then you can have something like this:

List<Path> ourPaths = new ArrayList<Path>();
ourPaths.add(new Path(Arrays.asList(new Position[]{ new Position(x, y, z), new Position(x, y, z) }));

Then, you wouldn't even need a switch/case selection. You could just do:

getLocalWalker().walkPath(ourPaths.get(random(1, 5)).getPath());

 

Thanks this is what I mean.

But I will get into this when I'm more experienced in Java. smile.png

 

 

Could also just use an array like this

 


 
Position[][] paths = new Position[][] {
            {
                    new Position(0,0,0), new Position(0,0,0) //path 0
            },

            {
                    new Position(0,0,0), new Position(0,0,0) //path 1
            }
    };
    
    Position[] myPath = paths[random(0, paths.length-1)];

 

This is more basic so I'll use this untill I'm able to optimize my code and make it more clever.

Thankyou.

Edited by herojord
Posted

 

Could also just use an array like this

 


 
Position[][] paths = new Position[][] {
            {
                    new Position(0,0,0), new Position(0,0,0) //path 0
            },

            {
                    new Position(0,0,0), new Position(0,0,0) //path 1
            }
    };
    
    Position[] myPath = paths[random(0, paths.length-1)];

 

 

I tried using this method, but since I'm working with cases it keeps looping so it never reaches the second value of the array.

because myPath gets a diff number everytime it enters the walking case.

 

How can I solve this issue?

Posted (edited)

I tried using this method, but since I'm working with cases it keeps looping so it never reaches the second value of the array.

because myPath gets a diff number everytime it enters the walking case.

 

How can I solve this issue?

I'm not sure what this issue is, and I'm also not sure what those cases would be since indexing an array means you don't have to use a switch anymore for this. Perhaps I can help if you show some of your code.

Edited by Flamezzz
Posted (edited)

I'm not sure what this issue is, and I'm also not sure what those cases would be since indexing an array means you don't have to use a switch anymore for this. Perhaps I can help if you show some of your code.

Im on my tablet but my script works like this

(!ores && not at bank)

Case: walking to bank

(ores && not at furnace)

Case : walking to furnace

(!ores && at bank)

Case : banking

(ores && at furnace)

Case : smelting

So the switch keeps calling the path arrays.

Edited by herojord
Posted


if (randomPath == 0)

{

log("random = 0");

randomPath = random(1,4);

}

if(randomPath == 1)

{

localWalker.walkPath(pathToHouseTwo);

sleep(100 + random (100, 200));

while(myPlayer().isMoving() || myPlayer().isAnimating())

{

sleep(400 + random (100, 200));

}

return 200 + gRandom(200, 400.0D);

}

else if (randomPath == 2)

{

localWalker.walkPath(pathToHouseTwo2);

sleep(100 + random (100, 200));

while(myPlayer().isMoving() || myPlayer().isAnimating())

{

sleep(400 + random (100, 200));

}

return 200 + gRandom(200, 400.0D);

}

else if (randomPath == 3)

{

localWalker.walkPath(pathToHouseTwo3);

sleep(100 + random (100, 200));

while(myPlayer().isMoving() || myPlayer().isAnimating())

{

sleep(400 + random (100, 200));

}

return 200 + gRandom(200, 400.0D);

}

else if (randomPath == 4)

{

localWalker.walkPath(pathToHouseTwo4);

sleep(100 + random (100, 200));

while(myPlayer().isMoving() || myPlayer().isAnimating())

{

sleep(400 + random (100, 200));

}

return 200 + gRandom(200, 400.0D);

}

Posted (edited)
if (randomPath == 0)
        {
            log("random = 0");
            randomPath = random(1,4);
        }
        if(randomPath == 1)
        {
            localWalker.walkPath(pathToHouseTwo);
            sleep(100 + random (100, 200));
            while(myPlayer().isMoving() || myPlayer().isAnimating())
            {
                sleep(400 + random (100, 200));
            }
            return 200 + gRandom(200, 400.0D);
        }
        else if (randomPath == 2)
        {
            localWalker.walkPath(pathToHouseTwo2);
            sleep(100 + random (100, 200));
            while(myPlayer().isMoving() || myPlayer().isAnimating())
            {
                sleep(400 + random (100, 200));
            }
            return 200 + gRandom(200, 400.0D);
        }
        else if (randomPath == 3)
        {
            localWalker.walkPath(pathToHouseTwo3);
            sleep(100 + random (100, 200));
            while(myPlayer().isMoving() || myPlayer().isAnimating())
            {
                sleep(400 + random (100, 200));
            }
            return 200 + gRandom(200, 400.0D);
        }
        else if (randomPath == 4)
        {
            localWalker.walkPath(pathToHouseTwo4);
            sleep(100 + random (100, 200));
            while(myPlayer().isMoving() || myPlayer().isAnimating())
            {
                sleep(400 + random (100, 200));
            }
            return 200 + gRandom(200, 400.0D);
        }

Didn't really read through the code, but I noticed you are not using a switch statememt. Why not?

Edited by fixthissite
Posted (edited)

+1 Flamezzz' solution. Simple and effective


I tried using this method, but since I'm working with cases it keeps looping so it never reaches the second value of the array.

because myPath gets a diff number everytime it enters the walking case.

 

How can I solve this issue?

 

You could probably make use of LocalWalker#walkPath instead; or maintain a global value to keep track of progress in your path walking. The first is probably the better way (tho I haven't actually tried it myself)

Edited by FrostBug
  • 1 year later...
Posted
On 9/19/2015 at 8:02 AM, Bobrocket said:

If you want to walk multiple paths, you could have a data structure like so:


public class Path {
    private List<Position> path;

    public Path(List<Position> ourPath) {
        path = ourPath;
    }

    public List<Position> getPath() {
        return path;
    }
}

And then you can have something like this:


List<Path> ourPaths = new ArrayList<Path>();
ourPaths.add(new Path(Arrays.asList(new Position[]{ new Position(x, y, z), new Position(x, y, z) }));

Then, you wouldn't even need a switch/case selection. You could just do:


getLocalWalker().walkPath(ourPaths.get(random(1, 5)).getPath());

I tried implementing this class and these methods but getLocalWalk() and walkPath are undefined for more, what do I need to import in order to fix that?

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