Simulate Player Death by Player

Discussion in 'Plugin Development' started by RAFA_GATO_FOFO, May 5, 2014.

Thread Status:
Not open for further replies.
  1. Alright so my goal is to set the players gamemode to creative when he dies by player damage.

    For some reason this EDBE event isn't working properly, is there something wrong?

    Code:java
    1. @EventHandler
    2. public void onEntityDamage(EntityDamageByEntityEvent e){
    3. if (e.getDamager() instanceof Player &&
    4. e.getEntity() instanceof Player){
    5. Player p = (Player)e.getEntity();
    6. if(e.getDamage() >= p.getHealth()){
    7. e.setCancelled(true);
    8. PlayerDeath.death(p);
    9. }
    10. }
    11. }


    And I've got the player being killed by himself.
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("kill")){
    2. Player p = (Player) sender;
    3. p.damage(20, p);
    4. return true;
    5. }
     
  2. RAFA_GATO_FOFO Couldn't you just use the PlayerDeathEvent? Or do you want to make it so that they don't actually die?
     
  3. AdamQpzm
    I want to prevent death yes.
     
  4. Offline

    Esophose

    RAFA_GATO_FOFO
    Using if(e.getDamage() >= p.getHealth()) isn't the correct logic. Try using
    if(p.getHealth()-e.getDamage() <= 0)
     
  5. Offline

    agokhale1

    RAFA_GATO_FOFO
    You could use PacketPlayInClientCommand and use the PerformRespawn enum
     
  6. Esophose
    Why not? I've changed it to what you posted but when using /kill I just die regardless.
     
  7. Offline

    agokhale1

    RAFA_GATO_FOFO
    Use the packets that I mentioned above, which will cancel the respawn screen and upon respawn, teleport them to their prior location and set their gamemode to createive
     
  8. Offline

    Esophose

    RAFA_GATO_FOFO
    When using /kill it will kill you no matter what, from what I know there isn't any way to stop that. The code I gave you will work if the player is killed by any sort of entity. If you want you could try just using a EntityDamageEvent instead of the EntityDamageByEntityEvent
     
  9. Offline

    Rocoty

    Esophose Those two do exactly the same
     
  10. Offline

    Esophose


    The EntityDamageEvent will detect other sorts of damage such as Lava, drowning, suffocation, falling, and cactus. The EntityDamageByEntityEvent doesn't detect those, it only detects damage inflicted by Entities.
     
  11. Esophose Surely you could effectively stop /kill from killing you by making your own command? Failing that, CommandPreProcessEvent
     
  12. Offline

    Esophose

    AdamQpzm Yes CommandPreProcessEvent would probably be the best way to do this.
    Check if the command was /kill, then cancel and do the code you want in there.
     
  13. I have my own kill command which simulates me killing myself.
     
  14. Offline

    RawCode

    what about disabling or replacing kill command with your own implementation that properly handle your custom death?
     
  15. That's what I did:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("heykillme")){
    2. Player p = (Player) sender;
    3. p.damage(20, p);
    4. return true;
    5. }


    This command is just supposed to replicate/simulate a player death by player in order to test the event.
     
  16. Offline

    Rocoty

    Esophose Sorry for the confusion. I was talking about your previous post
     
  17. Offline

    SuperOmegaCow

    RAFA_GATO_FOFO Rocoty RawCode
    Override the I function in Entityplayer and just remove the sending of the packet that tells clients that you died.
     
  18. Offline

    RawCode

    there is no such packet, client will render death screen if entity HP drop below 1.

    if you cancel state change packet, client will be kicked for flying if attempt to move around dead (tested long ago, may be different currently)
     
  19. Offline

    SuperOmegaCow

    RawCode
    I am only talking about iterating through the scoreboard.
     
  20. Sorry I haven't been able to reply sooner. Does my kill command (in the comment above) not work properly simulating a player death by player or is it the event?
     
  21. Offline

    RawCode

    check event and command and answer your question yourself.

    since you provided no debug trace and does not explained what you want - there is no way to answer your question for anyone expect you.
     
  22. RawCode
    I've asked you multiple times not to reply to my threads. You're a terrible example of how this community works and personally, I hate you.
     
  23. Offline

    xTigerRebornx

    RAFA_GATO_FOFO While you may hate him, he provides valid and useful help (most of the time :p). Debug and see if your command is firing the event.
    If you really have to, look through source of CB and see if the event is fired when the method is called.
     
Thread Status:
Not open for further replies.

Share This Page