Backstabbing Players

Discussion in 'Plugin Development' started by Eller, Feb 14, 2015.

Thread Status:
Not open for further replies.
  1. Hey guys, So I was making an Assassin kit for my KitPvP server.
    And I would like to make you insta-kill someone if you him him with shears in the back.
    This is my code currently:
    http://pastebin.com/jj7UYCLa

    Thanks in advance!
     
  2. Offline

    JustVincent

    I would do p.setHealth(0.0) personally, the rest looks good to me.
     
  3. Offline

    Ruptur

    @Eller
    What your problem was, was that you were checking if the damagee had the shears.
    You want to check if damager had the shears so quick fix.

    Code:
        @EventHandler
        public void onBackstab(EntityDamageByEntityEvent e) {
            if(e.getEntity() instanceof Player && e.getDamager() instanceof Player){
                Player d = (Player) e.getDamager();
                Player p = (Player) e.getEntity();
                    // this below was p.getItemInHand().getType() == Material.SHEARS
                    // need to be what it is now
                    if(d.getItemInHand().getType() == Material.SHEARS){
                        if(p.getLocation().getYaw() > d.getLocation().getYaw()-40 && p.getLocation().getYaw() < d.getLocation().getYaw()+40){
                            p.setHealth(0);
                        }
                    }
            }
        }
    
    If this solved your problem than don't forget to set this thread prefix to [Solved]

    If you think i helped then leave a like :D
     
    Last edited: Feb 14, 2015
    Eller likes this.
  4. Offline

    xTrollxDudex

    You should use the vectors of both players to see if they are pointing the same direction.
     
  5. Offline

    Ruptur

    @xTrollxDudex
    Already done that, the code works without errors
     
  6. @Ruptur Thanks I'll try it out! I see what I have done wrongly ... Stupid me :p Thanks for the help ill leave a like
     
Thread Status:
Not open for further replies.

Share This Page