Jump to content

can i have some help, please


jelleplomp

Recommended Posts

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

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

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

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

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

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?

Link to comment
Share on other sites

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

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

 

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