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.

Interacting with an array of strings instead of a string

Featured Replies

Want to be able to interact with multiple account names, not just one using : eg.       Player playersToTrade = getPlayers().closest("One Account");

 

What i've tried: (returns as if playersToTrade is null/not found)

	    String entities[] = {"name1", "name2", "acc4", "acc3"};
    
Player playersToTrade = getPlayers().closest(entities);
        if(playersToTrade != null) {
            if(!playersToTrade.isVisible()){
                camera.toEntity(playersToTrade);
                sleep(random(650,2450));
                
            } else if(playersToTrade.isVisible()) {
            playersToTrade.interact("Trade with");
            sleep(random(2500, 5000));
            }
	

Edited by vaynex

you can use simple loop

private String playerNames[] = {"name1", "name2", "acc4", "acc3"};
private static final TRADE_ACTION = "Trade with";

private void interactWithPlayer(){
	for(int i = 0; i < playerNames.length; i++{
		Player playersToTrade = getPlayers().closest(playerNames[i]);
        if(playersToTrade != null) {
            if(!playersToTrade.isVisible()){
                camera.toEntity(playersToTrade);
                sleep(random(650,2450));
                
            } else if(playersToTrade.isVisible()) {
            playersToTrade.interact(TRADE_ACTION);
            sleep(random(2500, 5000));
            }
       
                                              }
}

I dont know if i understand you questionAlso after            

 playersToTrade.interact(TRADE_ACTION) 

i suggest you to use also

while(context.myPlayer().isMoving()){

sleep...

}

 

Edited by Efpkaf

1 hour ago, Efpkaf said:

you can use simple loop


private String playerNames[] = {"name1", "name2", "acc4", "acc3"};
private static final TRADE_ACTION = "Trade with";

private void interactWithPlayer(){
	for(int i = 0; i < playerNames.length; i++{
		Player playersToTrade = getPlayers().closest(playerNames[i]);
        if(playersToTrade != null) {
            if(!playersToTrade.isVisible()){
                camera.toEntity(playersToTrade);
                sleep(random(650,2450));
                
            } else if(playersToTrade.isVisible()) {
            playersToTrade.interact(TRADE_ACTION);
            sleep(random(2500, 5000));
            }
       
                                              }
}

I dont know if i understand you questionAlso after            


 playersToTrade.interact(TRADE_ACTION) 

i suggest you to use also


while(context.myPlayer().isMoving()){

sleep...

}

 

 

Do not do this.

 

5 hours ago, vaynex said:

Want to be able to interact with multiple account names, not just one using : eg.       Player playersToTrade = getPlayers().closest("One Account");

 

What i've tried: (returns as if playersToTrade is null/not found)


	    String entities[] = {"name1", "name2", "acc4", "acc3"};
    
Player playersToTrade = getPlayers().closest(entities);
        if(playersToTrade != null) {
            if(!playersToTrade.isVisible()){
                camera.toEntity(playersToTrade);
                sleep(random(650,2450));
                
            } else if(playersToTrade.isVisible()) {
            playersToTrade.interact("Trade with");
            sleep(random(2500, 5000));
            }
	

Are there spaces in the usernames?

Edited by Explv

2 hours ago, Efpkaf said:

you can use simple loop


private String playerNames[] = {"name1", "name2", "acc4", "acc3"};
private static final TRADE_ACTION = "Trade with";

private void interactWithPlayer(){
	for(int i = 0; i < playerNames.length; i++{
		Player playersToTrade = getPlayers().closest(playerNames[i]);
        if(playersToTrade != null) {
            if(!playersToTrade.isVisible()){
                camera.toEntity(playersToTrade);
                sleep(random(650,2450));
                
            } else if(playersToTrade.isVisible()) {
            playersToTrade.interact(TRADE_ACTION);
            sleep(random(2500, 5000));
            }
       
                                              }
}

I dont know if i understand you questionAlso after            


 playersToTrade.interact(TRADE_ACTION) 

i suggest you to use also


while(context.myPlayer().isMoving()){

sleep...

}

 

please no

  • Author
2 hours ago, Explv said:

 

Do not do this.

 

Are there spaces in the usernames? 

 

note: When using Player playersToTrade = getPlayers().closest("One Account");  it works just fine. its just i have multiple mules and want the script to interact with any account that becomes visible

 

 

 

Yes, For example, 

    String entities[] = {"Mule Acc1", "Mule Acc2", "Mule Acc3", "Mule Acc4"};
	

Edited by vaynex

4 hours ago, Explv said:

 

Do not do this.

 

Are there spaces in the usernames?

What's a better method? I use something along the same lines to grab accounts from a text file.

You can have a counter that you use as the element number for the array. Increment the counter every time a trade is completed.

3 hours ago, vaynex said:

Yes, For example, 


    String entities[] = {"Mule Acc1", "Mule Acc2", "Mule Acc3", "Mule Acc4"};
	

-removed-

 

Edited by Explv

On 05/07/2017 at 1:35 PM, vaynex said:

Want to be able to interact with multiple account names, not just one using : eg.       Player playersToTrade = getPlayers().closest("One Account");

 

What i've tried: (returns as if playersToTrade is null/not found)


	    String entities[] = {"name1", "name2", "acc4", "acc3"};
    
Player playersToTrade = getPlayers().closest(entities);
        if(playersToTrade != null) {
            if(!playersToTrade.isVisible()){
                camera.toEntity(playersToTrade);
                sleep(random(650,2450));
                
            } else if(playersToTrade.isVisible()) {
            playersToTrade.interact("Trade with");
            sleep(random(2500, 5000));
            }
	

 

Does the one account that works not have any spaces in it's username?

On 2017-07-05 at 7:49 PM, Explv said:

 

Do not do this.

 

Are there spaces in the usernames?
 

Okay so im fairly new to coding, been reading through both your, Apaec's guide aswell as many support questions here and been chewing through Head first java. I've been writing 5-6 fairly simple scripts, although been trying to make them more advanced each time. Even have your answer on the states vs task thread bookmarked, you seem to understand alot about Java, would you care to explain to a fairly new coder why this isn't the correct way/ most optimal? and what could be done instead?

  • Author
2 hours ago, Explv said:

 

Does the one account that works not have any spaces in it's username?

it does actually have spaces

 

do you know why

Player playersToTrade = getPlayers().closest("Account 1", "Account 2", "Account 3") 

wont work and will only trade account 1

Edited by vaynex

23 minutes ago, vaynex said:

it does actually have spaces

 

do you know why

Player playersToTrade = getPlayers().closest("Account 1", "Account 2", "Account 3") 

wont work and will only trade account 1

What do you mean only trade 1 account? It will always choose the closest of the three.

You need to be way more specific

Create an account or sign in to comment

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.