Chikan Posted November 20, 2017 Share Posted November 20, 2017 I'm trying to write a PC script for myself, but I got snagged on the instancing of the tiles. What I've tried so far was to simply use Explv's map and just throw the area in and end my day. Area DefenceArea = new Area (2670,2585,2643,2602); Area PrimaryDefenceArea = new Area (2653,2596,2660,2589); Obviously these won't work since it's an instanced area and the tiles will vary each time so my question is: How would I properly get these kind tiles positions? Or, if possible how would I use As I've noticed those are seemingly static in instanced areas. Any help appriciated. Quote Link to comment Share on other sites More sharing options...
IDontEB Posted November 20, 2017 Share Posted November 20, 2017 Find some objects inside the instance that never move. Take that object's position and subtract or add the amount needed to the X and Y of the static object to get to the desired position. For example: You have barrier located at X,Y,Z. The position you want is 5 left and 2 down from the barrier so what you do new Position(barrier.getX()-5, barrier.gety()-2, barrier.getZ()) etc etc Quote Link to comment Share on other sites More sharing options...
Lemons Posted November 20, 2017 Share Posted November 20, 2017 (edited) Grid position is going to be a bad indicator, as it is simply a more accurate representation of the local position (think sub-positions). Each position has a 128x128 grid used for animations/moving characters. In your example: 6784 / 128 = 53 6272 / 128 = 49 Which is the same values for the local x/y. They seem static as the local/grid positions are the same relative to the loaded region. There are a few ways to handle instances areas. You can just use local position if it doesn't change from instance to instance, but if the region doesn't contain the entire instance, it won't work. You can find the furthest reachable east X and furthest reachable south Y, then use that as "0,0" and offset from that position. Or you can use an object that has a unique position, or a collection of objects, and get a point of reference from there. Edit: To add to IDontEB, you can use that but the API has a translate method for positions: Position offsetPos = barrier.getPosition().translate(-5, -2); Edited November 20, 2017 by Lemons 4 Quote Link to comment Share on other sites More sharing options...
Explv Posted November 20, 2017 Share Posted November 20, 2017 (edited) 3 hours ago, Chikan said: I'm trying to write a PC script for myself, but I got snagged on the instancing of the tiles. What I've tried so far was to simply use Explv's map and just throw the area in and end my day. Area DefenceArea = new Area (2670,2585,2643,2602); Area PrimaryDefenceArea = new Area (2653,2596,2660,2589); Obviously these won't work since it's an instanced area and the tiles will vary each time so my question is: How would I properly get these kind tiles positions? Or, if possible how would I use As I've noticed those are seemingly static in instanced areas. Any help appriciated. Like Fruity said you could use your local position in the region: myPosition().getLocalX() myPosition().getLocalY() As those coordinates will always be the same. To get the actual in game position, you would then add the local position to the region's start position: int actualX = getMap().getBaseX() + localX int actualY = getMap().getBaseY() + localY However a region isn't that big, I think 104 x 104 tiles, and I'm not sure if PC spans multiple regions, it might do. You could just store the baseX and baseY of the region where you spawn in PC, I think you always spawn in the same place right? And then when you start a game of PC you just get the baseX and baseY in the current instance, calculate the offset and apply it to all your stores positions and areas: final int baseXStartRegion = 1234; final int baseYStartRegion = 1234; int offsetX, offsetY; // When new PC game starts offsetX = baseXStartRegion - getMap().getBaseX(); offsetY = baseYStartRegion - getMap().getBaseY(); Then when you want to walk somewhere just apply the offsets to the destination position: Position getInstancedPosition(Position position) { return position.translate(offsetX, offsetY); } I *think* that should work. Edited November 20, 2017 by Explv Quote Link to comment Share on other sites More sharing options...
Explv Posted November 20, 2017 Share Posted November 20, 2017 (edited) 6 hours ago, Chikan said: I'm trying to write a PC script for myself, but I got snagged on the instancing of the tiles. What I've tried so far was to simply use Explv's map and just throw the area in and end my day. Area DefenceArea = new Area (2670,2585,2643,2602); Area PrimaryDefenceArea = new Area (2653,2596,2660,2589); Obviously these won't work since it's an instanced area and the tiles will vary each time so my question is: How would I properly get these kind tiles positions? Or, if possible how would I use As I've noticed those are seemingly static in instanced areas. Any help appriciated. Here is an example I came up with. Note that this is completely untested, but hopefully should help you understand what I meant in my previous comment. import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author = "Explv", name = "Example", info = "", logo = "", version = 0.1) public final class ExampleScript extends Script { /* This is getMap().getBaseX() and getMap().getBaseX() when the player is standing in boat at the start of Pest Control in the instance when all Positions and Areas were collected */ private static final int BOAT_REGION_BASE_X = 1234; private static final int BOAT_REGION_BASE_Y = 1234; // This position was collected in the same instance as the above base x and base y private static final Position PORTAL_POSITION = new Position(1, 2, 0); // This area was collected in the same isntance as the above base x and base y private static final CustomArea EXAMPLE_AREA = new CustomArea(1, 2, 3, 4); // These are the offsets from the current instance positions and the above positions private int offsetX = 0; private int offsetY = 0; // Determines if we have updated the above offsets in the current instance private boolean offsetsUpdated = false; @Override public int onLoop() throws InterruptedException { if (inPestControlGame()) { if (!offsetsUpdated) { offsetX = BOAT_REGION_BASE_X - getMap().getBaseX(); offsetY = BOAT_REGION_BASE_Y - getMap().getBaseY(); offsetsUpdated = true; } } else { offsetsUpdated = false; } if (!getInstancedArea(EXAMPLE_AREA).contains(myPosition())) { getWalking().walk(getInstancedArea(EXAMPLE_AREA)); } return 600; } private boolean inPestControlGame() { // Maybe check a widget exists or something return true; } private Position getInstancedPosition(final Position position) { return position.translate(offsetX, offsetY); } private Area getInstancedArea(final CustomArea area) { return area.translate(offsetX, offsetY); } } // Creating a CustomArea class so that we can store the start and end position // and also add a handy translate method class CustomArea extends Area { private Position startPosition, endPosition; public CustomArea(int x1, int y1, int x2, int y2) { super(x1, y1, x2, y2); startPosition = new Position(x1, y1, 0); endPosition = new Position(x2, y2, 0); } @Override public Area setPlane(final int z) { super.setPlane(z); startPosition = new Position(startPosition.getX(), startPosition.getY(), z); endPosition = new Position(endPosition.getX(), endPosition.getY(), z); return this; } public Area translate(final int offsetX, final int offsetY) { return new Area(startPosition.translate(offsetX, offsetY), endPosition.translate(offsetX, offsetY)); } } Edited November 20, 2017 by Explv 1 Quote Link to comment Share on other sites More sharing options...
Chikan Posted November 21, 2017 Author Share Posted November 21, 2017 On 20/11/2017 at 7:59 AM, Explv said: Here is an example I came up with. Note that this is completely untested, but hopefully should help you understand what I meant in my previous comment. import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author = "Explv", name = "Example", info = "", logo = "", version = 0.1) public final class ExampleScript extends Script { /* This is getMap().getBaseX() and getMap().getBaseX() when the player is standing in boat at the start of Pest Control in the instance when all Positions and Areas were collected */ private static final int BOAT_REGION_BASE_X = 1234; private static final int BOAT_REGION_BASE_Y = 1234; // This position was collected in the same instance as the above base x and base y private static final Position PORTAL_POSITION = new Position(1, 2, 0); // This area was collected in the same isntance as the above base x and base y private static final CustomArea EXAMPLE_AREA = new CustomArea(1, 2, 3, 4); // These are the offsets from the current instance positions and the above positions private int offsetX = 0; private int offsetY = 0; // Determines if we have updated the above offsets in the current instance private boolean offsetsUpdated = false; @Override public int onLoop() throws InterruptedException { if (inPestControlGame()) { if (!offsetsUpdated) { offsetX = BOAT_REGION_BASE_X - getMap().getBaseX(); offsetY = BOAT_REGION_BASE_Y - getMap().getBaseY(); offsetsUpdated = true; } } else { offsetsUpdated = false; } if (!getInstancedArea(EXAMPLE_AREA).contains(myPosition())) { getWalking().walk(getInstancedArea(EXAMPLE_AREA)); } return 600; } private boolean inPestControlGame() { // Maybe check a widget exists or something return true; } private Position getInstancedPosition(final Position position) { return position.translate(offsetX, offsetY); } private Area getInstancedArea(final CustomArea area) { return area.translate(offsetX, offsetY); } } // Creating a CustomArea class so that we can store the start and end position // and also add a handy translate method class CustomArea extends Area { private Position startPosition, endPosition; public CustomArea(int x1, int y1, int x2, int y2) { super(x1, y1, x2, y2); startPosition = new Position(x1, y1, 0); endPosition = new Position(x2, y2, 0); } @Override public Area setPlane(final int z) { super.setPlane(z); startPosition = new Position(startPosition.getX(), startPosition.getY(), z); endPosition = new Position(endPosition.getX(), endPosition.getY(), z); return this; } public Area translate(final int offsetX, final int offsetY) { return new Area(startPosition.translate(offsetX, offsetY), endPosition.translate(offsetX, offsetY)); } } ily Quote Link to comment Share on other sites More sharing options...