Player Damage

Discussion in 'Plugin Development' started by ProStriker123, Oct 31, 2014.

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

    ProStriker123

    Sorry for this stupid question but how can i do if i hit someone and its will take damage then if its will take damage its will send him message and if its wont take damage its wont send message

    Any help will be helpfuly and Thanks :D
     
  2. Offline

    ProStriker123

    Assist, You know you could just help and explain
     
  3. Offline

    Avygeil

    ProStriker123 You could also explain better. How would the player not take damage after being hit? Do you mean if damage done is lower than 1/2 heart?
     
    ProStriker123 likes this.
  4. Offline

    Orange Tabby

    ProStriker123
    Code:java
    1. @EventHandler
    2. public void PlayerDamage(EntityDamageByEntityEvent e) {
    3. if (e.getDamager() instanceof Player) {
    4. if (e.getEntity() instanceof Player) {
    5. Player p = (Player) e.getEntity();
    6. p.sendMessage("Your Msg");
    7. }
    8. }
    9. }


    Like This?
     
    ProStriker123 likes this.
  5. I believe the event is quite self explanatory. If you would mind taking look at the documentation, you would figure it out in less than a minute.
     
    ProStriker123 likes this.
  6. Offline

    Watto

    ProStriker123

    By explain do you mean spoon feed? Because Assist gave you everything you needed.
     
    ProStriker123 likes this.
  7. Offline

    ProStriker123

    Well i meant that if its will detect that the player will lose heart then its will send him a message cause if there is a region thats protect the place and they cant hurt eachother its still will send him message then i need it to detect it
    and Thanks for the response Like +1 :D

    Well i need only thats detect if he will lose heart, i asked him how to do it i also check it out there

    Avygeil Yes its he will lose heart also like snowball, snowball dosent lose heart but its detect that he got hitted

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

    MoseMister

    Code:
    @EventHandler
    public void PlayerDamage(EntityDamageByEntityEvent e) {
    if (e.getDamager() instanceof Player) {
    if (e.getEntity() instanceof Player) {
    Player p = (Player) e.getEntity();
    if (event.getDamage() != 0){
    p.sendMessage("Your Msg");
    }
    }
    }
    }
    like that?

    For region wise, my opinion would be to detect whether or not the player is within a PVPfree region by hooking into the plugin. The code i provided gets around the snowball problem.
     
  9. Offline

    Avygeil

    ProStriker123
    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    2. public void onPlayerDamage(EntityDamageByEntityEvent e)
    3. {
    4. if (e.getDamager() instanceof Player && e.getEntity() instanceof Player)
    5. {
    6. Player p = (Player)e.getEntity();
    7. p.sendMessage("Message");
    8. }
    9. }

    This should ignore events that were cancelled (ie. protected region), thus not sending him a message.

    Additional check if you want to ignore lower damages, for example below 1.0 :
    Code:java
    1. if (e.getDamage() >= 1.0)
    2. {
    3. // send msg
    4. }
    5.  
     
    ProStriker123 likes this.
  10. Offline

    Luke_Lax

    Spoon feed spoon feed with no effort from the op. Assist gave him all he needed to use the magic that is google.
     
Thread Status:
Not open for further replies.

Share This Page