The client is offline due to RuneScape update. You may see instance errors but this is due to the update and not actual instance errors. This should be resolved soon. Join our Discord for more information.

Area Building + Movement



  • Hi guys, i am porting over my other script from a different client and i just have a few quick issues that i need help with;

    I am trying to build a new area (B & C) by getting a random position in area (A) but i can't find a method to get a random position other than getting the center and to randomize it, but this is not working so well since it will just run to the center.

    My build method is this:

    protected Area buildArea(Position position, int size) {
            return Area.rectangular(new Position(position.getX() - size, position.getY() - size, 0), new Position(position.getX() + size, position.getY() + size, 0));
        }
    

    and my other code is this (pseudo and not fully ported) :

    {
                        Area area = null;
                        if (lastCheckedArea != null) {
                            area = buildArea(bff.getRandomPosition(), 10);
                        } else {
                            area = buildArea(bff.getRandomPosition(), 10);
                            while (api.getMap().realDistance(area.getRandomPosition()) < 25) {
                                area = buildArea(bff.getRandomPosition(), 10);
                            }
                        }
                        if (!inArea(area)) {
                            lastCheckedArea = area;
                            settings.setCurrentAction("Walking to random position in mole lair");
                            if (! Movement.isStaminaEnhancementActive() && Movement.getRunEnergy() <= 70) {
                                settings.setCurrentAction("Drinking stamina potion");
                                drinkPotion.drink("Stamina potion");
                            }
                            WalkingEvent walkingEvent = new WalkingEvent(area);
                            walkingEvent.setMinDistanceThreshold(0);
                            walkingEvent.setBreakCondition(new Condition() {
                                @Override
                                public boolean evaluate() {
                                    return findMole() != null;
                                }
                            });
                            api.execute(walkingEvent);
                        }
                    }
    

    tldr; need to build an area from an existing area by grabbing a random tile and building the area from the random position


  • Script Developer Sponsor Staff Director

    Your area building can be simplified to use Area.surrounding

    As for your question, you can use Random.nextElement(area.getTiles())



  • @Spencer said in Area Building + Movement:

    Your area building can be simplified to use Area.surrounding

    As for your question, you can use Random.nextElement(area.getTiles())

    Thanks for the reply, i'll check those methods out, thanks!


 

60
Online

11.4k
Users

1.1k
Topics

15.0k
Posts