Get Nearest Player in Radius

Discussion in 'Plugin Development' started by AlexanderL123, Nov 22, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    AlexanderL123

    Hi Guys,
    Does anyone know how I can find the next player in a radius of 128 blocks?
    Because I want to change a Zombies Target to the nearest Player in a radius of 128 Blocks.
     
  2. Offline

    mcdorli

    Code:
    float distance = 128
    Player current = null
    foreach entity : Bukkit.getServer().getEntites()
        if (entity is a player)
            if (zombie.distance(entity) <= distance)
                 distance = zombie.distance(entity)
                 current = entity
            end of if statement
        end of if statement
    if (current not null)
         zombies.setTarget(current)
    
     
  3. Offline

    CraftCreeper6

    @mcdorli
    Wouldn't it also work with getNearbyEntities, checking, then casting to player?
     
  4. Offline

    AlexanderL123

    How does getNearbyEntities work?
     
  5. Offline

    mcdorli

  6. Offline

    CraftCreeper6

  7. Offline

    mcdorli

    Oh, I thought, that is the middle x, y and z coordinates, my bad.
     
  8. Offline

    CraftCreeper6

Thread Status:
Not open for further replies.

Share This Page