How to remove npc?

Discussion in 'Plugin Development' started by W&L-Craft, Apr 17, 2014.

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

    W&L-Craft

    Hello,

    i am sorry to ask this but i am making a plugin that has npc's in it and i have a problem.

    here is a small part of my plugin that i can't figure out:
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("ktz")){
    2. if(args.length == 1){
    3. if (args[0].equalsIgnoreCase("play")){
    4. p.sendMessage(ChatColor.GOLD + "You have spawned a zombie, have fun!");
    5. p.sendMessage(ChatColor.GOLD + "For a list of weapons, use /ktz weaponlist");
    6. npc.spawn(spawn);
    7. npc.setProtected(false);
    8. }
    9.  
    10. if (args[0].equalsIgnoreCase("stop")){
    11. npc.destroy();
    12. //i have also tried npc.despawn()


    The idea is very simple when you do /ktz play a npc will spawn at your location
    and when you do /ktz stop the npc will be removed.

    But for some reason the npc doesn't despawn or gets removed. i have also tried npc.despawn() but that didnt work either

    Can someone help me with this

    Sorry for my english
     
  2. Offline

    Trevor1134

    W&L-Craft Since you are doing multiple 'ifs' you need to add 'return true;' at the end of each if block.

    Code:
    if(args[0].equalsIgnoreCase("test")){
    p.sendMessage("hi");
    return true;
    }
     
    next if...
     
    W&L-Craft likes this.
  3. Offline

    W&L-Craft

    Trevor1134

    Lol, i can not believe that i forgot that, thanks alot
     
  4. Offline

    Trevor1134

    W&L-Craft Let me know if it fixes it! :) And if it does, make sure to mark this thread as solved :)
     
  5. Offline

    W&L-Craft


    It is not fixed yet, the npc does not despawn or do anything else
     
  6. Offline

    Trevor1134

    W&L-Craft Update your code on your first post, please?
     
  7. Offline

    W&L-Craft

    Trevor1134

    Here you go :)

    Code:java
    1.  
    2. if (cmd.getName().equalsIgnoreCase("ktz")){
    3. if(args.length == 1){
    4. if (args[0].equalsIgnoreCase("play")){
    5. p.sendMessage(ChatColor.GOLD + "You have spawned a zombie, have fun!");
    6. p.sendMessage(ChatColor.GOLD + "For a list of weapons, use /ktz weaponlist");
    7. npc.spawn(spawn);
    8. npc.setProtected(false);
    9. return true;
    10. }
    11.  
    12. if (args[0].equalsIgnoreCase("stop")){
    13. npc.destroy();
    14. // npc.despawn() didn't work either
    15. return true;
    16.  
    17. }
    18.  


    Bump

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

    TheA13X

    Is NPC an Entity or an Class handling all the NPC's?
    If your npc is a Child of LivingEntity, you can just set his health to zero.
    Code:
    entity.setHealth(0);
     
Thread Status:
Not open for further replies.

Share This Page