Jump to content

Brainfree

Members
  • Posts

    135
  • Joined

  • Last visited

  • Days Won

    1
  • Feedback

    0%

Everything posted by Brainfree

  1. If you would like to add pouches (any type) into your script, and want to know what type of rune, and how much is in that pouch, this snippet is for you. Pouch import org.osbot.script.rs2.Client; import org.osbot.script.rs2.skill.Skill; public enum Pouch { SMALL(5509, -1, 1, 3, 3), MEDIUM(5510, 5511, 50, 6, 3), LARGE(5512, 5513, 50, 9, 7), GIANT(5514, 5515, 75, 12, 9); public final int normalID; public final int degradedID; public final int requiredLevel; public final int normalHold; public final int degradedHold; private Pouch(int AssignedNormalID, int AssignedDegradedID, int AssignedRequiredLevel, int AssignedNormalHold, int AssignedDegradedHold ) { this.normalID = AssignedNormalID; this.degradedID = AssignedDegradedID; this.requiredLevel = AssignedRequiredLevel; this.normalHold = AssignedNormalHold; this.degradedHold = AssignedDegradedHold; } public static EssenceType getPouchEssenceType(Client client, Pouch p) { int setting = client.getConfig(720); switch (p) { case SMALL: return setting >= 128 ? EssenceType.PURE : (setting >= 0x40) && (setting < 0x80) ? EssenceType.NORMAL : null; case MEDIUM: if (setting >= 64) setting %= 64; return setting >= 32 ? EssenceType.PURE : (setting >= 0x10) && (setting < 0x20) ? EssenceType.NORMAL : null; case LARGE: if (setting >= 64) setting %= 64; if (setting >= 16) setting %= 16; return setting >= 9 ? EssenceType.PURE : (setting >= 0x4) && (setting < 0x9) ? EssenceType.NORMAL : null; case GIANT: if (setting >= 64) setting %= 64; if (setting >= 16) setting %= 16; if (setting >= 4) if (setting < 0x9) setting %= 0x4; else setting %= 0x9; return setting == 0x2 ? EssenceType.PURE : setting == 0x1 ? EssenceType.NORMAL : null; } return null; } public static int getEssenceCount(Client client, Pouch p) { int setting = client.getConfig(486) - 0x40000000; switch (p) { case GIANT: return setting / 0x40000; case LARGE: setting %= 262144; return setting / 0x200; case MEDIUM: setting %= 262144; setting %= 512; return setting / 8; case SMALL: setting %= 262144; setting %= 512; return setting % 8; } return -1; } public int getNormalID() { return normalID; } public int getDegradedID() { return degradedID; } public int getNormalHold() { return normalHold; } public int getDegradedHold() { return degradedHold; } public int getRequiredLevel() { return requiredLevel; } public EssenceType getEssencesType(Client client) { return getPouchEssenceType(client, this); } public int getEssencesAmount(Client client) { return getEssenceCount(client, this); } } And for wrapping the rune types: public enum EssenceType { PURE(7936), NORMAL(1436); final int ID; private EssenceType(int ID) { this.ID = ID; } public int getID() { return this.ID; } } Example: import org.osbot.script.Script; import org.osbot.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "Brainfree", info = "Pouch display", version = 1.0, name = "Pouch viewer") public class Example extends Script { public int onLoop() { return 35; } public void onPaint(Graphics g) { int x = 10; int y = 15; EssenceType type; for (Pouch pouch : Pouch.values()) { type = pouch.getEssencesType(client); g.drawString(pouch.name() + ":[Type: " + (type == null ? "None" : type.name()) + ",Quantity: " + pouch.getEssencesAmount(client) + "]", x, y); y += 15; } } } Hope you enjoy.
  2. One of the coolest algorithms ever made.
  3. Good job man, keep up the good work; And don't worry about the ban!
  4. Because spam is always productive.
  5. Rsbots webwalker, and splinewalk was a snippit. My real walker is soon to come.
  6. Hello, Seemingly people have been requesting me for my mythology for walking threw regions, without having the clients pathfinder break. The reason why it breaks it because your destination, is as close to your current region as you can get (Collision dependent) , and most likely you're right next to it, so you've reached the maximum 'farthest' position that your current region can support path finding to. So you're suck, because you must be right before the area were runescape will load your next region (bad luck), and thus restricts the client from being able to find a path for the next position (Which would be within a neighboring region). How my method works is by combing the reliability of a pre-build path, with the optimization and randomcy of a regional flood agent (Pathfinder). It'll use the pre-build tile path (I call it a spline), when path finding is impossible, or you're within the 'zone' of were runescape is about to load the next region, this is to avoid you're player from pausing, or breaking when runescape loads you're new region (more human). It uses the spline, as way points and hints to were it should work to get to next. It also allow you to break the walking, conditionally based (like while this is true, keep working, else stop.) Example of it in work: http://youtu.be/tvNGQB3m_UE What I use for my flood agent, is a shortest distance tree, which is optimized for speed, and does not require a heuristics function, unlike A*, you can use something different, it does not matter really. The drawback of this method is the spline must be FULLY WALKABLE from A to B, and to get from B to A you must reverse the spline. I clone and reverse the elements, since i'm lazy . Most preferably I use a map utility called OMU (Overload Map Utility), made for p****bot, under some dude, what it does it'll make a tile path from A to B, as compact as you want (1) (The less space within the 'spline' from neighbor to neighbor, the better; ex: Tile(1,1,0), Tile(1, 2, 0), Tile(1,3,0)). Example of a spline (note: not checked to ensure every position is walkable): Download link to jar (google if you don't true me): https://dl.dropboxusercontent.com/u/58848692/OMU.jar What must be going through you're head is, 'I have to check every dam tile to be walkable...?'. But I have to say, have not fear, path finding is hear. Pathfinding is cool, because it if it can't find a path, then it's just not walkable (let's hope). So you can for loop it, like this: public boolean isRegional(Position position) { int baseX = position.getX() - client.getMapBaseX(); int baseY = position.getY() - client.getMapBaseY(); return baseX >= 16 && baseX <= 88 && baseY >= 16 && baseY <= 88; //I think runescape loads @ 16 and nulls collisions at the borders? } public void whatIsNotWalkableWithinMyRegion(Position[] mySpline) { for(Position node : mySpline) { if(!isRegional(node)) continue; //Can't truly verify if it's walkable, since we don't have the collision data for it. //So we would need make that position regional to correctly verify. if (pathfinder.findPath(myPosition(), node, false).length == 0) { System.out.println("Oww darn, this regional position is not walkable, plz fix: " + node); } } } Cool beans? Now for the googies? Please keep in mind this entire method was made to just work, and I'm sure there is methods to improve it's performances and structure, but the bellow code is all the methods I used in the above video. Take note of the TODO's for you'll have to do some housekeeping adjustments, mainly for randomcy. Also, I would split the sub classes for obvious reasons, I just did this so I don't have to post all 4 classes (so lazy right now ). Keep tuned for an exact replica of the videos use of this method. import org.osbot.script.mouse.MinimapTileDestination; import org.osbot.script.rs2.Client; import org.osbot.script.rs2.map.Position; import java.util.*; /** * @author Brainfree * It'll get the job done. */ public class PackedSplineWalk { public static final int BASE_LENGTH = 104; public static final int BASE_BOUNDARY = BASE_LENGTH - 1; public static final int WALL_NORTH_WEST = 0x1; public static final int WALL_NORTH = 0x2; public static final int WALL_NORTH_EAST = 0x4; public static final int WALL_EAST = 0x8; public static final int WALL_SOUTH_EAST = 0x10; public static final int WALL_SOUTH = 0x20; public static final int WALL_SOUTH_WEST = 0x40; public static final int WALL_WEST = 0x80; public static final int BLOCKED = 0x100; public interface Conditional { //All hail public boolean isActive(); } public abstract class FloodAgent { public int[][] flags; public int base_x, base_maxX, base_y, base_maxY, curr_plane; public final Client bot; public FloodAgent(Client bot) { this.bot = bot; } public void updateBase() { if (base_x != bot.getMapBaseX() || base_y != bot.getClient().getMapBaseY() || curr_plane != bot.getClient().getPlane()) { base_x = bot.getClient().getMapBaseX(); base_maxX = base_x + 104; base_y = bot.getClient().getMapBaseY(); base_maxY = base_y + 104; curr_plane = bot.getClient().getPlane(); flags = adjustCollisionFlags(bot.getClient().getClippingPlanes() [bot.getClient().getPlane()].getTileFlags()); } } private int[][] adjustCollisionFlags(final int[][] flags) { final int lx = flags.length - 1; final int lx_m = lx - 5; for (int x = 0; x <= lx; x++) { final int ly = flags[x].length - 1; final int ly_m = ly - 5; for (int y = 0; y <= ly; y++) { if (x <= 5 || y <= 5 || x >= lx_m || y >= ly_m) { flags[x][y] = -1; } } } return flags; } public abstract Position[] findPath(Position from, Position to, boolean fullFlood); } public enum DirectionalOrientation { NORTH_WEST(-1, 1, 135) { @Override public boolean walkable(int[][] flags, int f_x, int f_y, int here) { return (f_x > 0 && f_y < BASE_BOUNDARY && (here & (WALL_NORTH_WEST | WALL_NORTH | WALL_WEST)) == 0 && (flags[f_x - 1][f_y + 1] & BLOCKED) == 0 && (flags[f_x][f_y + 1] & (BLOCKED | WALL_WEST)) == 0 && (flags[f_x - 1][f_y] & (BLOCKED | WALL_NORTH)) == 0); } }, NORTH(0, 1, 90) { @Override public boolean walkable(int[][] flags, int f_x, int f_y, int here) { return (f_y < BASE_BOUNDARY && (here & WALL_NORTH) == 0 && (flags[f_x][f_y + 1] & BLOCKED) == 0); } }, NORTH_EAST(1, 1, 45) { @Override public boolean walkable(int[][] flags, int f_x, int f_y, int here) { return (f_x > 0 && f_y < BASE_BOUNDARY && (here & (WALL_NORTH_EAST | WALL_NORTH | WALL_EAST)) == 0 && (flags[f_x + 1][f_y + 1] & BLOCKED) == 0 && (flags[f_x][f_y + 1] & (BLOCKED | WALL_EAST)) == 0 && (flags[f_x + 1][f_y] & (BLOCKED | WALL_NORTH)) == 0); } ; }, EAST(1, 0, 0) { @Override public boolean walkable(int[][] flags, int f_x, int f_y, int here) { return (f_x < BASE_BOUNDARY && (here & WALL_EAST) == 0 && (flags[f_x + 1][f_y] & BLOCKED) == 0); } }, SOUTH_EAST(1, -1, 315) { @Override public boolean walkable(int[][] flags, int f_x, int f_y, int here) { return (f_x < BASE_BOUNDARY && f_y > 0 && (here & (WALL_SOUTH_EAST | WALL_SOUTH | WALL_EAST)) == 0 && (flags[f_x + 1][f_y - 1] & BLOCKED) == 0 && (flags[f_x][f_y - 1] & (BLOCKED | WALL_EAST)) == 0 && (flags[f_x + 1][f_y] & (BLOCKED | WALL_SOUTH)) == 0); } }, SOUTH(0, -1, 270) { @Override public boolean walkable(int[][] flags, int f_x, int f_y, int here) { return (f_y > 0 && (here & WALL_SOUTH) == 0 && (flags[f_x][f_y - 1] & BLOCKED) == 0); } }, SOUTH_WEST(-1, -1, 225) { @Override public boolean walkable(int[][] flags, int f_x, int f_y, int here) { return (f_x > 0 && f_y > 0 && (here & (WALL_SOUTH_WEST | WALL_SOUTH | WALL_WEST)) == 0 && (flags[f_x - 1][f_y - 1] & BLOCKED) == 0 && (flags[f_x][f_y - 1] & (BLOCKED | WALL_WEST)) == 0 && (flags[f_x - 1][f_y] & (BLOCKED | WALL_SOUTH)) == 0); } }, WEST(-1, 0, 180) { @Override public boolean walkable(int[][] flags, int f_x, int f_y, int here) { return (f_x > 0 && (here & WALL_WEST) == 0 && (flags[f_x - 1][f_y] & BLOCKED) == 0); } }; public abstract boolean walkable(int[][] flags, int f_x, int f_y, int here); public final int x_shift, y_shift, angle; DirectionalOrientation(int x_shift, int y_shift, int angle) { this.x_shift = x_shift; this.y_shift = y_shift; this.angle = angle; } } public class BitPathfinder extends FloodAgent { public static final int INFINITE_DISTANCE = Integer.MAX_VALUE; private static final int INITIAL_CAPACITY = 8; //what ever floats your boat private final Set<Integer> settledNodes; private final Map<Integer, Double> shortestDistances; private final double Cross = Math.sqrt(2); private final Comparator<Integer> shortestDistanceComparator = new Comparator<Integer>() { public int compare(Integer left, Integer right) { return Double.compare(getShortestDistance(left), getShortestDistance(right)); } }; private final PriorityQueue<Integer> unsettledNodes = new PriorityQueue<>( INITIAL_CAPACITY, shortestDistanceComparator ); private final Map<Integer, Integer> predecessors = new HashMap<>(); public BitPathfinder(Client client) { super(client); this.settledNodes = new HashSet<>(); this.shortestDistances = new HashMap<>(); } private void init(Integer start) { clear(); setShortestDistance(start, 0); unsettledNodes.add(start); } public void execute(Integer start, Integer destination, boolean fullFlood) { init(start); Integer u; while ((u = unsettledNodes.poll()) != null) { if (!fullFlood && u == destination) break; settledNodes.add(u); relaxNeighbors(u); } } //TODO so lazy, overkill bit shifting, does not matter tbh. public int makePositionHash(int x, int y, int z) { return (z << 28 | x << 14 | y); } public int[] getDestinations(int hash) { int x = (hash >> 14) & 0xFF; int y = hash & 0xFF; int[] nodes = new int[0]; for (DirectionalOrientation orientation : DirectionalOrientation.values()) { if (orientation.walkable(flags, x, y, flags[x][y])) { nodes = Arrays.copyOf(nodes, nodes.length + 1); //fk lists nodes[nodes.length - 1] = makePositionHash(x + orientation.x_shift, y + orientation.y_shift, curr_plane); } } return nodes; } private void relaxNeighbors(Integer u) { for (int v : getDestinations(u)) { if (isSettled(v)) continue; int x = (v >> 14) & 0xFF - (u >> 14) & 0xFF; int y = v & 0xFF - u & 0xFF; double shortDist = getShortestDistance(u) + ( (Math.abs(x) > 0 && Math.abs(y) > 0) ? Cross : 1); if (shortDist < getShortestDistance(v)) { setShortestDistance(v, shortDist); setPredecessor(v, u); } } } private boolean isSettled(Integer v) { return settledNodes.contains(v); } private void setShortestDistance(int node, double distance) { unsettledNodes.remove(node); shortestDistances.put(node, distance); unsettledNodes.add(node); } private Integer getPredecessor(int node) { return predecessors.get(node); } private void setPredecessor(int a, int b) { predecessors.put(a, b); } public double getShortestDistance(int node) { Double d = shortestDistances.get(node); return (d == null) ? INFINITE_DISTANCE : d; } public Integer[] extractPath(int destination) { ArrayDeque<Integer> holder = new ArrayDeque<>(); for (Integer node = destination; node != null; node = getPredecessor(node)) holder.add(node); Integer[] a = holder.toArray(new Integer[holder.size()]); reverseOrder(a); return a; } public Position[] findPath(Position start, Position end, boolean fullFlood) { updateBase(); int Start = makePositionHash(start.getX() - base_x, start.getY() - base_y, curr_plane); int End = makePositionHash(end.getX() - base_x, end.getY() - base_y, curr_plane); if (Start == End) return new Position[0]; execute(Start, End, fullFlood); return convert(extractPath(End)); } public Position[] convert(Integer[] nodes) { Position[] real = new Position[nodes.length]; for (int i = 0; i < nodes.length; i++) { int hash = nodes[i]; real[i] = new Position(((hash >> 14) & 0xFF) + base_x, (hash & 0xFF) + base_y, curr_plane); } return real; } public void clear() { settledNodes.clear(); unsettledNodes.clear(); shortestDistances.clear(); predecessors.clear(); } } public static <T> void reverseOrder(T[] nodes) { int l = nodes.length; for (int j = 0; j < l / 2; j++) { T temp = nodes[j]; nodes[j] = nodes[l - j - 1]; nodes[l - j - 1] = temp; } } public class Timer { private long end; private final long start; private final long period; public Timer(final long period) { this.period = period; start = System.currentTimeMillis(); end = start + period; } public boolean isRunning() { return System.currentTimeMillis() < end; } public void reset() { end = System.currentTimeMillis() + period; } } public class SplineWalk { private final Client client; int runningSessionEnableRunThresh; final int MINIMAL_RUN_ENERGY = 30; final int LOCAL_BASE_COMPRESS = 16; final int compressionIndex = 7; public SplineWalk(Client client) { this.client = client; } public int myX() { return client.getMyPlayer().getPosition().getX(); } public int myY() { return client.getMyPlayer().getPosition().getY(); } public Position myPosition() { return client.getMyPlayer().getPosition(); } public double positionDistance(Position A, Position B) { return Math.hypot(A.getX() - B.getX(), A.getY() - B.getY()); } public double distanceTo(Position position) { return positionDistance(client.getMyPlayer().getPosition(), position); } public Position getFarthest(Position[] path) { if (path == null || path.length == 0) return null; Position best = null; Position destination = path[path.length - 1]; double bd = Integer.MAX_VALUE, hold; int distance = (int) (9 + (3 * Math.random() + 1.5)); for (Position node : path) { if ((hold = Math.hypot( node.getX() - destination.getX(), node.getY() - destination.getY())) < bd && distanceTo(node) < distance) { best = node; bd = hold; } } return best; } public boolean withinPreLoadZone(int x, int y, final int baseX, final int baseY) { int realX = baseX + LOCAL_BASE_COMPRESS; int realY = baseY + LOCAL_BASE_COMPRESS; //could clean this up.. int with = 104 - (2 * LOCAL_BASE_COMPRESS); int realX0 = baseX + LOCAL_BASE_COMPRESS + compressionIndex; int realY0 = baseY + LOCAL_BASE_COMPRESS + compressionIndex; int with0 = 104 - (2 * (LOCAL_BASE_COMPRESS + compressionIndex)); return x >= realX && x <= realX + with && y >= realY && y <= realY + with && !(x >= realX0 && x <= realX0 + with0 && y >= realY0 && y <= realY0 + with0); } public boolean isRegional(Position position) { int baseX = position.getX() - client.getMapBaseX(); int baseY = position.getY() - client.getMapBaseY(); return baseX >= LOCAL_BASE_COMPRESS && baseX <= 104 - LOCAL_BASE_COMPRESS && baseY >= LOCAL_BASE_COMPRESS && baseY <= 104 - LOCAL_BASE_COMPRESS; } public Position getRegionalNext(Position[] spline) { //We want the last element of the path. //TODO you can randomize it! Position goal = spline[spline.length - 1], best = spline[0]; //worst double bd = Integer.MAX_VALUE, hold; for (Position step : spline) { if (isRegional(step) && (hold = Math.hypot( goal.getX() - step.getX(), goal.getY() - step.getY())) < bd) { bd = hold; best = step; } } return best; } public boolean canOperate() { return client.getGameState() == 10 && client.getLoginState() == 30; } public boolean checkGameState() throws InterruptedException { if (!canOperate()) { Timer timer = new Timer(5500); while (timer.isRunning() && !canOperate()) Thread.sleep(0, 1); if (!timer.isRunning()) ; //Stop the script.. else return true; } return false; } public boolean splineWalk( FloodAgent pathfinder, Conditional keepWalking, Position[] spline) throws InterruptedException { Position[] path = null; Position next; int regionX = 0, regionY = 0; MinimapTileDestination mouseDestination; runningSessionEnableRunThresh = MINIMAL_RUN_ENERGY; //TODO you can randomize this while (keepWalking.isActive()) { checkGameState(); if (!withinPreLoadZone(myX(), myY(), regionX, regionY)) { if (regionX != client.getMapBaseX() || regionY != client.getMapBaseY() || path == null || path.length == 0) { regionX = client.getMapBaseX(); regionY = client.getMapBaseY(); path = pathfinder.findPath(myPosition(), getRegionalNext(spline), Math.random() > 0.65); if (path.length <= 1) next = getFarthest(spline); else next = getFarthest(path); } else next = getFarthest(path); } else next = getFarthest(spline); if (next == null) { path = null; mouseDestination = new MinimapTileDestination(client.getBot(), (next = getFarthest(spline))); } else mouseDestination = new MinimapTileDestination(client.getBot(), next); if (client.moveMouse(mouseDestination, true)) { client.pressMouse(); int breakDist = (int) (3 * Math.random() + 1.5); Timer timeout = new Timer(1550); while (keepWalking.isActive() && distanceTo( client.getDestination()) > breakDist && timeout.isRunning() && Math.hypot( next.getX() - client.getDestination().getX(), next.getY() - client.getDestination().getY() ) < 4) { //TODO your set run method here if (client.getMyPlayer().isMoving() || checkGameState()) timeout.reset(); Thread.sleep(0, 1); } } } return !keepWalking.isActive(); } } } Whoa!? How do I use this monstrosity? Well here is an example: /** * * This class is from within the packed class, so I would split them, since they are not enclosing classes. */ public class SplineWalkExample extends Script { BitPathfinder pathfinder; SplineWalk splineWalk; public final Position[] splineFromBankToSawMill = new Position[]{ new Position(3252, 3425, 0), new Position(3252, 3426, 0), new Position(3252, 3427, 0), new Position(3252, 3428, 0), new Position(3253, 3428, 0), new Position(3254, 3428, 0), new Position(3255, 3428, 0), new Position(3256, 3428, 0), new Position(3256, 3429, 0), new Position(3257, 3429, 0), new Position(3258, 3429, 0), new Position(3259, 3429, 0), new Position(3260, 3429, 0), new Position(3261, 3429, 0), new Position(3261, 3428, 0), new Position(3262, 3428, 0), new Position(3263, 3428, 0), new Position(3264, 3428, 0), new Position(3265, 3428, 0), new Position(3266, 3428, 0), new Position(3267, 3428, 0), new Position(3268, 3428, 0), new Position(3269, 3428, 0), new Position(3270, 3428, 0), new Position(3271, 3428, 0), new Position(3272, 3428, 0), new Position(3273, 3428, 0), new Position(3274, 3428, 0), new Position(3275, 3428, 0), new Position(3276, 3428, 0), new Position(3277, 3428, 0), new Position(3278, 3428, 0), new Position(3278, 3429, 0), new Position(3279, 3429, 0), new Position(3280, 3429, 0), new Position(3281, 3429, 0), new Position(3282, 3429, 0), new Position(3282, 3430, 0), new Position(3283, 3430, 0), new Position(3283, 3431, 0), new Position(3284, 3431, 0), new Position(3284, 3432, 0), new Position(3285, 3432, 0), new Position(3285, 3433, 0), new Position(3285, 3434, 0), new Position(3285, 3435, 0), new Position(3285, 3436, 0), new Position(3285, 3437, 0), new Position(3285, 3438, 0), new Position(3285, 3439, 0), new Position(3285, 3440, 0), new Position(3285, 3441, 0), new Position(3285, 3442, 0), new Position(3285, 3443, 0), new Position(3285, 3444, 0), new Position(3285, 3445, 0), new Position(3285, 3446, 0), new Position(3285, 3447, 0), new Position(3285, 3448, 0), new Position(3285, 3449, 0), new Position(3285, 3450, 0), new Position(3285, 3451, 0), new Position(3285, 3452, 0), new Position(3285, 3453, 0), new Position(3285, 3454, 0), new Position(3285, 3455, 0), new Position(3285, 3456, 0), new Position(3285, 3457, 0), new Position(3285, 3458, 0), new Position(3285, 3459, 0), new Position(3285, 3460, 0), new Position(3285, 3461, 0), new Position(3286, 3461, 0), new Position(3286, 3462, 0), new Position(3287, 3462, 0), new Position(3288, 3462, 0), new Position(3288, 3463, 0), new Position(3289, 3463, 0), new Position(3290, 3463, 0), new Position(3291, 3463, 0), new Position(3291, 3464, 0), new Position(3292, 3464, 0), new Position(3296, 3464, 0), new Position(3293, 3465, 0), new Position(3294, 3465, 0), new Position(3294, 3466, 0), new Position(3294, 3467, 0), new Position(3295, 3467, 0), new Position(3295, 3468, 0), new Position(3295, 3469, 0), new Position(3296, 3469, 0), new Position(3296, 3470, 0), new Position(3296, 3471, 0), new Position(3297, 3472, 0), new Position(3297, 3473, 0), new Position(3297, 3474, 0), new Position(3297, 3475, 0), new Position(3297, 3476, 0), new Position(3298, 3476, 0), new Position(3298, 3477, 0), new Position(3298, 3480, 0), new Position(3298, 3480, 0), new Position(3298, 3480, 0), new Position(3298, 3481, 0), new Position(3298, 3482, 0), new Position(3298, 3483, 0), new Position(3298, 3484, 0), new Position(3298, 3485, 0), new Position(3298, 3486, 0), new Position(3299, 3490, 0), new Position(3299, 3491, 0), new Position(3299, 3489, 0), new Position(3299, 3490, 0) }; public Position[] splineFromSawToBank; final Conditional thisMustBeTrueToKeepWalking = new Conditional() { @Override public boolean isActive() { return !(myX() > 234234 && myZ() < 234234234); // while NOT between.. those.. bounds, keep chugging. } }; public void onStart() { pathfinder = new BitPathfinder(client); splineWalk = new SplineWalk(client); reverseOrder(splineFromSawToBank = splineFromBankToSawMill.clone()); } public int onLoop() { try { if(splineWalk.splineWalk(pathfinder, thisMustBeTrueToKeepWalking, splineFromBankToSawMill)) { System.out.println("My condition is not true anymore, and broken, so I have met it. that means," + "based on my condition im (myX() > 234234 && myZ() < 234234234)"); //Im here! lets do something } } catch (InterruptedException ignored) { // :'( } return 500; } } I hope this helps, sorry for the lack of depth, I'll try to fix it up tomorrow, but I'm running on fumes posting this.
  7. Hello, Being that the models for items that are elevated are broken(there heights are wrong), I have come up with a method to advert this pesky problem, it simply builds a Prism around were the model should be, and collides its corner vertices to derive it's midpoint, which in most cases, is were exactly the models center point is. Cool stuff. Example: And the src code: package rdpv2; import org.osbot.script.Script; import org.osbot.script.ScriptManifest; import org.osbot.script.rs2.utility.Utilities; import java.awt.*; @ScriptManifest( author = "Brainfree", version = 1.00, info = "Generates a point of elevation were a item on table should be, roughly", name = "Elevated Point Grabber" ) public class TableGrabbing extends Script { public Point[] getLid(int x, int y, int height, double compression) { Point A = getScreenPoint(x, y, 0, 0, height); if (A.x == -1) return null; Point B = getScreenPoint(x, y, 0, 1, height); if (B.x == -1) return null; Point C = getScreenPoint(x, y, 1, 1, height); if (C.x == -1) return null; Point D = getScreenPoint(x, y, 1, 0, height); if (D.x == -1) return null; Point c = getInterceptionPoint(A.x, A.y, C.x, C.y, B.x, B.y, D.x, D.y); Point Ac = getPointOnLineAtDistance(A.x, A.y, c.x, c.y, compression); Point Bc = getPointOnLineAtDistance(B.x, B.y, c.x, c.y, compression); Point Cc = getPointOnLineAtDistance(C.x, C.y, c.x, c.y, compression); Point Dc = getPointOnLineAtDistance(D.x, D.y, c.x, c.y, compression); return new Point[]{Ac, Bc, Cc, Dc}; } private Point getScreenPoint(int x, int y, int sx, int sy, int height) { return Utilities.getScreenCoordinates(bot, (x - client.getMapBaseX() + sx) << 7, (y - client.getMapBaseY() + sy) << 7, height); } public static Point getInterceptionPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { double dot = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); if (dot == 0) new Point(-1, -1); double X = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / dot; double Y = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / dot; return new Point((int) X, (int) Y); } public static Point getPointOnLineAtDistance( double OriginX, double OriginY, double EndLocationX, double EndLocationY, double scale) { final double LegXLength = (EndLocationX - OriginX); final double LegYLength = (EndLocationY - OriginY); double HypotenuseLength = Math.sqrt(LegXLength * LegXLength + LegYLength * LegYLength); double InverseX = HypotenuseLength * scale * LegXLength / HypotenuseLength; double InverseY = (HypotenuseLength * scale * LegYLength) / HypotenuseLength; return new Point( (int) (InverseX + OriginX), (int) (InverseY + OriginY) ); } /** * * Builds a 3D prism around were the ground items model should be in cases * of were the model in a elevated height, and is client failed to interpret it. * * @param tileX The Position X for which the ground item is located. * @param tileY The Position Y for which the ground item is located. * @param heightMin The lower elevation height of the prism. * @param heightMax The upper elevation height of the prism. * @param compression 1.0 = Full Tile bounds length, .75 = 3/4 of the side bounds length * @return The midpoint of the prism. */ public Point getElevatedPoint(int tileX, int tileY, int heightMin, int heightMax, double compression) { Point[] bottom = getLid(tileX, tileX, heightMin, compression); if (bottom == null) return null; Point[] top = getLid(tileX, tileY, heightMax, compression); if (top == null) return null; return getInterceptionPoint( top[0].x, top[0].y, bottom[2].x, bottom[2].y, top[1].x, top[1].y, bottom[3].x, bottom[3].y ); } public int onLoop() { Point wereTheMidPointOfTheModelOfThisItemShouldBe = getElevatedPoint(3232, 3399, 80, 120, .75); return 45; } private void drawLid(Point[] lid, Graphics graphics) { for (int i = 0; i < 4; i++) { graphics.drawLine( lid[i].x, lid[i].y, lid[i == 3 ? 0 : i + 1].x, lid[i == 3 ? 0 : i + 1].y); } } public void drawBounds(int tileX, int tileY, int heightMin, int heightMax, double compression, Graphics g) { Point[] bottom = getLid(tileX, tileY, heightMin, compression); if (bottom == null) return; Point[] top = getLid(tileX, tileY, heightMax, compression); if (top == null) return; for (int i = 0; i < 4; i++) { g.drawLine(bottom[i].x, bottom[i].y, top[i].x, top[i].y); } drawLid(bottom, g); drawLid(top, g); Point center = getInterceptionPoint( top[0].x, top[0].y, bottom[2].x, bottom[2].y, top[1].x, top[1].y, bottom[3].x, bottom[3].y ); g.setColor(Color.red); g.drawString(".", center.x, center.y); } public void onPaint(Graphics graphics) { drawBounds(3232, 3399, 80, 120, .75, graphics); } } Hope you can find great use of it.
  8. Updated to show all facing entities within a given distance.
  9. I must note that this will not work for irregular shaped area.
  10. This piece of software will tell you all Entity by a selected set of types, at a given distance, that you are facing. This has uses to tell what Entity's you can interact with (without changing positions, or direction), or are about to interact with. You could also pair it with animations to tell if a player is interacting with it, or yourself (ex. prioritizing ores by filtering 'currently being mined' ore, same with trees). By mainly this was made to tell what tree your were facing, and decide if it's a evil tree, or not (Wiz). Real use example: Example of use is within the code. import org.osbot.script.Script; import org.osbot.script.rs2.Client; import org.osbot.script.rs2.map.Position; import org.osbot.script.rs2.model.Entity; import org.osbot.script.rs2.model.Player; import java.util.ArrayDeque; import java.util.EnumSet; import java.util.List; /** * @author Brainfree */ public class FacingEntities extends Script { public enum DirectionalOrientation { NORTH_WEST(-1, 1, 135), NORTH(0, 1, 90), NORTH_EAST(1, 1, 45), EAST(1, 0, 0), SOUTH_EAST(1, -1, 315), SOUTH(0, -1, 270), SOUTH_WEST(-1, -1, 225), WEST(-1, 0, 180); public final int x_shift, y_shift, angle; DirectionalOrientation(int x_shift, int y_shift, int angle) { this.x_shift = x_shift; this.y_shift = y_shift; this.angle = angle; } } public Position getFacingPosition(Player player, int distance) { int angle_shift = (player.getRotation() / 0x100) * 45; angle_shift -= 270; if (angle_shift > 0) angle_shift += 270; angle_shift = Math.abs(angle_shift); for (DirectionalOrientation orientation : DirectionalOrientation.values()) { if (orientation.angle == angle_shift) { return new Position( player.getX() + (distance * orientation.x_shift), player.getY() + (distance * orientation.y_shift), player.getZ() ); } } return null; } public enum EntityType { OBJECT { @Override public List<? extends Entity> getType(Client client) { return client.getCurrentRegion().getObjects(); } }, NPC { @Override public List<? extends Entity> getType(Client client) { return client.getLocalNPCs(); } }, PLAYER { @Override public List<? extends Entity> getType(Client client) { return client.getLocalPlayers(); } }, GROUND_ITEM { @Override public List<? extends Entity> getType(Client client) { return client.getCurrentRegion().getItems(); } }; public abstract List<? extends Entity> getType(Client client); } public Entity[] getFacingEntities(Client client, Player player, int distanceInTiles, EnumSet<EntityType> checkFor) { if (checkFor == null || checkFor.size() == 0) return new Entity[0]; final Position facing = getFacingPosition(player, distanceInTiles); if (facing == null) return new Entity[0]; ArrayDeque<Entity> pool = new ArrayDeque<Entity>(); for (EntityType type : checkFor) { for (Entity node : type.getType(client)) { if (node != null && node.getX() == facing.getX() && node.getY() == facing.getY() && node.getZ() == facing.getZ()) { pool.add(node); } } } return pool.toArray(new Entity[pool.size()]); } public int onLoop() { Entity[] entitiesImFacingByMySelectedDistance = getFacingEntities( client, myPlayer(), 1, EnumSet.of(EntityType.NPC)); for(Entity cur : entitiesImFacingByMySelectedDistance) { if(cur.getName() != null && cur.getName() == "Tree") { System.out.println("I'm facing a tree, but possibly not interacting with it."); } } return 200; } } This part will tell ALL entities at a given distance away from player, so if the entities was less than, or equal to the distance you desired, and your facing it, it'll be added into the return. import org.osbot.script.Script; import org.osbot.script.ScriptManifest; import org.osbot.script.rs2.Client; import org.osbot.script.rs2.map.Position; import org.osbot.script.rs2.model.Entity; import org.osbot.script.rs2.model.NPC; import org.osbot.script.rs2.model.Player; import java.awt.*; import java.util.ArrayDeque; import java.util.EnumSet; import java.util.List; /** * @author Brainfree */ @ScriptManifest(author = "Brainfree", version = 1.0, info = "Tells all entities you're facing, within a given distance.", name = "FutureViewer") public class AllFacingEntities extends Script { public enum DirectionalOrientation { NORTH_WEST(-1, 1, 135), NORTH(0, 1, 90), NORTH_EAST(1, 1, 45), EAST(1, 0, 0), SOUTH_EAST(1, -1, 315), SOUTH(0, -1, 270), SOUTH_WEST(-1, -1, 225), WEST(-1, 0, 180); public final int x_shift, y_shift, angle; DirectionalOrientation(int x_shift, int y_shift, int angle) { this.x_shift = x_shift; this.y_shift = y_shift; this.angle = angle; } } enum EntityType { OBJECT { @Override public List<? extends Entity> getType(Client client) { return client.getCurrentRegion().getObjects(); } }, NPC { @Override public List<? extends Entity> getType(Client client) { return client.getLocalNPCs(); } }, PLAYER { @Override public List<? extends Entity> getType(Client client) { return client.getLocalPlayers(); } }, GROUND_ITEM { @Override public List<? extends Entity> getType(Client client) { return client.getCurrentRegion().getItems(); } }; public abstract List<? extends Entity> getType(Client client); } public Position getFacingPosition(Player player) { int angle_shift = (player.getRotation() / 0x100) * 45; angle_shift -= 270; if (angle_shift > 0) angle_shift += 270; angle_shift = Math.abs(angle_shift) + 180; if(angle_shift >= 360) angle_shift-= 360; for (DirectionalOrientation orientation : DirectionalOrientation.values()) { if (orientation.angle == angle_shift) { return new Position( player.getX() + orientation.x_shift, player.getY() + orientation.y_shift, player.getZ() ); } } return null; } public static boolean lineContainsPoint(double Ax, double Ay, double Bx, double By, double Px, double Py) { double cross_product = (Py - Ay) * (Bx - Ax) - (Px - Ax) * (By - Ay); double dotproduct = (Px - Ax) * (Bx - Ax) + (Py - Ay) * (By - Ay); return Math.abs((cross_product)) == 0 && dotproduct < 0; } public Entity[] getFacingEntities(Client client, Player player, int distanceInTiles, EnumSet<EntityType> checkFor) { if (checkFor == null || checkFor.size() == 0) return new Entity[0]; final Position facing = getFacingPosition(player); final Position me = client.getMyPlayer().getPosition(); if (facing == null) return new Entity[0]; ArrayDeque<Entity> pool = new ArrayDeque<Entity>(); for (EntityType type : checkFor) { for (Entity node : type.getType(client)) { if (node != null && lineContainsPoint( me.getX(), me.getY(), facing.getX(), facing.getY(), node.getX(), node.getY()) && Math.hypot(node.getX() - me.getX(), node.getY() - me.getY() ) <= distanceInTiles) { pool.add(node); } } } return pool.toArray(new Entity[pool.size()]); } public int onLoop() { Entity[] AllEntitiesImFacingWithinADistanceOf3 = getFacingEntities(client, myPlayer(), 3, EnumSet.of( EntityType.OBJECT, EntityType.NPC)); for(Entity whatImFacing : AllEntitiesImFacingWithinADistanceOf3) { if(whatImFacing instanceof NPC && whatImFacing.getName() == "Banker tutor") { System.out.println("I'm facing a banker tutor :}, she could be 3 tiles away, or even less >_>"); } } return 500; } public void onPaint(Graphics graphics) { Entity[] AllEntitiesImFacingWithinADistanceOf3 = getFacingEntities(client, myPlayer(), 3, EnumSet.of( EntityType.OBJECT, EntityType.NPC)); for(Entity whatImFacing : AllEntitiesImFacingWithinADistanceOf3) { ((Graphics2D) graphics).draw(whatImFacing.getMouseDestination().getArea()); } } } Hope this helps. /Updated, forgot to implement the distance into it. /Updated, as requested by wiz, added code for all facing entities, within a given distance.
  11. A lack of knowledge is not a lack of capability.

  12. Also if its obfuscated, and you don't know how to reverse engineer it, demand a private meeting, or simply ask a buddy who can read past the cluster.
  13. Brainfree

    So Um?

    It might be, but who bothered to even take the time to check? They have clarified that it's not by there actions that it was distributed to seemingly every user. And if they have not notified previously of any given updated, like they have for basically every update they've done; then it's worth suspicion. And I'm sure they'll never personally PM every given user to notify them of an update, that's just silly and a waste of resources. Also you may note it's an executable program, which is a dead give away that's it's fake.
  14. Look over scripts on the forms, it's how I first started out. Even if it's honest Copy and Pasting, if it works, it works. But I'm sure you're more for the knowledge, so I would suggest studying multiple implementations of your desired methods, and see how there used, and how they are structured into any given script.
  15. When the API (located on the top banner) is seemingly fixed, look over it. It has documentation on how each method within the API works, along with the required parameters. You could also import it into your IDE if you so wished, but that's a little extreme for your situation. But right now that's all I have to to suggest to you before I pass out on my bed. -Night all.
  16. Alright, at least this is not as bad as I thought have had happened.
  17. This algorithm will extract the bounding points of a given Entities model. This could be used for a more precise interacting, Triangulation, Notification, and just plain looking cool. :^) Disclaimers: The utilities methods for model to points is not working perfectly right now, and it'll cause some weird issues, but its stable. Example: The Code: import org.osbot.script.Script;import org.osbot.script.ScriptManifest;import org.osbot.script.rs2.model.Entity;import org.osbot.script.rs2.model.Model;import org.osbot.script.rs2.model.Player;import org.osbot.script.rs2.utility.Utilities;import java.awt.*;import java.util.Arrays;import java.util.HashSet;import java.util.Iterator;@ScriptManifest(author = "Brainfree", version = 1.0D, name = "OSModelHaulgorithm", info = "Constructs a Convex Haul around a Entities model.")public class OSModelHaulgorithm extends Script { public void onPaint(Graphics g) { for (Player current_player : client.getLocalPlayers()) { Polygon haul = buildEntityConvexPolygon(current_player); if(haul == null) return; ((Graphics2D) g).draw(haul); } } public Polygon buildEntityConvexPolygon(Entity gameObject) { PointSeries structure = buildModelConvexHaul( gameObject.getModel(), gameObject.getGridX(), gameObject.getGridY() ); if (structure == null) return null; return new Polygon(structure.x_points, structure.y_points, structure.num_points); } public PointSeries buildModelConvexHaul(Model model, int gridX, int gridY) { try { Point[] points = Utilities.getModelScreenPoints(this.getBot(), gridX, gridY, model); if (points == null || points.length <= 2) return null; //can't do much with a line. int[][] data = reflectClean(points); int[] x_cluster = new int[data.length], y_cluster = new int[data.length]; for (int i = 0; i < data.length; i++) { x_cluster[i] = data[i][0]; y_cluster[i] = data[i][1]; } PointSeries data_destination = new PointSeries(); reflectHaul(x_cluster, y_cluster, data.length, data_destination); data_destination.filter(0); //empty element slots. return data_destination; } catch (Exception ignored) {} //Utility errors. return null; } public int[][] reflectClean(Point[] points) { HashSet<Point> nodes = new HashSet<Point>(Arrays.asList(points)); //cheaper then clear. int[][] data_matrix = new int[nodes.size()][2]; Iterator<Point> data = nodes.iterator(); Point cur; for (int i = 0; i < nodes.size(); i++) { cur = data.next(); data_matrix[i][0] = cur.x; data_matrix[i][1] = cur.y; } return data_matrix; } public static class PointSeries { private int[] x_points; private int[] y_points; private int num_points = 0; public PointSeries(int initialCapacity) { this.x_points = new int[initialCapacity]; this.y_points = new int[initialCapacity]; } public PointSeries() { this(10); } public void filter(int invalid) { int valid_size = 0; for (int i = 0; i < num_points; i++) if (x_points[i] != invalid && y_points[i] != invalid) valid_size++; int[] x_dest = new int[valid_size], y_dest = new int[valid_size]; int x, y; for (int i = 0; i < num_points; i++) { if ((x = x_points[i]) != invalid && (y = y_points[i]) != invalid) { x_dest[i] = x; y_dest[i] = y; } } x_points = x_dest; y_points = y_dest; num_points = valid_size; } private void expand(int newCapacity) { x_points = Arrays.copyOf(x_points, newCapacity); y_points = Arrays.copyOf(y_points, newCapacity); } public void addPoint(int x, int y) { if (num_points + 1 > x_points.length) expand(((num_points * 3) / 2) + 1); x_points[num_points] = x; y_points[num_points] = y; num_points++; } } public boolean small(int[] xPoints, int[] yPoints, int current, int smallest, int i) { int xa, ya, xb, yb, val; xa = xPoints[smallest] - xPoints[current]; xb = xPoints[i] - xPoints[current]; ya = yPoints[smallest] - yPoints[current]; yb = yPoints[i] - yPoints[current]; val = xa * yb - xb * ya; if (val > 0) return true; else if (val < 0) return false; else { if (xa * xb + ya * yb < 0) return false; else { if (xa * xa + ya * ya > xb * xb + yb * yb) return true; else return false; } } } public void reflectHaul( int[] x_cluster, int[] y_cluster, int numPoints, PointSeries destination) { int min = 0, smallest; for (int i = 1; i < numPoints; i++) { if (y_cluster[i] == y_cluster[min]) { if (x_cluster[i] < x_cluster[min]) min = i; } else if (y_cluster[i] < y_cluster[min]) min = i; } int current = min; do { destination.addPoint(x_cluster[current], y_cluster[current]); smallest = 0; if (smallest == current) smallest = 1; for (int i = 0; i < numPoints; i++) { if ((current == i) || (smallest == i)) continue; if (small(x_cluster, y_cluster, current, smallest, i)) smallest = i; } current = smallest; } while (current != min); }} Have fun!
×
×
  • Create New...