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
  • AddFriend() method doesn't work properly


    zanko360

    Recommended Posts

    Greetings,

    The AddFriend() method of

    org.dreambot.api.methods.friend

    package doesn't work properly. When put in loop the loop sometimes continues without actually clicking on "Add Friend" an types the name in chat instead. Without delays and if statements it doesn't work. Sometimes the method executes without typing anything at all. With delay of 200milisecond and checking with Friends.haveFriend() it works.

    Don't know if this is intended or a bug just thought I might point this out

    Link to comment
    Share on other sites

    I'm not entirely sure what you're reporting. Could you give me the code you're using? You're talking about loops and then also delays, is it just the regular method that doesn't work? It's possible that it's lag that is effecting the method.

    Link to comment
    Share on other sites

    The method AddFriend(String playerName), of the class Friends. When called in a loop, ie. To iterate bunch of names got from surroundings, and then put in as argument in AddFriend(), works terrible. The method gets called, sometimes it executes as it should (it clicks on "Add Player" THEN types the name), sometimes or alot of the time it just one call gets executed correctly like this the other one ( because it is in loop) gets called "prematurely??" and doesn't click the "Add Player" instead it types the name in chat. Without big delays it could not figure out a way to implement it like this even with all sorts of if() while(true). Any ideas how I could get around this? Thank you in advance

    Link to comment
    Share on other sites

    2 hours ago, zanko360 said:

    The method AddFriend(String playerName), of the class Friends. When called in a loop, ie. To iterate bunch of names got from surroundings, and then put in as argument in AddFriend(), works terrible. The method gets called, sometimes it executes as it should (it clicks on "Add Player" THEN types the name), sometimes or alot of the time it just one call gets executed correctly like this the other one ( because it is in loop) gets called "prematurely??" and doesn't click the "Add Player" instead it types the name in chat. Without big delays it could not figure out a way to implement it like this even with all sorts of if() while(true). Any ideas how I could get around this? Thank you in advance

    Use something like this,

     

    List<Player> playerNames = getPlayers().all(p -> Objects.nonNull(p) && p.distance(getLocalPlayer()) <= 10);
            
            playerNames.forEach(p -> {
                if (getFriends().addFriend(p.getName())) {
                    sleepUntil(() -> Arrays.asList(getFriends().getFriends()).contains(p.getName()), 10000);
                }
            });

     

    Link to comment
    Share on other sites

    Ty 780. I got around it with:

    while(!Friends.haveFriend(list<Player>.get(iterator).getName())) {
                        	if(Widgets.getWidget(162).getChild(45).getText().equals("*") &&     										Widgets.getWidget(162).getChild(45).isVisible()){
                        		Friends.addFriend(list<Player>.get(iterator));
                        	}
                        	sleep(100);              	
                        }

    after the first attemp/call

    Link to comment
    Share on other sites

    while(!Friends.haveFriend(list<Player>.get(iterator).getName())) {
                            if(Widgets.getWidget(162).getChild(45).getText().equals("*")
                            && Widgets.getWidget(162).getChild(45).isVisible()){
                                Friends.addFriend(list<Player>.get(iterator));
                            }
                            sleep(100);                  
                        }
    Link to comment
    Share on other sites

    The add friend method as it is currently written wasn't going to consistently go through every action required to add a friend. This will be changed in the next release, along with adding a few sleeps of its own. You will still need to check if(addFriend()) to see if it successfully finishes (which will only return true when the friend is in your list)

    Link to comment
    Share on other sites

    Also deleteFriend() does the same thing. It would be dope to have deleteFriend() right click version so if you had a small friend's list you could chose a deleteFriend(Friend friend, boolean rightclick) something like that. I think it is more natural for a human to rightclick the name instead of typing it down if the friend's list is small

     

    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.