[Solved]Kill player by right clicking towards them with a Diamond Hoe

Discussion in 'Plugin Development' started by JohnSMMC, Aug 8, 2012.

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

    JohnSMMC

    Hi I am trying to develop a plugin so that when you left click with a diamond it it kills the player or mob that you have left clicked towards, but I don't know how to make the killing code.

    Please help me.
     
  2. Offline

    McLuke500

    Just with the player do player.setHealth(0);
    JohnSMMC
     
  3. Offline

    JohnSMMC

    But isn't that if you already have the player specified?
    McLuke500
     
  4. Offline

    McLuke500

    Yes you would have to get the player your pointing at and then set his health to 0
     
  5. Offline

    JohnSMMC

    Do you know how I would get the player I am looking at?
    McLuke500
     
  6. Offline

    McLuke500

    Last edited by a moderator: May 27, 2016
  7. Offline

    Bobfan

    Have an explosion.
     
    Jag.1000 likes this.
  8. Offline

    JohnSMMC

    Ok :(
    McLuke500

    I would rather it was a bit more subtle
    Bobfan

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  9. Offline

    XbannisherX

    Do you want him to die by clicking at a long distance? or just 1 block far?

    cuz if thats so....


    Code:
    public void YourCode(PlayerInteractEntityEvent event){//gets the event which is called, in this case PlayerInteractEntityEvent
    Entity e = event.getRightClicked();                      //gets the player/mob you right clicked
    Material m = event.getPlayer().getItemInHand().getType();//gets the caster's item in hand(for later use)
    Player p = event.getPlayer();
    if(m == Material.DIAMOND_HOE && p.hasPermission("putyour.permissionhere") ){//so, if the players iteminhand == a Diamond_Hoe and he has Your permission, Do this>>>
    Location loc = e.getLocation(); //gets the location for later use
    World w = loc.getWorld(); //gets the world for later use, loc and world are needed for lightning
    w.strikeLightning(loc);//spawns some lightning , just for the cool effect, and kills the player
    w.strikeLightning(loc);
    w.strikeLightning(loc);
    w.strikeLightning(loc);
    w.strikeLightning(loc);
    w.strikeLightning(loc);
    w.strikeLightning(loc);
    w.strikeLightning(loc);
    p.sendMessage(ChatColor.GOLD + "Player....is ded");//sends a message to the caster
    }else{//if none if this is happening>>>
    p.sendMessage("There is no player there...you silly");// send a message that there is no player there
    }
    //There may be some faults in this code, writing it on my cellphone, but this is the basic code you need for your plugin :)
    
    i have put down some basic text next to it for you to better understand it :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
    JohnSMMC likes this.
  10. Offline

    CoKoC

    I once made a class to abstract that code away. With it you can get the entity at any time, without an event. I think the original code was ripped off somewhere else.

    http://pastebin.com/raw.php?i=fvC6Tezi
     
  11. Offline

    JohnSMMC

    Wow, thanks banisher that helped me loads :)
    XbannisherX
    Oh and thanks CoKoC I will remember to use that code in the future :)
    CoKoC
     
Thread Status:
Not open for further replies.

Share This Page