Player bed animation on logout?

Discussion in 'Plugin Development' started by frogawesome, Jan 28, 2014.

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

    frogawesome

    So i am working on a plugin when players log out they leave a killable player entity behind that looks like it's taking a nap (bed animation) but i have no idea how to do the bed animation. i did research and i could only find outdated stuff so, any help?
     
  2. Offline

    Desle

    Use a packet for this;
    Code:
    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(new PacketPlayOutBed(EntityId, X, Y, Z));
    X, Y, Z represent the coordinates of the player
    To get a player's EntityId use;
    Code:
    p.getEntityId();

    EDIT:
    If you do it like this, it would spawn an npc and put it in sleep mode, instead of the player;
    Code:
    PacketPlayOutNamedEntitySpawn npc = new PacketPlayOutNamedEntitySpawn(p.getHandle());
    try {
        Field field = npc.getClass().getDeclaredField("a");
        field.setAccessible(true);               
        field.setInt(npc, 1337);
        field.setAccessible(!field.isAccessible());
    } catch(Exception x) {
        x.printStackTrace();
    }
    for (Player p : Bukkit.getOnlinePlayers()) {
        ((CraftPlayer) p).getHandle().playerConnection.sendPacket(npc);
        ((CraftPlayer) p).getHandle().playerConnection.sendPacket(new PacketPlayOutBed(1337, (int) p.getLocation().getX(), (int) p.getLocation().getY(), (int) p.getLocation().getZ()));
    }
     
  3. Offline

    frogawesome

    It gives me an error with the PacketPlayOutBed, i can't put any Integers there? (it needs to be a Human Entity etc...)
     
  4. Offline

    Desle

    frogawesome

    Int, Int, Unsigned Byte, Int.
    Try;
    Code:
     ((CraftPlayer) p).getHandle().playerConnection.sendPacket(new PacketPlayOutBed(1337, (int) p.getLocation().getX(), (byte) p.getLocation().getY(), (int) p.getLocation().getZ()));
    frogawesome
    This should work, actually:

    Code:java
    1. Player player = e.getPlayer();
    2. PacketPlayOutNamedEntitySpawn npc = new PacketPlayOutNamedEntitySpawn(((CraftPlayer) sender).getHandle());
    3. PacketPlayOutBed sleep = new PacketPlayOutBed();
    4. try {
    5. Field npca = npc.getClass().getDeclaredField("a");
    6. npca.setAccessible(true);
    7. npca.setInt(npc, 1337);
    8. npca.setAccessible(!npca.isAccessible());
    9. Field sleepa = sleep.getClass().getDeclaredField("a");
    10. sleepa.setAccessible(true);
    11. sleepa.setInt(sleep, 1337);
    12. sleepa.setAccessible(!sleepa.isAccessible());
    13. Field sleepb = sleep.getClass().getDeclaredField("b");
    14. sleepb.setAccessible(true);
    15. sleepb.setInt(sleep, (int) player.getLocation().getX());
    16. sleepb.setAccessible(!npca.isAccessible());
    17. Field sleepc = sleep.getClass().getDeclaredField("c");
    18. sleepc.setAccessible(true);
    19. sleepc.setInt(sleep, (int) player.getLocation().getY());
    20. sleepc.setAccessible(!sleepc.isAccessible());
    21. Field sleepd = sleep.getClass().getDeclaredField("d");
    22. sleepd.setAccessible(true);
    23. sleepd.setInt(sleep, (int) player.getLocation().getZ());
    24. sleepd.setAccessible(!sleepd.isAccessible());
    25. } catch(Exception x) {
    26. x.printStackTrace();
    27. }
    28. for (Player p : Bukkit.getOnlinePlayers()) {
    29. ((CraftPlayer) sender).getHandle().playerConnection.sendPacket(npc);
    30. ((CraftPlayer) sender).getHandle().playerConnection.sendPacket(sleep);
    31. }


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

    frogawesome

    Yeah, this works thanks, (i am not great with packets or even with npc's yet) how can i make it be killable? and (maybe) have an inventory?
     
  6. Offline

    Desle

  7. Offline

    frogawesome

    ok, thanks for the help anyway
     
  8. Desle Sorry to bring an old topic back to life but I have been trying to figure this out all day with no luck.
    I am trying to do a similar thing to frogawesome except instead of making the npc sleep when the player logs out I want it to act as a corpse when the player dies. Tried your code as well as multiple other peoples code and cant seem to get it working; best I have got is a NPC standing up without a skin in the position the player died. Could you please help? http://pastebin.com/yTyRBNtB is the code I am trying to use but nothing happens when the player dies, no errors, no player. I believe it could be something todo with the changes in 1.7 with UUID's now being required? not sure. Any help is greatly appreciated
     
  9. Offline

    frogawesome

    mike546378
    For their skin to appear you would need to create a seperate entity, then copy their entityID into the sleepa.setint(sleep, Entity.getEntityID()); Entity representing the player entity, I use remoteEntities Libary for that, but because It's not updated you can't interact with the player entities, but they do look like a corpse. Hope this helped
     
Thread Status:
Not open for further replies.

Share This Page