Setting a wolf hostile towards specific players.

Discussion in 'Plugin Development' started by CraterHater, Jul 2, 2015.

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

    CraterHater

    I want to make a wolf that is hostile towards all players except for the player that summoned him, I also want him to decay after 15 seconds. How do I do that?

    This is the summoning code:
    Code:
      @EventHandler
                                                                public void onPlayerUse10(PlayerInteractEvent event){
                                                                    Player p = event.getPlayer();         
                                                                    if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
                                                                        if(p.getItemInHand().getType() == Material.DIAMOND_SWORD){  
                                                                           int value2 = getConfig().getInt(p.getName() + ".Permission1");
                                                                            if(value2 == 2) {
                                                                            if (Cooldowns.tryCooldown(p, "x12", 12000)) {
                                                                                p.sendMessage("§b§2[Spells]:§rYou casted the werewolf Spell!");
                                                                                //Here that wolf has to spawn
                                                                                 p.playSound(p.getLocation(), Sound.NOTE_PLING, 5, 5);
                                                                           
                                                                               return;
                                                                            }else{
                                                                            p.sendMessage("§b§2[Spells]:§rYou have " + (Cooldowns.getCooldown(p, "x12") / 1000) + " seconds left!");
                                                                            p.playSound(p.getLocation(), Sound.NOTE_PLING, 3, 3);
                                                                            p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 100);
                                                                            return;
     
  2. @CraterHater I suggest checking out the Wolf interface for more info. There is a setAngry() and setTarget() method, though. To make the player that summoned him his owner, you can use setOwner().
     
  3. Offline

    _Error

    @CraterHater @CodePlaysMinecraft ain't sure at all if this will work but :
    Code:
    Wolf myentity = (Wolf) e.getPlayer().getWorld().spawnEntity(e.getPlayer().getLocation(), EntityType.WOLF);
    myentity.setAngry(true);
    EDIT: Set to solved if this works
     
  4. @_Error Yeah, that would work. The only thing missing would be to set the owner to the player spawning it.

    @CraterHater I'm not sure, but you could make a scheduler and after 3 seconds set the wolf's health to 0 or -1. That would probably be the best way to despawn it.
     
  5. Offline

    CraterHater

    No it doesn't work for me, the wolf spawns but isn't hostile
     
  6. Offline

    _Error

    I'm pretty sure you can
    Code:
    myentity.setOwner()

    Adding 1 more information,
    If you want to set the target you can use
    Code:
    myentity.setTarget()
    EDIT: @CraterHater Try setting the target and owner.
     
  7. Offline

    CraterHater

    @_Error Works thx Solved
    EDIT: still having some difficulties
     
    Last edited: Jul 2, 2015
  8. Offline

    _Error

    Np :)
     
  9. Offline

    CraterHater

    @_Error I still have some problems, this code does not make the wolf hostile towards nearby entities.
    Code:
    Wolf myentity = (Wolf) p.getWorld().spawnEntity(p.getLocation(), EntityType.WOLF);
    myentity.setAngry(true);
    myentity.setOwner(p);
    myentity.setCustomName("Summoned Werewolf");
    for(Entity x : p.getNearbyEntities(150, 10, 150))
    myentity.setTarget((LivingEntity) x);
    p.sendMessage("Should be done properly");
    It also doesn't display the message
     
  10. Offline

    dlange

    @CraterHater Debug some more (find out what line it stops at). I think that every time you do setTarget it CHANGES the target, not add one. So that would mean that your target would keep changing. Also, stacktrace?
     
  11. Offline

    CraterHater

    @dlange I added one message and here is everything: it does say 1 but not the other message:
    Code:
    @EventHandler
                                                                public void onPlayerUse10(PlayerInteractEvent event){
                                                                    Player p = event.getPlayer();         
                                                                    if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
                                                                        if(p.getItemInHand().getType() == Material.DIAMOND_SWORD){  
                                                                           int value2 = getConfig().getInt(p.getName() + ".Permission1");
                                                                            if(value2 == 2) {
                                                                            if (Cooldowns.tryCooldown(p, "x12", 28000)) {
                                                                                p.sendMessage("§b§2[Spells]:§rYou casted the werewolf Spell!");
    
                                                                               
    Wolf myentity = (Wolf) p.getWorld().spawnEntity(p.getLocation(), EntityType.WOLF);
    myentity.setAngry(true);
    myentity.setOwner(p);
    myentity.setCustomName("Summoned Werewolf");
    p.sendMessage("1");
    for(Entity x : p.getNearbyEntities(150, 10, 150))
    myentity.setTarget((LivingEntity) x);
    p.sendMessage("Should be done properly");
     
  12. Offline

    dlange

    @CraterHater Maybe just set it to angry, and its owner to the owner. IT should attack everyone but them?
     
  13. Offline

    _Error

    Can you set a wolf target for more than 1 person/mob? I ain't sure. Try what @dlange said, It might work.
    @CraterHater
     
  14. Offline

    dlange

    @_Error Don't believe that you can, as it always targets 1
     
  15. Offline

    _Error

    I think he might have to spawn it just as an angry wolf.
     
  16. Offline

    CraterHater

    @_Error @dlange I wan't it just to attack all entities except for the spawner but how...
     
  17. Offline

    _Error

    A dog will not attack it's owner, as @CodePlaysMinecraft said.
     
    CodePlaysMinecraft likes this.
Thread Status:
Not open for further replies.

Share This Page