GenericMeme46 13 Share Posted August 29, 2019 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 More sharing options...
Koschei 147 Share Posted August 30, 2019 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 More sharing options...
falloutr 20 Share Posted August 30, 2019 @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 More sharing options...
Koschei 147 Share Posted August 30, 2019 14 hours ago, Infidel said: Try not to hardcode when you don't need to. List<Player> interactingPlayers = getPlayers().all(player-> { return player.getInteractingCharacter().getName().equalsIgnoreCase(getLocalPlayer().getName()); }); Gotta null check Interacting character first Plus just check if the character != null and see if the character and local player are equal. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.