Solved Force Entity Attack Entity

Discussion in 'Plugin Development' started by funkystudios, Dec 23, 2012.

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

    funkystudios

    I am looking for a reliable way to force an entity to attack another entity (zombie attack skeleton for instance). Entity.setTarget() has no effect on what a zombie does to my knowledge and that's all I have tried.

    Is there a way to do this?
     
  2. Offline

    ChrisixStudios

    The only way I can think of is to make it look like and entity attacks another.
     
  3. Offline

    fireblast709

    how about damaging a mob with .damage(int damage, otherEntity), where damage is 0 and otherEntity is, obviously, another mob. If that doesn't work, damage them with 1 and directly heal them with 1

    The AI should do the rest (I guess ;3)
     
  4. Offline

    funkystudios

    ChrisixStudios - yeah, not to elegant that way

    fireblast709 That's a good idea, let me try it and see if the Minecraft AI takes action after damage is dealt.

    No luck... The entity just gets damaged the and the other creature doesn't care.

    Oh, it appears to work if I .damage() both entities. Still looking for a more elegant solution (even though the damage is 0, the creature will still flash red with damage - not to pretty).

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

    drampelt

    I use RemoteEntities for easy entity manipulation. I'm fairly certain the DesireAttackNearest desire should work for what you want to accomplish.
     
  6. Offline

    funkystudios

    Wow! How did I not come across that.....?? Still not working for me though....

    Code:
    RemoteEntity entity = Stratus.getManager().createEntity(RemoteEntityType.Zombie, block.getLocation(), false);
    RemoteZombie rz = (RemoteZombie) entity;
    rz.attack(player);
    drampelt I figured using .attack() would work, but no. This should force the zombie to attack 'player'... correct?

    I'm not trying to attack a nearby entity, but rather any entity of my choice at any distance.
     
  7. Offline

    drampelt

    funkystudios I don't have much time right now to test it out (I might be able to tomorrow), but try something like this:
    Code:
    RemoteEntity entity = Stratus.getManager().createEntity(RemoteEntityType.Zombie, block.getLocation(), false);
    entity.getMind().addActionDesire(new DesireAttackNearest(entity, Zombie.class, 10, 1), 1);
    
    I'm not quite sure what all the parameters for DesireAttackNearest are, but replace Zombie.class with the class of the entity you want the spawned zombie to attack. If you are going to have multiple desires (for example more than one entity to attack), you would want to change the priority accordingly.

    All of the desires can be found here (in the de.kumpleblase2.remoteentities.api.thinking.goals package).
     
  8. Offline

    funkystudios

    I'm posting the same stuff on both threads, but oh well?

    drampelt I'm not trying to get the mob to attack a close entity... I want it to attack a specified entity of my choice with .attack() like so... (but this code is not functional)

    Code:
    RemoteZombie entity = (RemoteZombie) Stratus.getManager().createEntity(RemoteEntityType.Zombie, block.getLocation(), false);
    entity.getMind().addActionDesire(new DesireAttackTarget(entity, 48F, false, false), 50); // Which one do I use? Movement or action?
    entity.getMind().addMovementDesire(new DesireAttackTarget(entity, 48F, false, false), 50);
    entity.attack((LivingEntity) getGamer().getPlayer());
     
  9. Offline

    drampelt

    Ah I think I understand what you want now. What you may want to try is make your own desire that extends DesireBase and copy but modify the DesireAttackTarget code to take a LivingEntity as a parameter. The code that you have there should work (I think?) but asking the author would be the best idea (which you did :)). Good luck getting this working, and if you do I would love to know how you managed to do it.
     
  10. Offline

    funkystudios

    drampelt Thanks for your help! I have managed to target an entity using...
    Code:
    EntityCreature ec = getHandle();
    ec.b(LivingEntity...);
     
  11. Offline

    drampelt

    Glad I could help and I'm happy you got it working :)
     
  12. Offline

    suckycomedian

    anyone know what Stratus would be? I can't figure out what to put before getManager()
     
  13. Offline

    funkystudios

    suckycomedian Stratus is the name of my plugin. I made a function like so...
    Code:java
    1. EntityManager manager = RemoteEntities.createManager(this);
    2. public static EntityManager getManager() {
    3. return manager;
    4. }
    And called it in a different class.
     
  14. Offline

    suckycomedian

    Thank you :)
     
  15. Offline

    procnole

    I cant seem to get this working :/
     
Thread Status:
Not open for further replies.

Share This Page