Jump to content

Interacting with an array of strings instead of a string


vaynex

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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