Compass Points to Nearest Player

Discussion in 'Plugin Development' started by chasechocolate, Sep 20, 2012.

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

    chasechocolate

    I need some code that will automatically point the player's compass to the nearest player. I also want it to send them a message saying "You're compass is now pointing at <player>!" Thanks!
     
  2. Offline

    iZanax

    PHP:
    Player[] targetplayersBukkit.getOnlinePlayers();
     
    int a Integer.MAX_VALUE;
    int b 0;
    Player targetplayer null;
     
    // For Loop of the targetplayers length
    for(?;?;?){ // the ? is your task
    targetplayers[i].getLocation().distance(player.getLocation());
     
    if(
    a){
    b;
    targetplayer targetplayers[i];
    }
    }
     
    player.setCompassTarget(targetplayer.getLocation());
    * player = the player u want to have the modified compass

    Not sure if im right, just wrote it in here :p
    Good luck.
     
  3. Offline

    stelar7

    you need to change b=a to a=b
     
  4. Offline

    iZanax

    stelar7 Thanks, i edited it. I've missed it : )
     
Thread Status:
Not open for further replies.

Share This Page