Guest Apogee Posted April 25, 2014 Share Posted April 25, 2014 I searched through all of the snippets and didn't find anything of interest.I need to know how to detect if a player is in the same area as me. Link to comment Share on other sites More sharing options...
Botre Posted April 25, 2014 Share Posted April 25, 2014 public int playerCounter(Area area) { int players = 0; for (Player p : this.client.getLocalPlayers()) { if (p != null && area.contains(p) && p != this.client.getMyPlayer()) { players++; } } return players; } Link to comment Share on other sites More sharing options...
NotoriousPP Posted April 25, 2014 Share Posted April 25, 2014 public int playerCounter(Area area) { int players = 0; for (Player p : this.client.getLocalPlayers()) { if (p != null && area.contains(p) && !p.equals(this.myPlayer())) { players++; } } return players; } Sorry I'm OCD about this. Use .equals() when comparing Object types, instead of != or == when not checking for null. With Integral types it's fine. Link to comment Share on other sites More sharing options...
Botre Posted April 25, 2014 Share Posted April 25, 2014 (edited) Sorry I'm OCD about this. Use .equals() when comparing Object types, instead of != or == when not checking for null. With Integral types it's fine. As in !p.equals(null) ? I never use .equals() for null checks Now I've got another thing to OCD about myself Edited April 25, 2014 by Botrepreneur Link to comment Share on other sites More sharing options...
NotoriousPP Posted April 25, 2014 Share Posted April 25, 2014 (edited) As in !p.equals(null) ? I never use .equals() for null checks Now I've got another thing to OCD about myself No I mean the opposite. It's okay to check for null and integral types(int, float, double, etc.) using == or !=. But when checking Object types use .equals(). Edited April 25, 2014 by NotoriousPP Link to comment Share on other sites More sharing options...
Pandemic Posted April 25, 2014 Share Posted April 25, 2014 (edited) No I mean the opposite. It's okay to check for null and integral types(int, float, double, etc.) using == or !=. But when checking Object types use .equals(). Change this: p != this.client.getMyPlayer() to !p.equals(client.getMyPlayer()) Edited April 25, 2014 by Pandemic Link to comment Share on other sites More sharing options...
FearMe Posted April 25, 2014 Share Posted April 25, 2014 A better way would be "client.getLocalPlayers().length/.size() > 1" though... Link to comment Share on other sites More sharing options...
Booch Posted April 25, 2014 Share Posted April 25, 2014 I generally use ==, != to compare primitive data-type, int, char, boolean etc. For Non-primitive/Objects - Use .equals() Link to comment Share on other sites More sharing options...
Joseph Posted April 25, 2014 Share Posted April 25, 2014 (edited) Not everything has to be in he snippet. Snippets are for more advance stuff. You could also check the issues sub-forum. Something someone might have the same question. And another person could answer for them. Here a link: http://osbot.org/forum/topic/46118-following-players/ That method give you a list of people in your area not including your self. You can simply do getPlayer(area).size > 0 Edited April 25, 2014 by josedpay Link to comment Share on other sites More sharing options...
Guest Apogee Posted April 25, 2014 Share Posted April 25, 2014 Issue is resolved. Thanks guys . Link to comment Share on other sites More sharing options...