Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Disable camera movement when walking to tile?


    chartpk

    Recommended Posts

    Hi,

    I'm currently using the code below to make player move by clicking on a tile on the canvas screen. However, I don't want the camera to rotate. So i'd like the bot to click somewhere on the screen to get closer to NPC, without moving camera.

     

    Code currently using:

    getWalking().walkOnScreen(getMap().getWalkable(closestNpc.getTile()));

    PS: On a different note, i'm wondering whether the client's mouse speed is constant? For example it's set to 5 by default, or even 6, 7,8,9, or 10. Are all these fixed, constant speeds? Or do they vary?

    Link to comment
    Share on other sites

    Try something of sorts.

    It is not gonna do anything if it ain't visible, you gotta add that part if you want

     

    Tile tileToWalkTo = new Tile(1234,1234);
    if(getMap().isVisible(tileToWalkTo)){
       Polygon poly = tileToWalkTo.getPolygon();
       if(poly != null){
          getMouse().click(poly.getBounds().getLocation());
       }
    }
    
    Link to comment
    Share on other sites

    Try something of sorts.

    It is not gonna do anything if it ain't visible, you gotta add that part if you want

     

    Tile tileToWalkTo = new Tile(1234,1234);
    if(getMap().isVisible(tileToWalkTo)){
       Polygon poly = tileToWalkTo.getPolygon();
       if(poly != null){
          getMouse().click(poly.getBounds().getLocation());
       }
    }
    

     

    That's really neat!! Thank you. All though, the main idea is that the initial goal tile is outside of screen. Then the player should walk closer to it by clicking somewhere on screen to get closer to that area, without moving camera.

     

    See image:

    kjC1Tlm.png

    Basically the tile supposed to walk to is outside screen, where NPC is. The clickable points would then be within the blue area,, green area, and yellow area, where yellow area is the most likely clicked point. (Let's disregard any objecs in between, and the path is free to walk to)

     

    Maybe something like this could work?:

     

    //Walks towards a goal tile only using screen, without turning camera
        public void walkToPointOnScreenTowardsEntity(Entity entity) {
            Tile t = new Tile(entity.getTile());
            if(getMap().isVisible(t)) {
                //Walk there
                Polygon poly = t.getPolygon();
                if (poly != null) {
                    getMouse().click(poly.getBounds().getLocation());
                }
            } else {
                //Calculate a closer tile
                Tile myPlayerTile = getLocalPlayer().getTile();
                //Calculate a tile closer to our player's tile from the goal tile
                int goalTileX = t.getX();
                int goalTileY = t.getY();
    
                int myPlayerTileX = myPlayerTile.getX();
                int myPlayerTileY = myPlayerTile.getY();
    
                //Will calculate the center point between player coords and goal tile coords.
                int centerPointX = (goalTileX - myPlayerTileX) / 2;
                int centerPointY = (goalTileY - myPlayerTileY) / 2;
    
                //Now just add the new coordinates to player's current coordinates, to get the tile located between player and goal tile
                centerPointX = (myPlayerTileX+Math.round(centerPointX),myPlayerTileY+Math.round(centerPointY));
                Tile closerTileToWalkTo = new Tile(centerPointX, centerPointY);
                
                //Call recursively until a closer tile is found
                walkToPointOnScreenTowardsEntity(closerTileToWalkTo);
            }
        } 

    Do you think this would work, or be good? Eventually I could add a gauss distribution to the tiles if the new, closer calculated tiles if they're on screen.

    An example would be:

    Goal tiles: (3210,3000);

     

    Player tiles: (3200,2995);

     

    Closer tiles:((goal.x-player.x)/2,(goal.y-player.y)/2));

    Closer tiles: ((3210-3200)/2,(3000-2995)/2);

    Closer tiles (Math.round(5),Math.round(2.5));

    Closer tiles (5,3);

    //Now add player's tiles

    Closer tiles (3200+5,2995+3);

     

    Closer tiles: (3205,2998);

     

    And then, with the assumption that this closer tile will now be visible on screen and available to click on. Would this be any good?

    Link to comment
    Share on other sites

    That's really neat!! Thank you. All though, the main idea is that the initial goal tile is outside of screen. Then the player should walk closer to it by clicking somewhere on screen to get closer to that area, without moving camera.

     

    See image:

    kjC1Tlm.png

    Basically the tile supposed to walk to is outside screen, where NPC is. The clickable points would then be within the blue area,, green area, and yellow area, where yellow area is the most likely clicked point. (Let's disregard any objecs in between, and the path is free to walk to)

    What you ask there will require the use of a pathfinder and that will always give you the shortest route.

    Link to comment
    Share on other sites

    What you ask there will require the use of a pathfinder and that will always give you the shortest route.

    How would you implement a pathfinder?

     

    I tried doing something in the code below to find a center point between player and npc goal tile, so that when npc tile is too far away, it'll find a tile in the center between player and npc, which hopefully is clickable and visible on screen. You think this would work?:

     

     

    //Walks towards a goal tile only using screen, without turning camera
        public void walkToPointOnScreenTowardsEntity(Entity entity) {
            Tile t = new Tile(entity.getTile());
            if(getMap().isVisible(t)) {
                //Walk there
                Polygon poly = t.getPolygon();
                if (poly != null) {
                    //Can I make this click ONLY if the uptext is "Walk here"?
                    getMouse().click(poly.getBounds().getLocation());
                }
            } else {
                //Calculate a closer tile
                Tile myPlayerTile = getLocalPlayer().getTile();
                //Calculate a tile closer to our player's tile from the goal tile
                int goalTileX = t.getX();
                int goalTileY = t.getY();
    
                int myPlayerTileX = myPlayerTile.getX();
                int myPlayerTileY = myPlayerTile.getY();
    
                //Will calculate the center point between player coords and goal tile coords.
                int centerPointX = (goalTileX - myPlayerTileX) / 2;
                int centerPointY = (goalTileY - myPlayerTileY) / 2;
    
                //Now just add the new coordinates to player's current coordinates, to get the tile located between player and goal tile
                centerPointX = (myPlayerTileX+Math.round(centerPointX),myPlayerTileY+Math.round(centerPointY));
                Tile closerTileToWalkTo = new Tile(centerPointX, centerPointY);
                
                //Call recursively until a closer tile is found
                walkToPointOnScreenTowardsEntity(closerTileToWalkTo);
            }
        }
    
    Link to comment
    Share on other sites

    ...

    what if there's a wall in between? Or on one side? You cant use that method, its unreliable.

    Also start looking at the API, its fairly simple to use a local pathfinder.

    AStarPathFinder pf = getWalking().getAStarPathFinder();
    Tile start = new Tile();
    Tile end = new Tile();
    LocalPath<Tile> path = pf.calculate(start,end);
    

    That will give you a list (LocalPath) that has tiles from start to end. It will always be the shortest path.

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.