How to shot an arrow out of a block?

Discussion in 'Plugin Development' started by Etarus, Sep 30, 2011.

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

    Etarus

    I want to fire an arrow out of a block if a player is in a specific range out of the block.
    The block should fire an arrow with intervals and every time focus the player wich is in range.

    Can someone maybe help me?
    Thanks for all help.
     
  2. Offline

    Butkicker12

    Code:
    public void onBlockPlace(BlockPlaceEvent event){
    Player p = event.getPlayer();
    if(event.getBlockPlaced().getType()== Material.WHATEVERYOUWANT){
    p.shootArrow();
    Idk if it works. I know the p.shootArrow will.
     
  3. that fires the arrow from the player...
     
  4. Offline

    Butkicker12

    Oh Hmm ok then I guess it should be
    b.shootArrow();
    Dont know if that will work.
     
  5. Offline

    K900

    You probably can't. You can trigger a dispenser from code, but shooting arrows is not what blocks do often :)
     
  6. Well, he could spawn an arrow in front of the block and set pitch, yaw, velocity and so on. But that's complicated...
     
  7. Offline

    Etarus

    Yeah I know that this is complicated but I will try it :)

    This is a bit source out of the Plugin: ArrowWall (maybe outdated?)
    https://github.com/overlordnyaldee/...hinecorporation/ArrowWall/ArrowWallUtils.java

    I think I can copy past, try and try again if it works, but it would be very nice if anyone can tell me if this is a correct way or sth like this.

    Mor on arrow shooting... i don't understand it all
    http://jd.bukkit.org/apidocs/org/bu...cation, org.bukkit.util.Vector, float, float)
     
  8. Offline

    Baummann

    @Etarus
    Why don't you place a dispenser, shoot an arrow and remove the dispenser again?
     
  9. Offline

    Etarus

    Can this shot an arrow 360° ??
    I don't think so. Or I'm wrong?

    I don't want to shoot the arrow every time in one direction.
     
  10. Don't think you can use that :)
     
  11. Offline

    Etarus

    Any idea what i could use instead of?
     
  12. Look at the craftbukkit code for player.shootArrow()
     
    Butkicker12 likes this.
  13. Offline

    Etarus

    i don't want to shot an arrow out of a player.
    i want to shot it out of coordinations with target any player in a specific range.
     
  14. I know, thats why I'm saying look at how to shoot a area and replicate it.
     
  15. Offline

    Shamebot

    Spawn an arrow (world.spawnArrow(..)). Subtract the player location from the block location/arrow spawn location, have a look at the Location.getDirection() code for how to convert a vector to yaw/pitch.
     
  16. Offline

    Diogyn

    Hi, I need it too. For the moment I changed my plan to do so with dispensers. It work fine but just in 4 directions.... But tell me if you manage it ;)
    Good luck
     
  17. Offline

    Tezlastorme

    How do you trigger a dispenser using code? I'm trying to get a dispenser to be fired once and then keep firing rapidly like a machine gun either forever or until it runs out of arrows.
     
  18. Offline

    Tezlastorme

  19. Offline

    ItsHarry

    Just spawn an arrow and apply velocity to it
     
  20. Offline

    Tezlastorme

    Meh, idk how to set the velocity so it fires forwards. :eek:
     
  21. He wanted to shoot it out of the dispenser, so no need to go that complicated. dispenser.dispense() is all he needs (and if he wants it to fire rapidly use a syncRepeatingTask to fire it every X ticks... also checking the dispensers inventory and stop the task when it's empty would be a good thing). But as he didn't ask any more questions I think he still got it working. ;)
     
  22. Offline

    ItsHarry

    I'm pretty sure he wants to shoot it out of a block, not a dispenser.
     
  23.  
  24. Offline

    Tezlastorme

    A dispenser is a block is it not? ;) But yeah, I want to fire it out of a dispenser in this case. Anway I'm getting errors still :/ I'm using ProjectileLaunchEvent so when the dispenser fires one arrow it fires again and again but I'm getting an error when it gets to the dispenser.dispense() bit. Here is some of my code:
    Code:
    @EventHandler(priority = EventPriority.NORMAL)
        public void onProjectileLaunch(ProjectileLaunchEvent event){
            if(event.getEntityType() == EntityType.ARROW){
                Arrow arrow = (Arrow) event.getEntity();
                if (!(arrow.getShooter() instanceof LivingEntity)){
                    Dispenser dispenser = (Dispenser) arrow.getShooter();
                    if(aa.autoDispensers.containsKey(arrow.getShooter())){
                        if(aa.autoDispensers.get(arrow.getShooter())){
                            dispenser.dispense();
                        }
                    }
                    if(aa.autodispensers){
                        dispenser.dispense();
                    }
     
  25. I'm not sure if you can do that, but I'll have to look into bukkit code to get sure. Before I do that: What's the error you're getting?
     
  26. Offline

    Tezlastorme

    In the console window:
    Code:
    [SEVERE] Could not pass ProjectileLaunchEvent to AutoArrows
     
  27. That looks like the start of a stacktrace, where's the rest of it? Also we need to know which lines are the ones noted in that stacktrace...
     
  28. Offline

    ItsHarry

    K well he was not clear, in the OP he didn't state anything about a dispenser and I thought his question about dispensers was about something else..

    Yes a dispenser is a block, but I meant any block like dirt or grass etc, you know what I mean :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  29. Offline

    Iron_Crystal

    The OP and the guy wanting to shoot out of dispencers are two different people...

    The op, etarus, wanted to shoot out of any block.

    Tezlastorme wanted to shoot out of dispencers
     
Thread Status:
Not open for further replies.

Share This Page