jelleplomp Posted March 26, 2015 Share Posted March 26, 2015 (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 March 26, 2015 by jelleplomp Quote Link to comment Share on other sites More sharing options...
Alek Posted March 26, 2015 Share Posted March 26, 2015 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. 1 Quote Link to comment Share on other sites More sharing options...
jelleplomp Posted March 26, 2015 Author Share Posted March 26, 2015 (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 March 26, 2015 by jelleplomp Quote Link to comment Share on other sites More sharing options...
Twin Posted March 26, 2015 Share Posted March 26, 2015 (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 March 26, 2015 by twin 763 Quote Link to comment Share on other sites More sharing options...
Celeos Posted March 26, 2015 Share Posted March 26, 2015 What do you mean by east, west, and south? Is this all one cow field? Quote Link to comment Share on other sites More sharing options...
Twin Posted March 26, 2015 Share Posted March 26, 2015 What do you mean by east, west, and south? Is this all one cow field?Yeah it is. He broke it into 3 areas to have it run around if there are no attackable cows. Quote Link to comment Share on other sites More sharing options...
jelleplomp Posted March 26, 2015 Author Share Posted March 26, 2015 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)); Quote Link to comment Share on other sites More sharing options...
jelleplomp Posted March 27, 2015 Author Share Posted March 27, 2015 please some help Quote Link to comment Share on other sites More sharing options...
jelleplomp Posted March 29, 2015 Author Share Posted March 29, 2015 bump Quote Link to comment Share on other sites More sharing options...
Twin Posted March 29, 2015 Share Posted March 29, 2015 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. 1 Quote Link to comment Share on other sites More sharing options...
jelleplomp Posted March 30, 2015 Author Share Posted March 30, 2015 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. thanks man Quote Link to comment Share on other sites More sharing options...
Twin Posted March 30, 2015 Share Posted March 30, 2015 thanks man Actually to walk a path its localWalker.walkPath(), my bad for the misinformation Quote Link to comment Share on other sites More sharing options...
Acinate Posted March 31, 2015 Share Posted March 31, 2015 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? Quote Link to comment Share on other sites More sharing options...
Twin Posted March 31, 2015 Share Posted March 31, 2015 (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 March 31, 2015 by twin 763 Quote Link to comment Share on other sites More sharing options...
Acinate Posted March 31, 2015 Share Posted March 31, 2015 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 Quote Link to comment Share on other sites More sharing options...