Client side Player Npc?

Discussion in 'Plugin Development' started by xxNightlordx, Sep 2, 2013.

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

    xxNightlordx

    Is it possible to have a client side player NPC using ProtocolLib or any other methods?
     
  2. Offline

    bobacadodl

    Yes, you can probably use a spawn player packet with protocolLib and only send it to one player.
     
  3. Offline

    xxNightlordx

    This was part of the code for spawning a fake ghast.
    Code:java
    1. public void sendPacket(Player p) {
    2. PacketContainer newPacket = new PacketContainer(24);
    3.  
    4. newPacket.getIntegers().
    5. write(0, 500).
    6. write(1, (int) EntityType.GHAST.getTypeId()).
    7. write(2, (int) (p.getLocation().getX() * 32)).
    8. write(3, (int) (p.getLocation().getY() * 32)).
    9. write(4, (int) (p.getLocation().getZ() * 32));
    10.  
    11. newPacket.getDataWatcherModifier().
    12. write(0, ghastWatcher);
    13.  
    14. try {
    15. ProtocolLibrary.getProtocolManager().sendServerPacket(p, newPacket);
    16. e.printStackTrace();
    17. }
    18. }


    Do I just replace EntityType.Ghast with EntityType.Player?

    Nope....Crashes the client :C

    Fyi, I'm only want to create a dummy npc player. It doesnt move

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

    mattrick

  5. Offline

    phips99

    xxNightlordx If you want to spawn a NPC you should use the SpawnNamedEntity Packet.
    Code:java
    1. Packet14SpawnNamedEntity spawned = new Packet14SpawnNamedEntity();
    2. spawned.setEntityID(12345); //Unique ID...
    3. spawned.setPosition(p.getLocation().toVector());
    4. spawned.setPlayerName(p.getName()); //If you set the name of a npc it renders the skin of the player with that skin!
    5. spawned.setYaw(p.getLocation().getYaw());
    6. spawned.setPitch(p.getLocation().getPitch());
    7. spawned.setCurrentItem((short) p.getItemInHand().getTypeId());
    8. try {
    9. for (Player players : Bukkit.getOnlinePlayers()) {
    10. ProtocolLibrary.getProtocolManager().sendServerPacket(
    11. players, spawned.getHandle());
    12. }
    13. e.printStackTrace();
    14. }

    If you are interested in setting more options to the npc tahg me!
     
  6. Offline

    xxNightlordx

    phips99
    It crashes the client. Here is how I implemented it:

    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    3.  
    4. if (sender instanceof Player) {
    5. Player p = (Player) sender;
    6.  
    7. Packet14SpawnNamedEntity spawned = new Packet14SpawnNamedEntity();
    8. spawned.setEntityID(12345);
    9. spawned.setPosition(p.getLocation().toVector());
    10. spawned.setPlayerName("Herobrine");
    11. spawned.setYaw(p.getLocation().getYaw());
    12. spawned.setPitch(p.getLocation().getPitch());
    13. spawned.setCurrentItem((short) p.getItemInHand().getTypeId());
    14.  
    15. try {
    16. ProtocolLibrary.getProtocolManager().sendServerPacket(p, spawned.getHandle());
    17. e.printStackTrace();
    18. }
    19.  
    20. }
    21.  
    22. return true;
    23.  
    24. }


    Nevermind, I think ill use RemoteEntites instead, But thanks for helping :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  7. xxNightlordx Are you defining what type of entity your spawning?
     
  8. Offline

    xxNightlordx

    Nevermind, RemoteEntities isnt what I'm looking for :(. BorisTheTerrible What do you mean defining what type? I used that same code that phips99 suggested.
     
  9. Offline

    xTrollxDudex

    xxNightlordx
    It's Packet20NamedEntitySpawn
    phips99
    Packet 14 is like BlockDig or something xD
     
  10. Offline

    chasechocolate

  11. Offline

    phips99

  12. Offline

    xxNightlordx

    Yea, I'm using ProtocolLib...

    @phips99 Do you have any solutions?

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

    xTrollxDudex

  14. xxNightlordx I'm not an expert at packets, but I quote this.
    So it might be crashing the client because the client never registered that player joining.... But I wouldn't really know. You might want to ask aadnk for help.
     
  15. Offline

    xxNightlordx

  16. Offline

    xxNightlordx

  17. Offline

    bob0310

  18. Offline

    xxNightlordx

    bob0310 It gets your post to the top of the forum page. But you can only bump once every 24 hours
     
Thread Status:
Not open for further replies.

Share This Page