Solved Change amount of damage lightning does

Discussion in 'Plugin Development' started by Ibix13, May 18, 2013.

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

    Ibix13

    I am making a kit plugin and I need to make it when you smite someone with lightning(I already have) it does more damage. it only does like 4 hearts currently but I need it to do way more. Here is code: ​
    Code:
                                World world = player.getWorld();
                                    Block targetblock = player.getTargetBlock(null,
                                            500);
                                    Location location = targetblock.getLocation();
                                    world.strikeLightning(location);
                                    player.sendMessage("You have used"
                                            + ChatColor.GREEN + " Thunder!");
    Thanks, and BTW I have been searching for a while and havn't gotten any luck. Halp!
     
  2. Offline

    Ultimate_n00b

    Either you could strike lightning more than once, or:
    Listen on Entity damage event.
    Check if its lightning.
    If so, cancel the event (or subtract how much damage you want by how much it did)
    Add damage you want (or just add this damage from ^)
     
    Ibix13 likes this.
  3. Offline

    Ibix13

    how would I subtract it? code:
    Code:
    @EventHandler
        public void onPlayerDamage(EntityDamageByEntityEvent event) {
     
                            if(event.getDamager() instanceof LightningStrike){
                             
                            }
     
  4. Offline

    Ultimate_n00b

    int finalDamage = (HowMuchDamageYouWantInTheFormOfANumber) - event.getDamage;
    event.setDamage(finalDamage);
     
    Ibix13 likes this.
  5. Offline

    Ibix13

    It doesn't work? can you test it?

    I have to go but I'll be back in about an hour and a half D:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  6. or, once you smite someone, add this:
    Code:
    //Player assumes that you have already connected player and the player, so you used a command like /smite <player>
    // Replace player with whatever your player symbol is. 
    [FONT=Consolas] World world = player.getWorld();
                                    Block targetblock = player.getTargetBlock(null,
                                            500);
                                    Location location = targetblock.getLocation();
                                    world.strikeLightning(location);
                                    player.sendMessage("You have used"
                                            + ChatColor.GREEN + " Thunder!");[/FONT]
    [FONT=Consolas]                                player.setHealth(6);[/FONT]
    [FONT=Consolas]
    [/FONT]
    Now, The player that is struck is now on 3 hearts, instead of 6. (6 means 6 units of health, not hearts. 1 heart = 2 units)
     
  7. Offline

    Ibix13

    But if I was on 4 hearts then It would take 1 heart..

    Ok I used this in a different method and I got it to work, only problem is I get an error when I strike lightning D:
    Code:
    @EventHandler
        public void onPlayerD(EntityDamageEvent event) {
            if(((EntityDamageByEntityEvent) event).getDamager() instanceof LightningStrike){
            int finalDamage = (25) - event.getDamage();
            event.setDamage(finalDamage);
    That is the code
    here is the error: http://pastebin.com/ptqnP5q7

    Oh herp derp I fixed it with this code:
    Code:
    @EventHandler
        public void onPlayerD(EntityDamageByEntityEvent event) {
            if(((EntityDamageByEntityEvent) event).getDamager() instanceof LightningStrike){
            int finalDamage = (20) - event.getDamage();
            event.setDamage(finalDamage);
    Thank you ulitmate_n00b :D Solved :D

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

    Ultimate_n00b

    Why are you adding (EntityDamageByEntityEvent)?
    Can't you just do event.getDamager?
     
  9. Yes. However....
    Code:
    if(player.getHealth() == 20){
    player.setHealth(16);
    }
    else if(player.getHealth() == 18){
    player.setHealth(14);
    }
    
    That way natrual lightning strikes wont give extra damage, and it could be only a certain item or command that does it.
     
Thread Status:
Not open for further replies.

Share This Page