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
  • Pull player from character?


    GenericMeme46

    Recommended Posts

    Atm I'm needing to pull a player object from a character, and the only way I know of getting said object is to cycle through all the players and seeing if their name matches the character name. Is there a better way to pull character from player?

    Link to comment
    Share on other sites

    Just a guess you're trying to see if a player is interacting with you or something along those lines, pretty much all you would do is check if it's an instance of the Player class, then cast it. 

    	Character character = getLocalPlayer().getCharacterInteractingWithMe();
            if (character instanceof Player) {
                Player player = (Player) character;
            }

     

    2 hours ago, GenericMeme46 said:

    Atm I'm needing to pull a player object from a character, and the only way I know of getting said object is to cycle through all the players and seeing if their name matches the character name. Is there a better way to pull character from player?

     

    Link to comment
    Share on other sites

    @Koschei, thats exactly it. The issue was needing to get the composite of the player who is attacking.

    In chat we settled on:

    List<Player> attackingPlayers = getPlayers().all(player->{ return player.getInteractingCharacter().getName() == "MyUserName"; });


    your way would work but if in multi-combat might miss potential threats.

    Link to comment
    Share on other sites

    14 hours ago, Infidel said:

    Try not to hardcode when you don't need to. <3

    
    List<Player> interactingPlayers = getPlayers().all(player-> { 
        return player.getInteractingCharacter().getName().equalsIgnoreCase(getLocalPlayer().getName()); 
    });

    Gotta null check Interacting character first :P

    Plus just check if the character != null and see if the character and local player are equal. 

    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.