applying potion effects

Discussion in 'Plugin Development' started by Retherz_, Nov 20, 2012.

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

    Retherz_

    Hello, how can i apply potion effects on monsters.. like regeneration on a cow?
     
  2. Offline

    Drkmaster83

    Code:
    @EventHandler
    public void onEntityDamageByEntity(EntityDamageByEntityEvent e)
    {
        if(e.getEntity() instanceof Cow)
        {
            e.getEntity().addPotionEffect(//potion effect);
        }
    }
    '
    That's for if it gets damaged, though... Hmm... You get my draft.
     
  3. Offline

    CevinWa

    You have to cast to get the cow.
    Code:
    @EventHandler
    public void onEntityDamageByEntity(EntityDamageByEntityEvent e)
    {
        if(e.getEntity() instanceof Cow)
        {
    Cow cow = ((Cow) e.getEntity())
            cow.addPotionEffect(//potion effect);
        }
    }
     
  4. Offline

    Retherz_

    How do i change the duration?
     
  5. Offline

    CevinWa

    Ohh like this.

    Cow..addPotionEffect(PotionEffectType.<Someeffect>.createEffect((int) 1000L, 50));


    Where 1000L is the time in ticks and 50 is the gratetude or power.
     
  6. Offline

    Retherz_

    So its like regeneration 50 and duration 50 seconds?
     
  7. Offline

    CevinWa

    Just divide 1000 with 20 to get out how many seconds it is. 50 is just how powerful it is.
     
  8. Offline

    Retherz_

    But how can i make it infinite seconds? just make it a trillion?
     
  9. Offline

    fireblast709

  10. Offline

    CevinWa

    Exactly Minecraft makes it ilike nearly nfinite if you set it as like 100000000L
     
  11. Offline

    fireblast709

    nearly infinite =/= infinite >->
     
  12. Offline

    Rprrr

    Infinite would need a repeating task.
     
  13. Offline

    WaterNode

    Perhaps make a repeating task that sets it for 10 minutes every few seconds?
    Code:
    int taskID = Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
        public void run() {
            Cow.addPotionEffect(PotionEffectType.<Someeffect>.createEffect((int) 1000L, 50));
        }
    }, 60L, 200L);
    Gives them a 20 second potion effect every 10 seconds.
     
  14. Offline

    Doggyroc

    Don't know if this is still open, if it is not, someone tell me. Infinite potion effects can be achieved by using Integer.MAX_VALUE in the duration argument.
     
  15. Offline

    CeramicTitan

    Entity entity = event.getEntity(){
    if(entity instanceof LivingEntity){
    if(entity == EntityType.COW){
    ((LivingEntity) entity).addPotionEffect(new PotionEffect.SPEED, *DURATION IN TICKS*, *POTENCY*);
    }
    }
    }
     
Thread Status:
Not open for further replies.

Share This Page