LifezHatred Posted September 22, 2013 Share Posted September 22, 2013 (edited) (Apparently this forums do not like to keep my tabbed code) This code will walk a random path every time to a coordinate, use waypoints to move around buildings/fences will return true once it is within 5 spaces of the end point. (WILL WALK ANY DISTANCE) tabbed version- http://pastebin.com/djSDJb2p place this in your script public long lastRun = 0; public Position lastClick = null; public int randomDistance = 0; public boolean walkToLocation(Position p) throws InterruptedException { int maxY; int maxX; boolean revY = false; boolean revX = false; Position playerPosition = myPlayer().getPosition(); if(playerPosition.getX() < p.getX()) { revX = true; int distance = p.getX()-playerPosition.getX(); if(distance > 17) { maxX = 17; } else { maxX = distance; } } else { int distance = playerPosition.getX()-p.getX(); if(distance > 17) { maxX = 17; } else { maxX = distance; } } if(playerPosition.getY() < p.getY()) { revY = true; int distance = p.getY()-playerPosition.getY(); if(distance > 17) { maxY = 17; } else { maxY = distance; } } else { int distance = playerPosition.getY()-p.getY(); if(distance > 17) { maxY = 17; } else { maxY = distance; } } int addX = (int) (10+(Math.random()*(maxX-10))); int addY = (int) (10+(Math.random()*(maxY-10))); if(maxX < 10) { addX = maxX; } if(maxY < 10) { addY = maxY; } if(!revX) { addX = addX*-1; } if(!revY) { addY = addY*-1; } if(lastClick == null) { if(walk(new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()))) { lastClick = new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()); randomDistance = (int) (3+(Math.random() * 3)); } } else { if(lastClick.distance(myPlayer().getPosition()) < randomDistance) { if(walk(new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()))) { lastClick = new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()); randomDistance = (int) (3+(Math.random() * 3)); } } } if(lastClick.distance(p) < 5) { lastClick = null; return true; } return false; } Use (in the onLoop() Method) if(walkToLocation(new Position(x,y,z))) { //what happens once it reaches end } Will release a detailed guide soon to determine waypoints Guide: And Edited September 24, 2013 by LifezHatred Link to comment Share on other sites More sharing options...
Unbound Posted September 23, 2013 Share Posted September 23, 2013 Looks nice! Is there a possibility to make a script purely for walking? The otherone thats currently online doesn't work. I'm sure this one will work Link to comment Share on other sites More sharing options...
LifezHatred Posted September 23, 2013 Author Share Posted September 23, 2013 (edited) Looks nice! Is there a possibility to make a script purely for walking? The otherone thats currently online doesn't work. I'm sure this one will work i guess i could add a few more methods to it, n put it in a class the only thing it would need now is add a a method that executes waypoints which would be something like public Position[] waypoints = {...}; public int offset = 0; public boolean executeWaypoints(Position[] p) { if(walkToLocation(p[offset])) { offset++; if(offset == p.length) { offset = 0; return true; } } return false; } which returns true once it reaches the end Edited September 23, 2013 by LifezHatred Link to comment Share on other sites More sharing options...
Swizzbeat Posted September 23, 2013 Share Posted September 23, 2013 Never realized how much I love the tab key until I saw this But anyway it looks nice, I'll work this into one of my scripts somewhere! Link to comment Share on other sites More sharing options...
LifezHatred Posted September 24, 2013 Author Share Posted September 24, 2013 (edited) Never realized how much I love the tab key until I saw this But anyway it looks nice, I'll work this into one of my scripts somewhere! yeah apparently no matter how many times i re pasted it the tabs would not show up =[ tabbed version - http://pastebin.com/djSDJb2p Edited September 24, 2013 by LifezHatred Link to comment Share on other sites More sharing options...
TheAnswer Posted September 24, 2013 Share Posted September 24, 2013 (edited) Never realized how much I love the tab key until I saw this But anyway it looks nice, I'll work this into one of my scripts somewhere! yeah apparently no matter how many times i re pasted it the tabs would not show up =[ tabbed version - http://pastebin.com/djSDJb2p You have to use spaces instead of tabs. Also the word wrapping can mess things up so, start any new line on a new line to prevent weird word wrapping. Hope you don't mind here is the code formatted below public long lastRun = 0; public Position lastClick = null; public int randomDistance = 0; public boolean walkToLocation(Position p) throws InterruptedException { int maxY; int maxX; boolean revY = false; boolean revX = false; Position playerPosition = myPlayer().getPosition(); if(playerPosition.getX() < p.getX()) { revX = true; int distance = p.getX()-playerPosition.getX(); if(distance > 17) { maxX = 17; } else { maxX = distance; } } else { int distance = playerPosition.getX()-p.getX(); if(distance > 17) { maxX = 17; } else { maxX = distance; } } if(playerPosition.getY() < p.getY()) { revY = true; int distance = p.getY()-playerPosition.getY(); if(distance > 17) { maxY = 17; } else { maxY = distance; } } else { int distance = playerPosition.getY()-p.getY(); if(distance > 17) { maxY = 17; } else { maxY = distance; } } int addX = (int) (10+(Math.random()*(maxX-10))); int addY = (int) (10+(Math.random()*(maxY-10))); if(maxX < 10) { addX = maxX; } if(maxY < 10) { addY = maxY; } if(!revX) { addX = addX*-1; } if(!revY) { addY = addY*-1; } if(lastClick == null) { if(walk(new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()))) { lastClick = new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()); randomDistance = (int) (3+(Math.random() * 3)); } } else { if(lastClick.distance(myPlayer().getPosition()) < randomDistance) { if(walk(new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()))) { lastClick = new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()); randomDistance = (int) (3+(Math.random() * 3)); } } } if(lastClick.distance(p) < 5) { lastClick = null; return true; } return false; } Edited September 24, 2013 by TheAnswer Link to comment Share on other sites More sharing options...
LifezHatred Posted September 25, 2013 Author Share Posted September 25, 2013 (edited) Never realized how much I love the tab key until I saw this But anyway it looks nice, I'll work this into one of my scripts somewhere! yeah apparently no matter how many times i re pasted it the tabs would not show up =[ tabbed version - http://pastebin.com/djSDJb2p You have to use spaces instead of tabs. Also the word wrapping can mess things up so, start any new line on a new line to prevent weird word wrapping. Hope you don't mind here is the code formatted below public long lastRun = 0; public Position lastClick = null; public int randomDistance = 0; public boolean walkToLocation(Position p) throws InterruptedException { int maxY; int maxX; boolean revY = false; boolean revX = false; Position playerPosition = myPlayer().getPosition(); if(playerPosition.getX() < p.getX()) { revX = true; int distance = p.getX()-playerPosition.getX(); if(distance > 17) { maxX = 17; } else { maxX = distance; } } else { int distance = playerPosition.getX()-p.getX(); if(distance > 17) { maxX = 17; } else { maxX = distance; } } if(playerPosition.getY() < p.getY()) { revY = true; int distance = p.getY()-playerPosition.getY(); if(distance > 17) { maxY = 17; } else { maxY = distance; } } else { int distance = playerPosition.getY()-p.getY(); if(distance > 17) { maxY = 17; } else { maxY = distance; } } int addX = (int) (10+(Math.random()*(maxX-10))); int addY = (int) (10+(Math.random()*(maxY-10))); if(maxX < 10) { addX = maxX; } if(maxY < 10) { addY = maxY; } if(!revX) { addX = addX*-1; } if(!revY) { addY = addY*-1; } if(lastClick == null) { if(walk(new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()))) { lastClick = new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()); randomDistance = (int) (3+(Math.random() * 3)); } } else { if(lastClick.distance(myPlayer().getPosition()) < randomDistance) { if(walk(new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()))) { lastClick = new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()); randomDistance = (int) (3+(Math.random() * 3)); } } } if(lastClick.distance(p) < 5) { lastClick = null; return true; } return false; } i like my conventions better, yours is more of a C++ convention plus if people want a tabbed version i did provide a link Edited September 25, 2013 by LifezHatred Link to comment Share on other sites More sharing options...
5uck Posted September 27, 2013 Share Posted September 27, 2013 Thank you for this. Been working on a project that doesnt cope well with the usual walking methods and this saved me alot of head ache. Thanks Link to comment Share on other sites More sharing options...
LifezHatred Posted September 29, 2013 Author Share Posted September 29, 2013 (edited) Thank you for this. Been working on a project that doesnt cope well with the usual walking methods and this saved me alot of head ache. Thanks Np man, its less detectable because it uses a different path to that location every time (in my yew cutter i released it never runs the same path) Edited September 29, 2013 by LifezHatred Link to comment Share on other sites More sharing options...
Dualshotty Posted October 1, 2013 Share Posted October 1, 2013 This looks awesome. I'll wait for the more detailed guide, thanks for sharing! Link to comment Share on other sites More sharing options...
liverare Posted October 1, 2013 Share Posted October 1, 2013 (edited) Perhaps you should simplify your code to something like: public static Position getNextPosition(Script script, Position end) { Position cur = script.myPosition(); int disX = end.getX() - cur.getX(), disY = end.getY() - cur.getY(); boolean revX = disX < 0, revY = disY < 0; disX = Math.abs(disX); disY = Math.abs(disY); if (disX >= 17) disX = 10 + MethodProvider.random(5); if (disY >= 17) disY = 10 + MethodProvider.random(5); return new Position(cur.getX() + (revX ? ~disX : disX), cur.getY() + (revY ? ~disY : disY), cur.getZ()); } I made my method a 'getter' to allow users to provide users with the ability to handle the actual walking themselves. Edited December 29, 2013 by liverare Link to comment Share on other sites More sharing options...
LifezHatred Posted October 1, 2013 Author Share Posted October 1, 2013 Perhaps you should simplify your code to something like: public static Position getNextPosition(Script script, Position end) { Position cur = script.myPosition(); int disX = end.getX() - cur.getX(), disY = end.getY() - cur.getY(); boolean revX = disX < 0, revY = disY < 0; disX = Math.abs(disX); disY = Math.abs(disY); if (disX >= 17) disX = 10 + MethodProvider.random(5); if (disY >= 17) disY = 10 + MethodProvider.random(5); return new Position(cur.getX() + (revX ? ~disX : disX), cur.getY() + (revY ? ~disY : disY), cur.getZ()); } I made it a getter method because I assume people will want to provide better structured handling for walking--instead of trusting this method will get them from A to B. Ehh i guess, but i'd rather keep mine the way it is Link to comment Share on other sites More sharing options...
liverare Posted October 6, 2013 Share Posted October 6, 2013 (edited) . . . Ehh i guess, but i'd rather keep mine the way it is Why? Your code is 74 lines long (2.34 KB) whereas mine is only 11 lines long (522 bytes). They both draw pretty much the same conclusion aside from mine lacking the walking handler. Program however you want, but condensing code whilst maintaining its overarching functionality and purpose is good practice. It helps remove redundant lines which help improve readability. [EDIT] I should also note that Pork has produced a much better method than both of ours because his uses some nice mathematics. Edited December 29, 2013 by liverare 1 Link to comment Share on other sites More sharing options...
LifezHatred Posted October 6, 2013 Author Share Posted October 6, 2013 . . . Ehh i guess, but i'd rather keep mine the way it is Why? Your code is 74 lines long (2.34 KB) -- most of which is redundant. Mine is 11 (522 bytes) and it draws pretty much the same conclusion (without walking handler). I'm not going to tell you how to program, but at least have consideration for possible improvements. because idc bout all that stuff? don't post on my thread anymore if all ur going to do is complain about what i do Link to comment Share on other sites More sharing options...
Yugod Posted October 10, 2013 Share Posted October 10, 2013 Thanks for the snippet. Also liverare was trying to improve ya code no need to go angry on the guy :p Link to comment Share on other sites More sharing options...