Player Death

Discussion in 'Plugin Development' started by themanman0, May 15, 2011.

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

    themanman0

    I understand this is the Entity death event and a player respawn event, but I don't see how I can get the name of the killer and the victim.
     
  2. Offline

    halvors

    You'll have to capture that in the EntityDamageEvent.
     
  3. Offline

    themanman0

    So do I even need the Entity Death Event?
     
  4. Offline

    DreadKyller

    no, because what you will do in the EntityDamageEvent is get the attacker and then get the player who got attacked. then you will check to see if the players health minus the event.getDamage is less than 0 (death), if it is less that 0 then do whatever, I take it you are trying to keep track of player kills?

    PHP:
    public void onEntityDamage(EntityDamageEvent event){
        if(
    event instanceof EntityDamageByEntityEvent){
                
    EntityDamageByEntityEvent act = (EntityDamageByEntityEvent)event;
                
    Entity attacker act.getDamager();
                if(
    attacker instanceof HumanEntity){
                    
    HumanEntity cause = (HumanEntity)attacker;
                    if(
    act.getEntity() instanceof HumanEntity){
                        
    HumanEntity play = (HumanEntity)act.getEntity();
                        if(
    play instanceof Player){
                            
    Player player = (Player)play;
                            if(
    player.getHealth()-act.getDamage()<0){
                                
    //Do whatever, the player is dead
                            
    }
                        }
                    }
                }
            }
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page