Launch a arrow to a player

Discussion in 'Plugin Development' started by ArthurHoeke, Jan 26, 2014.

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

    ArthurHoeke

    Hello
    I got a question, How to make that you got a emerald block and if a player is in a range of 5 blocks that there will be an arrow shooted to the player, How to make that?

    Thanks
     
  2. Offline

    jimuskin

    ArthurHoeke You check if the player is 5 blocks within the range of an emerald block and then you spawn in an arrow.
     
  3. Offline

    ArthurHoeke

    jimuskin Yes but how to make this? With wich event etc?
     
  4. Offline

    bubba1234119

    One way would be using the player move event and checking the x, y and z and see if any of those come within 5 of the player.
     
  5. Offline

    Maurdekye

    You use a PlayerMoveEvent, and you check all around the player for an emerald block. If it finds one, then it shoots an arrow at the player from the block.
     
  6. Offline

    ArthurHoeke

    bubba1234119 Maurdekye Okay thx, Whats the code to check the cords of a player? something like p.getCordinats or something?
     
  7. Offline

    GriffinPvP

    The method p.getLocation() returns the player's location.
     
  8. Offline

    Cammeritz

    Code:java
    1. Entity en = event.getEntity()
    2. Location location = en.getLocation();
    3. double radius = 5D;
    4. List<Entity> near = location.getWorld().getEntities();
    5. for(Entity e : near) {
    6. if(e.getLocation().distance(location) <= radius)
    7. if(e instanceof Player){
    8. Player pl = (Player) e;
    9. Block b = xxx
    10. b.doSomething();
    11. } else {
    12. return;
    13. }
    14. }
     
  9. Offline

    ArthurHoeke

    Cammeritz what i have to put on block b = xxx?
    The cords or something? And how ?
     
  10. Offline

    Cammeritz

    You can (for example) save the coords of the block in the config.yml or with an command, which saves the coords in the config.
     
  11. Offline

    jimuskin


    We are not here to provide the code for you, we are here to help you. For the Block b = xxx, like Cammeritz has said, save the coords into a config and retrieve the block at those set coords. OR if you are using an emerald block, save the coords when the block is placed. Then, launch an arrow from the block's location targetting the player.
     
  12. Offline

    Cammeritz

Thread Status:
Not open for further replies.

Share This Page