Jump to content

Multiple path walking


herojord

Recommended Posts

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

 

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

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

 

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

 

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?

Link to comment
Share on other sites

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

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


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

}

Link to comment
Share on other sites

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

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

  • 1 year later...
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?

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