Spawning a number of specified Mobs

Discussion in 'Plugin Development' started by Geekhellmc, Aug 23, 2014.

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

    Geekhellmc

    Can someone direct me to how I can spawn a number of specified mobs?
    Ex: Spawn like 10 zombies, 5 creepers and 3 skeletons.
    And is it possible to use a code to then delete all the mobs?
     
  2. Offline

    ulsa

    :)
     
  3. Offline

    Geekhellmc

    ulsa none of them explain how to make it spawn like 10 zombie at once :(
     
  4. Offline

    stoneminer02

    Either copy paste it 10 times or just make a for loop.
    You can also do a while loop.
     
  5. Offline

    Geekhellmc

    Ok, that sounds good.
     
  6. Offline

    ChipDev

    10 zombies, 5 creepers and 3 skeletons:
    Code:java
    1. public void onJoin(PlayerJoinEvent e) {
    2. Player p = e.getPlayer();
    3. Location loc = p.getLocation();
    4. for(int a=0; a < 10; a++) {
    5. p.getWorld().spawn(loc.add(0,3,0), Zombie.class);
    6. }
    7. for(int b=0; b < 5; b++) {
    8. p.getWorld().spawn(loc.add(0,3,0), Creeper.class);
    9. }
    10. for(int c=0; c < 3; c++) {
    11. p.getWorld().spawn(loc.add(0,3,0), Skeleton.class);
    12. }
    13. }

    I really wanted to get 'C++' in there :p
    On join: Spawn 10 zombies, 5 creepers, and 3 skeles overhead.
     
    KingFaris11 likes this.
  7. Offline

    unon1100

    ChipDev Examined the code, it won't work as you expect it to. You don't clone the location object before using the .add() method, and therefore every time you call the method it will add ANOTHER 3 blocks to the location.
    A better way to do this is by creating a location, and set it equal to p.getLocation().clone().add(0,3,0);
    When spawning the entity, do getWorld().spawn(loc, class);
     
    KingFaris11 likes this.
  8. Offline

    aredherring

    I was about to correct you and then realized that `Location` is not immutable and does actually work exactly like that.
    That's batshit retarded.

    [​IMG]
     
    hintss and KingFaris11 like this.
  9. Offline

    unon1100

  10. Necrodoom (Y)
     
    ChipDev likes this.
  11. Offline

    ChipDev

    unon1100 aredherring Oh jeez. I understand why... I made the location outside of all the 3. I've never used more than one loop :p
     
  12. Offline

    Necrodoom

    ChipDev need i put a remainder on why spoonfeeding is bad again? Because I think I already explained it to you several times.
     
    KingFaris11 likes this.
  13. Offline

    ChipDev

    Yes, you have... but that was the base idea.
     
  14. Offline

    Geekhellmc

    I did not actually needed spoon feed because I don't like loops XD I just did copy pasting and some changes and worked well. Necrodoom never spoon feed the hungry :p
     
  15. Base idea that is practically the idea.
    Better way would be in English, like so:
    Code:
    > Store local player object
    > Store local location of the player
    > For loop from 0 to amount spawned
        > Spawn entity 3 blocks above the local location using the add() method.
    
     
Thread Status:
Not open for further replies.

Share This Page