Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Looping over my friends list


    boogzey

    Recommended Posts

    How can I loop over my friends list and check if a friend is online? Or rather, how can I enumerate the number of online friends I have at a particular time? I've instantiated friend like so:

     

    final Friend onlineFriends = new Friend(Client.getClient(), true);

     

    Let's say I have a list of players, p. I loop over my list of players and add them to my friends list. After that, how can I check which of them are online?

     

    Here's what I'm currently using to add them.

     

    for (String p: users) {
        log("Attempting to add (" + p + ") "+ " to list ");
        sleepUntil(() ->  friend.addFriend(p), 10000);
        if(friend.haveFriend(p)){
            log("Successfully added: " + p);
        }
    Link to comment
    Share on other sites

    You don't have to instantiate Friend.  To add a player to your friends list just use:

    getFriends().addFriend(Player);

    Verify they are added with:

    getFriends().haveFriend(playerName);

    And to check if they are online...

    for(Friend f : getFriends().getFriends()) {
    	if(f.isOnline()) {
    		//friend is online
    	}
    }

     

    Link to comment
    Share on other sites

    24 minutes ago, Milasoft said:

    You don't have to instantiate Friend.  To add a player to your friends list just use:

    
    getFriends().addFriend(Player);

    Verify they are added with:

    
    getFriends().haveFriend(playerName);

    And to check if they are online...

    
    for(Friend f : getFriends().getFriends()) {
    	if(f.isOnline()) {
    		//friend is online
    	}
    }

     

    Perfect, thank you!

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.