Contain an Entity (Mob)

Discussion in 'Plugin Development' started by 97WaterPolo, Aug 19, 2014.

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

    97WaterPolo

    Hello!

    So my problem is.....

    I have a mob that attacks players and summons mobs to attack nearby players. The only problem is, some players got the bright idea to lure the boss to an enemy base, and summon all the minions near the enemy base thus having the boss and the minions attack the enemy.

    I was thinking of trying to have it so that the boss and the minions can not leave a defined region, and when it got to the end of the region, the boss and minions would stop targeting the players and head back to the center of the region,until the boss is agroed again by a player within the region.

    I know the effects of keeping track of all entities moving around on the server, and I was hoping someone from the Bukkit community could help point me in the right direction.

    Tl;Dr: I don't want my boss to leave a certain region, when the player leaves the region, the boss becomes un-agressive and teleports/walks back to the center of the region.
     
  2. Offline

    xTrollxDudex

    What have you tried so far
     
  3. Offline

    97WaterPolo

    xTrollxDudex
    Well I tried creating a circular region from the entity's spawn location, and tried checking to see if the entity is within the location on damage event, if not teleport him back to the spawn location. All this really did was have the boss be teleported randomly as he didn't seem to unagro, and the minions (zombies) didn't seem to follow suit.

    I honestly don't have a huge clue on how I should even approach this problem, should I have a repeating task that check's the boss's location, add a resource that does have the EntityMoveEvent, or try again with creating a small region.
     
  4. Offline

    xTrollxDudex

    NMS possibly? If you don't want to, I reccommend a repeating task.
     
  5. Offline

    97WaterPolo

  6. Offline

    Yekllurt

    97WaterPolo likes this.
  7. Offline

    97WaterPolo

    Yekllurt
    Would there be a better way to check if the entity is inside a region besides looping threw all locations within the cuboid region and seeing if the entity is near it?
     
  8. Offline

    Yekllurt

    Here is a method i found for cheking the distance between 2 points if you want to online check the distance between x & z put the y value in both location's to 0. Here you can loop threw all the Mobs where you have in your Hashmap, yml, etc. check if the distance is bigger then for example 50 you can teleport the entity to a random location in the circle .
    Or you spawn a custom entity and motify the pathfinder

    Code:java
    1. public static double distanceBetweenLocations(Location loc, Location target){
    2. int x1 = loc.getBlockX();
    3. int x2 = target.getBlockX();
    4. int y1 = loc.getBlockY();
    5. int y2 = target.getBlockY();
    6. int z1 = loc.getBlockZ();
    7. int z2 = target.getBlockZ();
    8. float vxs = x1 - x2;
    9. float vys = y1 - y2;
    10. float vzs = z1 - z2;
    11. float vxm = vxs * vxs;
    12. float vym = vys * vys;
    13. float vzm = vzs * vzs;
    14. float vtotal = vxm + vym + vzm;
    15. double vsq = Math.sqrt(vtotal);
    16. int i = (int)vsq;
    17. return i;
    18. }
     
  9. Offline

    97WaterPolo

    Yekllurt
    Thank you very much! :)

    Yekllurt
    Wait, doesn't?

    location1.distance(location2); do roughly the same thing? Or am I missing something?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  10. Offline

    xTrollxDudex

    Yes, pretty much. By the way, for performance reasons, use distanceSquared and square your distance check value
     
    97WaterPolo likes this.
Thread Status:
Not open for further replies.

Share This Page