Causing a player to look like they took damage?

Discussion in 'Plugin Development' started by Abrupt, Feb 21, 2011.

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

    Abrupt

    I can only think of one way, which is this:
    Code:
    	    	if(player.getHealth() == 20) {
    	    		player.setHealth(19);
    	    		player.setHealth(20);
    	    	} else {
    	    		player.setHealth(player.getHealth() + 1);
    	    		player.setHealth(player.getHealth() - 1);
    	    	}
    but I doubt this is the best way on doing so. any recommendations?
     
  2. Offline

    nossr50

    That actually doesn't make them look like they took damage, just changes the value quietly.
     
  3. Offline

    Abrupt

    really? I thought if you changed it to less than the health that they had would, but must've been mistaken.

    anyway, does anyone know of a way to do this then?
     
  4. Offline

    fullwall

    Find the spot where the server handles dealing damage in the net.minecraft server sources. Activate the event.
     
  5. Offline

    nossr50

    @fullwall Hm? I don't really understand how to do that.
     
  6. Offline

    Edward Hand

    I assume we're talking about the little jerk and the flashing hearts you get when you get dealt damage?

    If so:
    Code:
    CraftPlayer cPlayer = (CraftPlayer)thePlayer;
    cPlayer.getHandle().a.b(new Packet8UpdateHealth(19));
    cPlayer.getHandle().a.b(new Packet8UpdateHealth(20));
    (adjusting numbers appropriately)

    I just tested that and it works very well (though nobody else can see it except the player being hurt)
     
  7. Offline

    nossr50

    @Edward Hand the little jerk happens even with setHealth(), I want to be able to make mobs/players look like they've taken damage to other players.
     
  8. Offline

    Edward Hand

    In that case its a little more complex (but still possible):
    Code:
    CraftPlayer cp = (CraftPlayer)aRandomPlayer;
    cp.getHandle().a.b(new Packet38EntityStatus(damagedPlayer.getEntityId(), (byte)2));
    where damagedPlayer is the player being damaged and aRandomPlayer is the player you want to see that person being damaged. If you want the player to appear damaged to all players, do some kind of for loop.
     
  9. Offline

    Abrupt

    thanks, this is what I needed :)
     
  10. Offline

    Edward Hand

    Oh and try changing that 2(byte) to 3(byte).

    It makes it look like they died (resulting in instant invisibility for that player)
     
  11. Offline

    nossr50

    Hmm, bukkit isn't recognizing CraftPlayer
    Whats the import for that?
     
  12. Offline

    Edward Hand

    You need to include a reverence to CraftBukkit-0.0.10-SNAPSHOT in eclipse or whatever (along with bukkit)
     
  13. Offline

    Abrupt

    you need to add the craftbukkit library to your project, then it's this:
    Code:
    import org.bukkit.craftbukkit.entity.CraftPlayer;
    edit:
    ninja'd :eek:
     
  14. Offline

    nossr50

    Thanks, this is super helpful

    Hmm changing the byte to 3 won't make monsters look like they've died.

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

    Edward Hand

    You cast is a byte didnt you?
    (byte)3
    and you're sending the packet to the right player?
     
  16. Offline

    nossr50

    @Edward Hand
    I am, I have two functions setup. One to make entities look like they've died and one to make them look like they've taken damage. It doesn't seem to be working for either case.
    Code:
        public void sendDamagedLookPackets(Entity damaged){
            for(Player x : plugin.getServer().getOnlinePlayers()){
            CraftPlayer cp = (CraftPlayer)x;
            if(x.getEntityId() != damaged.getEntityId())
            cp.getHandle().a.b(new Packet38EntityStatus(damaged.getEntityId(), (byte)2));
            }
        }
        public void sendDeathLookPackets(Entity damaged){
            for(Player x : plugin.getServer().getOnlinePlayers()){
            CraftPlayer cp = (CraftPlayer)x;
            if(x.getEntityId() != damaged.getEntityId())
            cp.getHandle().a.b(new Packet38EntityStatus(damaged.getEntityId(), (byte)3));
            }
        }
     
Thread Status:
Not open for further replies.

Share This Page