Solved Remove NPC created using packets

Discussion in 'Spigot Plugin Development' started by Martinusius2, Aug 7, 2018.

  1. So I have NPC created using packets, and now I want to remove it (something like opposite of PacketPlayOutNamedEntitySpawn). I tried PacketPlayOutEntityDestroy:
    Code (Text):
    connection.sendPacket(new PacketPlayOutEntityDestroy(new int[]{npc.getId()}));
    But it doesn't seem to work.
  2. ScarabCoder

    ScarabCoder Retired Resource Staff

  3. I know, but that does not remove the NPC character.
    Code (Text):
    connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, npc));
  4. FrostedSnowman

    Resource Staff

    are you sure the entity id is correct? can you show your entire code
  5. Code (Text):
    MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
                WorldServer world = ((CraftWorld) Bukkit.getServer().getWorld("world2")).getHandle();
                npc = new EntityPlayer(server, world, new GameProfile(player.getUniqueId(), "You"), new PlayerInteractManager(world));
                npc.teleportTo(npcloc, false);
                PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
                connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc));
                connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
  6. FrostedSnowman

    Resource Staff

    show how you store the entity ID
  7. ScarabCoder

    ScarabCoder Retired Resource Staff

    the ID is generated and stored in NMS. He's taking it from there, too. That won't be the issue.
  8. This is NPC:
    Code (Text):
    private EntityPlayer npc;
    This is that remove thing:
    Code (Text):
    connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, npc));
    I absolutelly don't know, what ID are you talking about.
  9. In video tutorial I watched, that thing (PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, npc)) also didn't remove the character. It only removed it from tablist. So I don't see a reason why it should do that for me.
  10. You dont use REMOVE_PLAYER to rid of the entity, i think it was something about RemoveEntity, DeleteEntity or DestroyEntity. The player thing is tracking of something separate. You must keep track of the entity id for that.
  11. I said I tried that here:
    But it didn't work.
  12. Ok, it works now. I don't know why it didn't work before.
  13. I found the solution for it:

    Code (Java):
    connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, npc));
    connection.sendPacket(new PacketPlayOutEntityDestroy(npc.getId()));
    You just have to use the entityDestroy with the id to remove the actual body and use the PlayerInfo to remove the name from the Tab-List.

    kind regards
    #14 Linus_Hoja, Mar 13, 2020
    Last edited: Mar 13, 2020
  14. If you keep this up, you'll be raising your zombie army in no time at all.

  15. can you show how you did it? I'm trying to do the same thing as you. Please?