1. These forums are still being retired! Please use GitHub discussions or Discord. You cannot create new threads or new accounts now. If you need to contact some user of the forums, you should do it sooner, rather than later. This notice was last updated on May 30th, 2021.

Resolved How do I kill an NPC with the api?

Discussion in 'Help and Support' started by Eater-of-Cake, Jul 10, 2017.

Tags:
  1. Eater-of-Cake

    Eater-of-Cake Level 1

    Joined:
    Jul 10, 2017
    Messages:
    5
    I have this:
    TShock.Utils.GetNPCById(id).damage = 1000;
    I assume damage is the amount of damage the npc has taken, but I doubt this would work?
    Any other ways?
     
  2. Zaicon

    Zaicon Spam Cleaner 9000
    TShock Mod Plugin Developer

    Joined:
    Feb 15, 2014
    Messages:
    811
    I'd recommend looking at the current source code to see how they do it:

    /butcher:
    Code:
    TSPlayer.Server.StrikeNPC(i, (int)(Main.npc[i].life + (Main.npc[i].defense * 0.6)), 0, 0);
    /clear npc:
    Code:
    Main.npc[i].active = false;
    Main.npc[i].type = 0;
    TSPlayer.All.SendData(PacketTypes.NpcUpdate, "", i);
     
  3. Eater-of-Cake

    Eater-of-Cake Level 1

    Joined:
    Jul 10, 2017
    Messages:
    5
    I will see if your second listing works. Thanks for the help!:)
     
  4. Eater-of-Cake

    Eater-of-Cake Level 1

    Joined:
    Jul 10, 2017
    Messages:
    5
    Thank you! It worked.