NPC Manipulations

Discussion in 'Plugin Development' started by girardcome, Jun 23, 2019.

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

    girardcome

    Hello I hope you are well, me not really, I have a problem with NPC.

    I can not make them move, I have the impression that when the NPC spawned, it is not realistic, it does not move, it is untouchable.

    I would like with my code that I just made, allow them to move themselves from one location to another.

    /! \ I do not want to use an API. I use only NMS. (i don't wan't citizens or any other APIs like that thanks)


    Here is my code:
    PHP:
        public void summonNPC(Player p) {
            
    Location loc p.getLocation();
            
    MinecraftServer nmsServer = ((CraftServerBukkit.getServer()).getServer();
            
    WorldServer nmsWorld = ((CraftWorldp.getWorld()).getHandle();
            
    GameProfile gp = new GameProfile(p.getUniqueId(), "NPC Tests");
            
    EntityPlayer npc = new EntityPlayer(nmsServernmsWorldgp, new PlayerInteractManager(nmsWorld));

            
    npc.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getPitch(), loc.getYaw());

            
    PlayerConnection connection = ((CraftPlayerp).getHandle().playerConnection;

            
    connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));

           
            
    npc.getBukkitEntity().getInventory().setItemInHand(new ItemStack(Material.DIAMOND_SWORD));
        }
        
     
  2. Offline

    Visualizeding

    One solution I had for this was creating a custom entity using NMS and spawning it at the exact location of the npc, and using the entities pathfinders to move it to locations using either PacketPlayOutEntityTeleport or PacketPlayOutRelEntityMove, I forget which one, but one shows real player movement. The alternative is creating your own pathfinder.
     
  3. Offline

    KarimAKL

    @Visualizeding I don't think the EntityPlayer class have a Pathfinder.
     
  4. Offline

    Visualizeding

    It doesn't need to be an EntityPlayer, you can use any entity like a zombie, and just set it invisible.
     
  5. Offline

    KarimAKL

    @Visualizeding That's not what i mean. How would you get the player NPC to walk, if it doesn't have a pathfinder?
     
  6. Offline

    Visualizeding

    @KarimAKL You use another entity to get the pathfinder, and have the npc move to the entities location.
     
Thread Status:
Not open for further replies.

Share This Page