Solved Save, delete, then respawn mobs within an area.

Discussion in 'Plugin Development' started by xYourFreindx, Aug 4, 2014.

Thread Status:
Not open for further replies.
  1. I've been trying to find a way to make it so that when players using my plugin vanish... The mobs that are tracking them, stop tracking.
    That way players can't safely lead mobs around the map in vanish mode.

    I couldn't find a way to do this... So I tried just switching the player's game mode to creative real quick, then switching it back to survival. But that spams the player with "your game mode has been changed" which is totally unprofessional, and not to be included in my plugin. Unfortunately, the "Your game mode has been changed" Appears to be client side, and can't be canceled.

    I may be over thinking and missed something obvious....
    BUT
    The most logical solution, to me, seems to be that I should get all the mobs that are around a player, save their health, their position, their effects, and if I can, their armor... And respawn them instantly in that exact spot.
    Since it would be a new mob, it would no longer be tracking that player.

    I have no idea how I would do this, or if it's even possible.

    I'm going to need some help with this,
    if I can't figure it out.... I guess the next best thing is to give all mobs around the player a huge slowness potion until the player unvanishes. But that would be the last resort, as the mob would still be tracking the player, and if a new player were to come along, the mob would be unable to move.
     
  2. Offline

    artish1

    xYourFreindx
    or you can player.getNearbyEntities(), loop through them, check if they are EntityMonster/EntityCreature (I am NOT SURE about this, these might be NMS classes so you might want to change them to Bukkit (if possible)), if so, cast to EntityMonster/EntityCreature, and then setTarget(null);

    But this is just my first thought on how to do this.
     
  3. Offline

    _LB

    artish1 That means that the mobs will never be able to track any players if there is a vanished player nearby.
     
  4. artish1 FUDGE That's a great idea!! Thank you! I wonder if it works...
    Do you know if EntityMonster and EntityCreature are the only aggressive mob type entities?
     
  5. Offline

    _LB

    xYourFreindx I have yet to encounter an aggressive painting.
     
  6. Offline

    artish1

    xYourFreindx
    I'm pretty sure EntitySkeleton, EntityZombie, and any other of those types of aggressive mobs extends EntityMonster, and EntityMonster, and for the passive types of mobs, its EntityAnimal (i think). Both EntityMonster and EntityAnimal extends EntityCreature (which has the setTarget() method)

    You can always look more deep into the NMS, but so far the setTarget() method goes as far back until it reaches the EntityCreature class, which is here. So you can check if its EntityCreature instead of doing those i think?

    EDIT: so i hope that gives you an idea on how the NMS Entity "tree" looks like when it comes to the AI mobs.

    EDIT #2: Also i forgot to tell you that the setTarget() method for the passive mobs, it just makes the passive mobs follow the target(or player if you want to be specific), kind of like a pet.
     
  7. _LB
    Why would it prevent any mob from tracking players if a vanished player is nearby?

    How I pictured it working, is that when the player uses the vanish command, it gets all the nearby monsters, and set's their target to null.
    Would that then make their target null permanently. Because I would have assumed that they would target again once a targetable player gets nearby again.
    To be clear, the command would null the targets, not the presence of the vanished player. (as far as I understand)
     
  8. Offline

    _LB

    xYourFreindx Because you need to check if the target is the vanished player first. If you just blindly null the target they will never track any player.
     
  9. _LB
    When the player sends the command. Then there is a 100% probably that that player is vanished. So I null the target of all the mobs around THAT player. The loop will only go through once, so once all the mobs around THAT player (that just vanished) will have forgotten any target they have. Now that the player is vanished, the mobs cannot track that player. So they cannot retarget the player.

    If I get it working, I'll send tag you, and send a clipping of how I managed it.
     
  10. Offline

    _LB

    xYourFreindx You are not considering the possibility of them vanishing next to another player and the mobs are tracking that player instead.
     
  11. _LB I have considered that.

    All the players who are vanished are also added to an array list, I'll try and check the mobs to see if the player they're targeting is on that list before I null them. It sounds like it should work, but I haven't tested it yet. If it doesn't, then having the mobs retarget the other player isn't the worst thing in the world. But I think it will.
    Thanks for pointing out flaws though. I hate flaws.
     
  12. Offline

    artish1

    _LB
    xYourFreindx

    Heres a solution:
    before setting it to null (more on this later), check if the target is a player, and if the players UUID/Name, is equal to that of the player who vanished. Now if there is a player NEARBY the player who vanished, you can always use the idea i first posted in this thread, "getNearbyEntities()", check if the entity is a player, and check if that player is NOT the vanished player, if all is CHECKED, then set the target to the nearby player

    EDIT: I just found that there is a method called findTarget(), in EntityCreature.
    It can be of some use.
     
    xYourFreindx likes this.
  13. artish1
    _LB
    Just want you guys to know, that it was successful.
    You've no idea how happy I am.
    If anyone is interested in seeing the final result... ​
    Here you go:​
    Code:java
    1.  
    2. for(Entity mob : ((Player)sender).getNearbyEntities(36, 36, 36)) {
    3. if(mob.getType().equals(EntityType.BLAZE) || mob.getType().equals( EntityType.CAVE_SPIDER )|| mob.getType().equals( EntityType.CREEPER) || mob.getType().equals( EntityType.ENDERMAN )|| mob.getType().equals( EntityType.GIANT) || mob.getType().equals( EntityType.IRON_GOLEM )|| mob.getType().equals( EntityType.PIG_ZOMBIE )|| mob.getType().equals( EntityType.PLAYER )|| mob.getType().equals( EntityType.SILVERFISH) || mob.getType().equals( EntityType.SKELETON) || mob.getType().equals( EntityType.SPIDER )|| mob.getType().equals( EntityType.WITCH )|| mob.getType().equals( EntityType.WITHER) || mob.getType().equals( EntityType.ZOMBIE) || mob.getType().equals( EntityType.WOLF)){
    4. if(mob.getType().equals(EntityType.PLAYER)){
    5. //* Potential Stuff Here*//
    6. }else{
    7. Creature mobs = (Creature) mob;
    8. if(mobs.getTarget() != null && mobs.getTarget().equals((LivingEntity)sender)){
    9. mobs.setTarget(null);
    10. main.enderman.put(((Player) sender).getUniqueId(), mob);
    11. }
    12. }
    13. }
    14. }


    The enderman part is so I can reset the target when the player exits vanish.
    (A work in progress)

    Thank you all for your help. ​
     
Thread Status:
Not open for further replies.

Share This Page