Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Issue on method

Featured Replies

I can't get it work, building a method for getting random coords Positions, but it never works, all help will be aprecciate

 

 

import java.util.ArrayList;

import java.util.Random;

 

import org.osbot.script.rs2.map.Position;

 

 

public class testa {

 

public static void main(String[] args) {

// TODO Auto-generated method stub

ArrayList<Position> tree = new ArrayList<>();

tree.add(new Position(2827,3087,0));

tree.add(new Position(2827,3036,0));

tree.add(new Position(2826,3087,0));

tree.add(new Position(2826,3085,0));

for(int i = 0; i < tree.size(); i++){

Random r = new Random();

i = r.nextInt(i);

tree.get(i);

System.out.println(i);

}

}

 

}

What does it log?

Edit: please start getting use to using a list.

List<Position> tree = new ArrayList<Position>();

Edited by josedpay

System.out.println(i);

 

Should just print out 1-4 (0-3?)...

 

I'm not all to familiar with Position, but look at this -

String[] Salutations = {"Hi", "Hello", "Hey"};

public void onMyCommand() {
  Random r = newRandom();
  int pickMe = r.random(Salutations.size()-1); //Whatever the random integer method is, ranging from 0 to 1 less than the max array value 
  //Arrays start at 0
  System.out.println(Salutations[pickMe]+" there, digdig18.");
}

You take a random number, that wouldn't exceed the value of your array, and then select that position in the array.

I would probably do it like this

public final Position[] positions = {new Position(2827,3087,0), new Position(2827,3036,0), new Position(2826,3087,0), new Position(2826,3085,0)};

public Position getRandomPosition(){
    return positions[random(positions.length)];
}

Edited by Ande

  • Author

System.out.println(i);

 

Should just print out 1-4 (0-3?)...

 

I'm not all to familiar with Position, but look at this -

String[] Salutations = {"Hi", "Hello", "Hey"};

public void onMyCommand() {
  Random r = newRandom();
  int pickMe = r.random(Salutations.size()-1); //Whatever the random integer method is, ranging from 0 to 1 less than the max array value 
  //Arrays start at 0
  System.out.println(Salutations[pickMe]+" there, digdig18.");
}

You take a random number, that wouldn't exceed the value of your array, and then select that position in the array.

Yes mr thelegacy0, it should pick a random number between 1-4 (i have 4 coords), and thank's !

 

I would probably do it like this

public final Position[] positions = {new Position(2827,3087,0), new Position(2827,3036,0), new Position(2826,3087,0), new Position(2826,3085,0)};

public Position getRandomPosition(){
    return positions[random(positions.length)];
}

I'm surprised with your lean code, probably i will use this, thanks for the attention.

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.