Jump to content

can i have some help, please


Recommended Posts

Posted (edited)

hello,

 

I'am currently trying to create a more enhanced cow killer,

I've divided the cow field into 3 different area's:

East,

South,

West

 

so say if im in "East", and there is no attackable cow the bot runs to "South" I've created this method:

	public void walkToArea(String area, Player p) throws InterruptedException {
		/* 2 other areas to EAST*/
		methods.safeWalkTo(PathSouthToEast);
		if(area == "East" && whatAreaPlayer(p) == "South") {
			methods.safeWalkTo(PathSouthToEast);
		}
		if(area == "East" && whatAreaPlayer(p) == "West") {
			methods.safeWalkTo(PathWestToEast);
		}
		/*end EAST*/
		
		/* 2 other areas to West*/
		if(area == "West" && whatAreaPlayer(p) == "South") {
			methods.safeWalkTo(PathSouthToWest);
		}
		if(area == "West" && whatAreaPlayer(p) == "East") {
			methods.safeWalkTo(PathEastToWest);
		}
		
		/* 2 other areas to West*/
		if(area == "South" && whatAreaPlayer(p) == "West") {
			methods.safeWalkTo(PathWestToSouth);
		}
		if(area == "South" && whatAreaPlayer(p) == "East") {
			methods.safeWalkTo(PathWestToSouth);
		}
	}

whatAreaPlayer:

	public String whatAreaPlayer(Player p) {
		if (cowFieldSouth.contains(p))
			return "South";
		if (cowFieldEast.contains(p))
			return "East";
		if (cowFieldWest.contains(p))
			return "West";
		return "cant find";
	}

safeWalkTo (thanks to Renegeade)

	public void safeWalkTo(Position[] p) throws InterruptedException {
		this.getLocalWalker().walkPath(p);
		Position lastPos = p[p.length - 1];
		while (true) {
			double lastDistance = distanceSquared(this.myPosition(), lastPos);
			if (lastDistance < 4.5d) {
				break;
			}
			Methods.sleep(3000);
			if (Math.abs(distanceSquared(this.myPosition(), lastPos)
					- lastDistance) < 1.1d) {
				ArrayList<Position> shortenedPath = new ArrayList<Position>();
				boolean startAdding = false;
				for (Position pos : p) {
					if (distanceSquared(this.myPosition(), pos) < 100d) {
						startAdding = true;
					}
					if (startAdding) {
						shortenedPath.add(pos);
					}
				}
				this.getLocalWalker().walkPath(shortenedPath);
			}
		}
	}

	private double distanceSquared(Position p1, Position p2) {
		return Math.pow(p1.getX() - p2.getX(), 2d)
				+ Math.pow(p1.getY() - p2.getY(), 2d);
	}

but now it just wont move...

 

thanks in advance,

Jelleplomp

Edited by jelleplomp
Posted (edited)

Or use localWalker.walk(area.getRandomPosition))? There's no sense in using paths for every scenario when you can have the walking event auto-generate one using DCPF. 

 

so your telling me i can use a method that generates a path to an area? XD

ffs lol thanks

 

what int do i need to use?

Edited by jelleplomp
Posted (edited)

so your telling me i can use a method that generates a path to an area? XD

ffs lol thanks

what int do i need to use?

localWalker.walk(MYAREA.getRandomPosition(0));

Is what I'd do.

Sometimes, if your character moves far enough away though, it won't walk back into the area.

There was also a line of code someone posted on here where they filtered out every cow they couldn't attack, then stored it into an array, then rolled a random number that was no greater than the arrays length to pick what cow to attack. On mobile, so I don't want to type it all out.

Edited by twin 763
Posted

getting this error =\

[ERROR][Bot #1][03/26 04:18:15 PM]: Error in script executor!
java.lang.NullPointerException
	at Searching.walkToArea(Methods.java:98)
	at JP_COW_KILLER.onLoop(JP_COW_KILLER.java:37)
	at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(vk:97)
	at java.lang.Thread.run(Unknown Source)

line : 

getLocalWalker().walk(cowFieldEast.getRandomPosition(0));
Posted

getting this error =\

[ERROR][Bot #1][03/26 04:18:15 PM]: Error in script executor!java.lang.NullPointerException	at Searching.walkToArea(Methods.java:98)	at JP_COW_KILLER.onLoop(JP_COW_KILLER.java:37)	at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(vk:97)	at java.lang.Thread.run(Unknown Source)
line :
getLocalWalker().walk(cowFieldEast.getRandomPosition(0));

When you're walking to an area or a path, it's localWalker.walk(). You don't need to do getLocalWalker unless you want it to walk to a specific point.

  • Like 1
Posted

Here is how I would go about doing this;

 

Entity Cow1 = getNPC.closest(COW_AREA1, "Cow")

Entity Cow2 = getNPC.closest(COW_AREA2, "Cow")

Entity Cow3 = getNPC.closest(COW_AREA3, "Cow")

 

 

if(COW_AREA1.contains(Cow1)) {

   cow1.interact("Attack");

} else if(COW_AREA2.contains(Cow2) && !COW_AREA1.contains(Cow1)) {

   cow2.interact("Attack");

} else if(COW_AREA3.contains(Cow3) && !COW_AREA1.contains(Cow1) && !COW_AREA2.contains(Cow2)){

   cow3.interact("Attack");

 

 

Made a script with similar concept, maybe you get some ideas?

Posted (edited)

Here is how I would go about doing this;

 

Entity Cow1 = getNPC.closest(COW_AREA1, "Cow")

Entity Cow2 = getNPC.closest(COW_AREA2, "Cow")

Entity Cow3 = getNPC.closest(COW_AREA3, "Cow")

 

 

if(COW_AREA1.contains(Cow1)) {

   cow1.interact("Attack");

} else if(COW_AREA2.contains(Cow2) && !COW_AREA1.contains(Cow1)) {

   cow2.interact("Attack");

} else if(COW_AREA3.contains(Cow3) && !COW_AREA1.contains(Cow1) && !COW_AREA2.contains(Cow2)){

   cow3.interact("Attack");

 

 

Made a script with similar concept, maybe you get some ideas?

 

All this seems really redundant, just get the closest cow and check if its either in the cow pen and under attack.

Area COWAREA = new Area(0,0,0,0)
NPC cow = npcs.closest("Cow");
if(cow!=null)
     if(COWAREA.contains(cow)&&!cow.isUnderAttack())
          cow.interact("Attack");

and if the cow is underattack just do

 

localWalker.walk(COWAREA.getRandomPosition(0)); and it will go to a new area and find new cows.

 

Or you can filter out every cow that is under attack, so the only cows it will think about targetting are ones that aren't under attack.

Edited by twin 763
Posted

All this seems really redundant, just get the closest cow and check if its either in the cow pen and under attack.

Area COWAREA = new Area(0,0,0,0)
NPC cow = npcs.closest("Cow");
if(cow!=null)
     if(COWAREA.contains(cow)&&!cow.isUnderAttack())
          cow.interact("Attack");

and if the cow is underattack just do

 

localWalker.walk(COWAREA.getRandomPosition(0)); and it will go to a new area and find new cows.

 

Or you can filter out every cow that is under attack, so the only cows it will think about targetting are ones that aren't under attack.

 

The simpler the less buggy too!

 

I would do same, but he wants a more complex script I guess laugh.png

 

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