Jump to content

How can i detect if players are nearby?


Recommended Posts

Guest Apogee
Posted

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.

Posted

 

smile.png

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.

Posted (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 mellow.png

Now I've got another thing to OCD about myself ph34r.png

Edited by Botrepreneur
Posted (edited)

As in !p.equals(null) ?

I never use .equals() for null checks mellow.png

Now I've got another thing to OCD about myself ph34r.png

 

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 by NotoriousPP
Posted (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 by josedpay
Guest Apogee
Posted

Issue is resolved. Thanks guys :).

 

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...