Solved Spawn giant when a zombie attack player.

Discussion in 'Plugin Development' started by MineDoubleSpace, Aug 10, 2013.

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

    MineDoubleSpace

    Code:java
    1. public void EntityEffectByEntityDamage(EntityDamageByEntityEvent event) {
    2. if(event.getEntity() instanceof Player) {
    3. }if(event.getDamager().getType() == EntityType.ZOMBIE) {
    4. Player player = (Player) event.getEntity();
    5. player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION,
    6. 500, 1));
    7. player.getWorld().spawnCreature(player.getLocation(), EntityType.GIANT);
    8.  
    9. }
    10. }else if(event.getDamager().getType() == EntityType.ZOMBIE) {
    11. }
    12. }


    This is the code I'm trying to use, but i want to kill the zombie when the Giant spawn.
    and if possible createExplosion() when giant spawn,
    Thanks!
     
  2. Offline

    PropGamer

    You can't make effects for live npcs/entitys such as zombies I think.
     
  3. Offline

    TheSmallBones

    Code:
     @EventHandler
    
    public void EntityEffectByEntityDamage(EntityDamageByEntityEvent event) {
    if(event.getEntity() instanceof Player) {
    if(event.getDamager().getType() == EntityType.ZOMBIE) {
    Entity entity = event.getDamager();
    entity.remove();
    Player player = (Player) event.getEntity();
    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION,500, 1));
    player.getWorld().spawnCreature(player.getLocation(), EntityType.GIANT);
    event.getEntity().getWorld().createExplosion(event.getEntity().getLocation(), 1);
    }
    }
    }
     
  4. Offline

    MineDoubleSpace

    PropGamer So what you are saying that i cant kill the Damager?

    TheSmallBones Is there way to kill the zombie when the giant spawns?

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

    TheSmallBones

    Oh instead of remove it? Yeah entity.setHealth(0.0);
     
  6. Offline

    MineDoubleSpace

    TheSmallBones Oh i see.. sorry didnt see the entity.remove(); part :D
     
  7. Offline

    TheSmallBones

    Also I just updated my code a few seconds ago, more compact and no pointless else statement, and you may need to do Zombie entity = event.getDamager();. I'm not sure if you can set an entity health to 0.
     
  8. Offline

    xxMOxMOxx

    I think his code currently does
     
  9. Offline

    MineDoubleSpace

    xxMOxMOxx TheSmallBones One more simple thing i need to ask.
    When the giant spawn is there to way to sethealth(18)
    maybe using CreatureSpawnEvent
     
  10. Offline

    TheSmallBones

    Yes that is right. But remember it's a double now so it'd be 18.0
     
  11. Offline

    xxMOxMOxx

    Creature spawn event would work great if theres no other way giants can spawn, but there might be a better way
     
  12. Offline

    MineDoubleSpace

    Can you tell me the code for it pls :) thanks
     
  13. Offline

    xxMOxMOxx

    TheSmallBones would you like to take this one or should I? I usually seem to post a few seconds after you lol
     
  14. Offline

    TheSmallBones

    Oh wait I thought you said zombie. Yeah so when you spawn the giant do this Entity g = player.getWorld().spawnCreature(player.getLocation(), EntityType.GIANT); and then g.setHealth(18.0); you don't need a listener besides the one you have right now.

    Oh and also I'm not exactly sure if Giants max health is 20, never worked with them before so keep that in mind if you're trying to spawn them with 10% less health.

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

    xxMOxMOxx

    I think giants tank like a boss and have 100 health
     
  16. Offline

    TheSmallBones

    Yeah then 18 health would be nothing then, considering they have no armor. It'd be like killing a no armor player minus 1 heart. Don't quote me on this though I had no idea they existed until a month ago.
     
  17. Offline

    MineDoubleSpace

    xxMOxMOxx setting sethealth(18.0) on npc gives me an error on eclipse

    not it working thanks for help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page