[SOLVED] Spawn Aggressive Dogs

Discussion in 'Plugin Development' started by X0R0N, Jul 18, 2012.

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

    X0R0N

    Hi guys,
    In the plugin i am coding right now i try to spawn dogs which are aggresive on players.
    my problem is that i set them to angry and set the player as target, but they still dont attack him.
    Please take a look at my code:


    Code:
    Wolf e = (Wolf)c.GetPlayer().getWorld().spawnCreature(loc, CreatureType.WOLF);
    e.setAngry(true);
    e.setTarget((LivingEntity)c.GetPlayer());

    c.GetPlayer() returns the Player Object of the Player i try to attack with dogs.
    The dogs spawn next to him, but they still stay friendly.

    kind regards,
    X0R0N
     
  2. Offline

    X0R0N

    cmon guys there must be a solution for my problem! Or is it a bukkit bug?
     
  3. Offline

    lx3krypticx

    No it's possible. I've seen it happen. Sorry this wasn't helpful. I hope you find your answer.
     
  4. your not right, if you have commandbook, you can do /spawnmob wolf:angry and yo get angry wolves, I am almost sure I saw commandbook code on github, so maybe X0R0N may able to find the code and look it up
     
    ZeusAllMighty11 likes this.
  5. Offline

    ZeusAllMighty11

    if (!specialType.equals("")) {
    if (creature instanceof Wolf) {
    if (specialType.matches("angry")) {
    ((Wolf) creature).setAngry(true);
    return creature;
    } else if (specialType.matches("sit(ting)?")) {
    ((Wolf) creature).setSitting(true);
    return creature;
    } else if (specialType.matches("tame(d)?") && sender instanceof Player) {
    ((Wolf) creature).setOwner(((Player) sender));
    return creature;
    }

    source from commandbook
     
  6. Offline

    X0R0N

    Doesnt really help sry. As you can see i already set him to angry
     
  7. Offline

    ZeusAllMighty11

    Set the owner of the dog as the player using the command to make the dog mad, make the dog mad, and all players around him are set to the enemies. Not that difficult
     
  8. Offline

    X0R0N

    The problem is that the Server spawns the dogs automatically. Its a part of an automated PVE system. There is no player typing a command.
     
  9. Offline

    r0306

    X0R0N
    I believe that you have to spawn the wolf first then schedule a delayed task to set the anger and target.
     
  10. Offline

    ZeusAllMighty11

    Setup a scheduler if you want it to be natural. Otherwise, do it via boolean onCommand(blah blah){
    //code
    }
     
  11. Offline

    X0R0N

    No works!
    I did it via delayed task
    Code:
    xxxx.getServer().getScheduler().scheduleSyncDelayedTask(xxxx, new SetAngry(c.GetPlayer(),ls),10);
    ls is a list with the wolves. Heres the code of my task:

    Code:
    public class SetAngry implements Runnable {
        private Player pl;
        private List<Wolf> li;
        SetAngry(Player p, List<Wolf> ls) {
            pl=p;
            li=ls;
        }
       
        public void run() {
            for(Wolf e: li) {
                e.setAngry(true);
                e.setTarget(pl);
            }
        }
    }
    The wolves have red eyes but still dont attack the player as always.
     
  12. Offline

    r0306

    X0R0N
    I think this is a bug with the current build. I tested it out on my server and confirmed that it's not working but by adding this line, it updates the wolves so that they start attacking:

    Code:
    Wolf e = (Wolf)c.getPlayer().getWorld().spawn(c.getPlayer().getLocation(), Wolf.class);
    e.setAngry(true);
    e.setTarget((LivingEntity)c.getPlayer());
    e.damage(0, c.getPlayer());
     
  13. Offline

    X0R0N

    Thank you this is working for me =)
    Problem solved!
     
Thread Status:
Not open for further replies.

Share This Page