Adding potion effects to mobs.

Discussion in 'Plugin Development' started by Ryan Johnson, Jul 29, 2012.

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

    Ryan Johnson

    Hey,

    I am developing a zombie survival type plugin, similar to the game 'Killing Floor' just for personal use, as a challenge, and I am stuck here.
    I have been searching for a while but can't seem to get anything that works.
    I am going to make it work so each wave is stronger, faster and with much more zombies, and I can't work out how to give speed (and take speed) or give strength (And take strength).
    Currently I have this, which I thought would give the potion effect when a zombie spawns:
    Code:
    public void onZombieSpawn(CreatureSpawnEvent event){
            event.getEntity().addPotionEffect(new PotionEffect(PotionEffectType.SPEED,2147483647, 50));
        }
    I thought this would make the zombie go, well, very fast, but it doesn't... It does nothing.
    Sorry if this has been answered before, but I couldn't seem to find it.

    Thanks for the help.

    (Also, I am quite new to java and plugin development. So far I have gotten by with Google and these forums, but I am not that great with how to use code and such.)
     
  2. Offline

    r0306

    @ Ryan Johnson
    An entity can refer to non-living entities such as minecarts or paintings and those can’t be assigned potion effects. That’s why you have to convert the entities to LivingEntity before assigning.
    Code:
    public void onZombieSpawn(CreatureSpawnEvent event){
     
    if (event.getEntity() instanceof LivingEntity)
     
    ((LivingEntity)event.getEntity()).addPotionEffect(new PotionEffect(PotionEffectType.SPEED,2147483647, 50));
     
  3. Offline

    Ryan Johnson

    Doesn't seem to work...
    This is what I have:
    Code:
    public void onZombieSpawn(CreatureSpawnEvent event){
            if (event.getEntity() instanceof LivingEntity){           
                ((LivingEntity)event.getEntity()).addPotionEffect(new PotionEffect(PotionEffectType.SPEED,70000, 2));
            }
        }
    I have been changing the numbers after 'SPEED'. As far as I am aware, what I have as '70000' is the duration, and what I have as '2' is strength?
    If I have this wrong please correct me, if this isn't how to change the duration and the strength I may also need some help with that :)
     
  4. Offline

    r0306

    Ryan Johnson
    No, that's right. I'm not sure why it's not working. Maybe try adding this extra boolean to override other potioneffects.
    Code:
     ((LivingEntity)event.getEntity()).addPotionEffect(new PotionEffect(PotionEffectType.SPEED,70000, 2), true);
     
  5. Offline

    TheSmallBones

    Just tried this out. Should there potion bubbles coming off? If so, there isn't.
     
  6. Offline

    r0306

  7. Offline

    TheSmallBones

    Just tried adding speed 4 and they went the same speed as normal. Then added damage increase 3 and still had same damage when they hit me. =/
     
  8. Offline

    Jogy34

    1. Bubbles would still come out of the zombie, I have put a potion effect on a spider before and there were bubbles coming off of it so I don't see why a zombie should be any different
    2. the getEntity method of a CreatureSpawnEvent returns a LivingEntity so there is no need to cast to a LivingEntity
    3. Not all potion effects affect all mobs. I would suggest throwing a speed splash potion at a zombie to see if it speeds it up, if not then the potion probably doesn't work on zombies.
     
    Bavestry likes this.
  9. Offline

    finalblade1234

    ok i did this to my plugin Wolves Elite and EVERY mob had speed...
    help plz
    [EDIT]
    Plz help me make it so they have it 4ever
     
  10. Offline

    phips99

    You can't do it forever (you can type a very long int like 1234567899999999999) and what you mean with every mob?
     
  11. Offline

    Googleholic

    Now guys i know this is late, but this is how i managed to do it

    Code:
    public class Main extends JavaPlugin implements Listener{
     
        public void onEnable(){
        }
       
        public void spawnMOB(Player player){
            Creeper creeper = (Creeper) player.getLocation().getWorld().spawn(player.getLocation(), Creeper.class);
           
            creeper.setCustomName(ChatColor.AQUA + "PuffyCloud");
            creeper.setCustomNameVisible(true);
        }
       
        public void spawnMOB2(Player player){
            Zombie zombie = (Zombie) player.getLocation().getWorld().spawn(player.getLocation(), Creeper.class);
           
            zombie.setCustomName(ChatColor.AQUA + "EvilKnight");
            zombie.setCustomNameVisible(true);
            zombie.setBaby(true);
            zombie.getEquipment().setHelmet(new ItemStack(Material.GLASS));
            zombie.hasPotionEffect(PotionEffectType.INVISIBILITY);
            zombie.getEquipment().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE));
        }
     
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] a) {
            if (cmd.getName().equalsIgnoreCase("Mobs")) {
                Player p = (Player) sender;
                spawnMOB(p);
            }
               
            if (cmd.getName().equalsIgnoreCase("Mobs2")) {
                Player player = (Player) sender;
                spawnMOB2(player);
            }
            return false;
        }
    }
    It might be wrong i am only just learning so lets see how i went thanks guys :)
     
Thread Status:
Not open for further replies.

Share This Page