Jump to content

Interacting with an array of strings instead of a string


Recommended Posts

Posted (edited)

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
Posted (edited)

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
Posted (edited)
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
  • Like 1
Posted
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

Posted (edited)
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
Posted
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?

Posted
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?

Posted (edited)
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
Posted
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

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...