Lighting Strike Event

Discussion in 'Plugin Development' started by The Fancy Whale, Mar 16, 2014.

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

    The Fancy Whale

    I have a plugin where players can strike others with lightning using a stick. How would I set the amount of damage from the lightning and is it possible to set a knockback using player velocity? Thanks
  2. Offline


    If you get the location of the lightning strike then loop through the players near it, you can set their health etc

    1. for(Entity e : lightning.getLocation().getChunk().getEntities()){
    2. Location loc = e.getLocation();
    3. if (loc.getBlockX() == lightning.getLocation().getBlockX() && loc.getBlockY() == lightning.getLocation().getBlockY() && loc.getBlockZ() == lightning.getLocation().getBlockZ()){
    4. e.setHealth(e.getHealth() - 4);
    5. }
    6. }
  3. Offline


    Rather than handling it with the lightning strike, you would probably just use the lightning for effect, and handle the damage/knockback while hitting the player with the stick.
  4. Offline


    xXSniperzzXx_SD The Fancy Whale
    While that code does knock them back, you want to normalize the vector to a Y value to add a cool knockback effect.
  5. Offline

    The Fancy Whale

    xXSniperzzXx_SD AoH_Ruthless Axe2760 But if I want to set the damage from lightning first I need to remove the default damage it does right? I am not sure how I would do that. Would I use entitydamageevent and then use getCause()?
  6. Offline


    The Fancy Whale Probably, I would say to just use that instead of the lightning strike event but I guess the lightning won't always hit players. But you could probably do the Lightning strike effect then it won't do damage.
  7. Offline


    The Fancy Whale
    Well What I would do is fake the lightning by creating the lightning effect (extends World).
    Then damage the player:

    1. Player p = /*Your player*/;
    2. Location loc = p.getLocation();
    3. World world = p.getWorld();
    5. world.strikeLightningEffect(p.getLocation()); //Strike the lightning
    6. p.damage(/*However much you want to damage them*/);
Thread Status:
Not open for further replies.

Share This Page