Firing arrows like a dispenser using world.arrowSpawn?

Discussion in 'Plugin Development' started by Taco, Mar 6, 2011.

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

    Taco

    I'm trying to make arrows fire at a player until they're dead, but my problem is they only spawn and fall to the ground until I stop spawning them. I've tried loops and recursive calls to make this work, but I can't figure it out. Any help?

    Here's my current code:

    Code:
     public void arrowSlay(Location arrows, World world, int x, Player player)
        {
            try
            {
                arrows = new Location(world, player.getLocation().getX()+x, player.getLocation().getY()+1, player.getLocation().getZ()+x);
                world.spawnArrow(arrows, new Vector(5, 1, 5), 1.2f, 4.0f);
                Thread.sleep(200);
                if(player.getHealth() > 0)
                    arrowSlay(arrows, world, x, player);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    I've also tried something like this:

    Code:
    while(player.getHealth() > 0)
        {
            try
            {
                arrows = new Location(world, player.getLocation().getX()+x, player.getLocation().getY()+1, player.getLocation().getZ()+x);
                world.spawnArrow(arrows, new Vector(5, 1, 5), 1.2f, 4.0f);
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    Edit: I realized the code here is a bit flawed, I fixed it in my source, but I was using this on myself so it didn't matter for my problem.
    --- merged: Mar 7, 2011 11:10 PM ---
    Le bump?
     
  2. Offline

    NathanWolf

    Hi!

    I've done this in Spells, so I know it's possible- however, I've since replaced that code withe fireArrow, so I/you would have to go digging in github history to see it, unless I left it commented out.

    Anyway, I remember this was very tricky to get right- in fact, I believe there was an extra second step that was required to actually assign a direction and velocity to the arrow.

    I'll try and dig up that source code and come back.... I was going to link, but I moved code around for Maven, so the history is a bit hard to follow :p
     
Thread Status:
Not open for further replies.

Share This Page