Solved Headshot/Vital hit?

Discussion in 'Plugin Development' started by MgMaor, Sep 23, 2013.

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

    MgMaor

    On projectile hit > if ent instanceof player >
    How to check in what spot the projectile hit?
    head/chest..
     
  2. MgMaor
    It is not possible with any organ except the head. To find the head, get the players location and add 1 to the y.
     
    1Achmed1 likes this.
  3. Offline

    The_Doctor_123

    Don't use ProjectileHitEvent. Here's something that'll work better:

    Code:java
    1. @EventHandler
    2. public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
    3. {
    4. if (event.getDamager() instanceof Arrow && event.getEntity() instanceof Player)
    5. {
    6. if (event.getDamager().getLocation().distance(((Player) event.getEntity()).getEyeLocation()) < 0.4)
    7. {
    8. event.setDamage(event.getDamage() * 2);
    9. }
    10. }
    11. }
     
  4. Offline

    mattrick

    I believe Bukkit locations actually support decimals.....
     
  5. mattrick16
    Yes. I said add one, because players are actually two blocks, and the p.getLocation() gives you the block at their feet. IF you add 1 to that, it will give you the head.
     
  6. Offline

    iZanax

    #Player.getEyeLocation() ?

    By the way. Projectile are not giving the proper location when they hit, they always give the location that is moved like 0.5 blocks in the direction he went. This will give a lot of false-positive. I don't use it because of that.

    If someone knows how to deal with this a give it a 90% succes rate. Please provide information :3
     
  7. iZanax
    Oh duh.. yeah that would work too...
     
  8. Offline

    MgMaor

    The_Doctor_123
    Not work :/
    Can you give me more hints?
    I bad with world/location etc..
     
  9. Offline

    The_Doctor_123

    MgMaor
    Possibly change 0.4 to something larger?
     
  10. Offline

    MgMaor

  11. Offline

    The_Doctor_123

    MgMaor
    Define "not working." Is it throwing errors or just not working? If its not working, check if the event is even firing.
     
  12. Offline

    MgMaor

    The_Doctor_123
    No errors. They get "hi" but they dont get HELL YEAH!
    Code:java
    1. @EventHandler
    2. public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
    3. {
    4. if (event.getEntity() instanceof Player)
    5. {
    6. Player t = (Player) event.getEntity();
    7. if (event.getDamager() instanceof Arrow) {
    8. Arrow a = (Arrow) event.getDamager();
    9. if (a.getShooter() instanceof Player) {
    10. Player p = (Player) a.getShooter();
    11. p.sendMessage("hi");
    12. t.sendMessage("hi");
    13. if (a.getLocation().distance(t.getEyeLocation()) < 0.4)
    14. {
    15. p.sendMessage("HELL YEAH!");
    16. t.sendMessage("HELL YEAH!");
    17. t.setHealth(0);
    18. }
    19. }
    20. }
    21. }
    22. }
     
  13. Offline

    chasechocolate

  14. Offline

    The_Doctor_123

    MgMaor
    I still believe that you haven't tried a high enough value.

    chasechocolate
    Oh man, I watched that video.. no.. please, no.. He doesn't know what in the world he's doing. Of course, what tutorials are there where people actually do?
     
  15. Offline

    1Achmed1

    The_Doctor_123
    TheBCBroz are actually pretty good. I leaned a lot from them :)
     
  16. Offline

    Compressions

    1Achmed1 Yeah a lot... of bad habits.
     
  17. Offline

    1Achmed1

  18. Offline

    chasechocolate

    The_Doctor_123 1Achmed1 I wouldn't rely on them for this reason:
    However, I just showed that video so you could get the correct numbers for calculating if it is a headshot or not.
     
    Compressions likes this.
  19. Offline

    The_Doctor_123

    1Achmed1
    I watched them as well, just to get the main idea of how to do something when I was a Bukkit noob. I, however, did see the bad practice he was doing and even more today.

    I seriously need to start up my own YouTube Bukkit tutorial series and set these people straight.
     
  20. Offline

    chasechocolate

    I'm going to start a series too :)
     
  21. Offline

    The_Doctor_123

    chasechocolate
    Oh finally, a person that actually knows Java will start a tutorial series!
     
    1Achmed1 and chasechocolate like this.
  22. Offline

    1Achmed1

    Yes. It'll be good to get good tutorials from
    1. A BukkitDev team member
    2. A bukkit plugin pro
     
  23. Offline

    james137137

    well looking at a plugin aready made i found this.

    https://github.com/bitWolfy/MorePhy...kledmc/physics/components/ArrowComponent.java

    Code:
    public void onEntityDamage(EntityDamageByEntityEvent event) {
     
    ....
    HitArea hitArea = HitArea.get(event.getDamager().getLocation().getY() - event.getEntity().getLocation().getY());
    ....
     
    }
     
    public static HitArea get(double height) {
                if(height <= 1.85 && height > 1.38) return HitArea.HEAD;
                else if(height <= 1.38 && height > 1.26) return HitArea.NECK;
                else if(height <= 1.26 && height > 0.74) return HitArea.TORSO;
                else if(height <= 0.74 && height > 0.46) return HitArea.CROTCH;
                else if(height <= 0.46 && height > 0.17) return HitArea.LEGS;
                else if(height <= 0.17 && height > 0) return HitArea.TOE;
               
                return HitArea.UNKNOWN;
            }
     
  24. Offline

    MgMaor

    james137137
    Not work
    Code:java
    1. @EventHandler
    2. public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
    3. {
    4. if (event.getEntity() instanceof Player)
    5. {
    6. Player t = (Player) event.getEntity();
    7. if (event.getDamager() instanceof Arrow) {
    8. Arrow a = (Arrow) event.getDamager();
    9. if (a.getShooter() instanceof Player) {
    10. Player p = (Player) a.getShooter();
    11. p.sendMessage("hi");
    12. t.sendMessage("hi");
    13. if (a.getLocation().getY() <= 1.85 && a.getLocation().getY() > 1.38)
    14. {
    15. p.sendMessage("HELL YEAH!");
    16. t.sendMessage("HELL YEAH!");
    17. t.setHealth(0);
    18. }
    19. }
    20. }
    21. }
    22. }
     
  25. Offline

    unforgiven5232

    Message me if your serous and need a partner
     
  26. Offline

    MgMaor

    SOLVED!!! THX ALL
    Code:java
    1. @EventHandler
    2. public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
    3. {
    4. if (event.getEntity() instanceof Player)
    5. {
    6. Player t = (Player) event.getEntity();
    7. if (event.getDamager() instanceof Arrow) {
    8. Arrow a = (Arrow) event.getDamager();
    9. if (a.getShooter() instanceof Player) {
    10. Player p = (Player) a.getShooter();
    11. p.sendMessage("hi");
    12. t.sendMessage("hi");
    13. if (a.getLocation().getY() - t.getLocation().getY() > 1.35)
    14. {
    15. p.sendMessage("HELL YEAH!");
    16. t.sendMessage("HELL YEAH!");
    17. t.setHealth(0);
    18. }
    19. }
    20. }
    21. }
    22. }
     
Thread Status:
Not open for further replies.

Share This Page