[Bukkit 1.6.2] Mob spawning amount

Discussion in 'Plugin Development' started by tamajpm, Jul 31, 2013.

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

    tamajpm

    Hello everyone,

    I have a little problem with my new plugin. I want to make a plugin that can spawn mobs on the location that the player stands. I know how to make that, but how i can set the amount that it spawning the mobs. Below the command i want to create:

    /qms {Mobname} {Amount} {Player}

    The first is the mob that it is gonna spawn, the second is the amount and the last is where it is spawning the mobs. But how i can set the amount, that is the question.

    Julian
     
  2. Do you mean you don't know how to spawn a specific amount of mobs?
    Code:
    for (int i = 0; i < amount; i++) //Spawn mob code
    The amount object is an integer that holds the amount of mobs to spawn.

    Or do you mean you don't know how to make it so that you can obtain the amount?
    Code:
    Integer.parseInt(args[1])
    You have to check if args[1] is an integer though.

    Code:
    if (this.isInteger(args[1])) { //Do code }
    Code:
    public boolean isInteger(String aString) {
        try {
            Integer.parseInt(aString);
            return true;
        } catch (Exception ex) {
            return false;
        }
    }
    
     
  3. Offline

    tamajpm

    Is there not a easy way where you can time .setAmount or something? Becouse a doesn't understand the "for" statement.
     
  4. Offline

    Seadragon91

    Code:
    for (int i = 0;i < 5;i++) {
    // the i will have the values: 0,1,2,3,4, that means the code in the loop will run 5 times
    // add here the code to spawn the entity and it will spawn 5 times, change the 5 to 20 then 20 times
    }
    
    For loops are easy to understand, you will need them take a look at it;)
     
  5. Offline

    tamajpm

    Seadragon91 If i change 5 to args[1] it spawns the amount that the player says?
     
  6. Offline

    xTrollxDudex

    tamajpm
    In Seadragon91 's earlier post he explained:
    PHP:
    int amout;
    try{
    amout Integer.parseInt(args[1]);
    }catch(
    NumberFormatException e){
    sender.sendMessage("That is not a valid amount of mobs!");
    Now you can do
    PHP:
    for(int inin =< amountin++){
    //spawn mobs
    }
     
  7. Offline

    tamajpm

    xTrollxDudex
    Is that the same as:

    for(int i = 0; i < Integer.parseInt(args[1]); i++) {}
     
  8. Offline

    Debels

    tamajpm its not the same since a user can pass "cake" as the amount and your plugin would throw an error, so the method troll said is much safer.
     
    tommycake50 and xTrollxDudex like this.
  9. Offline

    tamajpm

    One more question, can i set 1 line of code for the mob spawning and thats take the args[0]??? So i don't need to type every time else if(args[1].equalsIgnoreCase("mobtype")) {
    for(int i = 0; i < amount; i++) {
    player.getWorld().spawnEntity(pLocation, EntityType.MOBTYPE);
    }
    }

    or something?
     
  10. Offline

    Taketheword

    Create a method with every mob type you want spawnable:

    Code:
    public EntityType getType(String mobName){
        if(mobName.equalsIgnoreCase("SPIDER")) return EntityType.SPIDER;
        else if(mobName.equalsIgnoreCase("ZOMBIE")) return EntityType.ZOMBIE;
    }
    Then just do:

    Code:
    EntityType type = getType(args[0]);
    for(int i = 0; i < amount; i++) {
        player.getWorld().spawnEntity(pLocation, type);
    }
    
    EDIT:
    Or you can do just this: (but this requires the player types the Entity name exactly as it is in bukkit.

    Code:
    EntityType type = EntityType.valueOf(args[0]);
    for(int i = 0; i < amount; i++) {
        player.getWorld().spawnEntity(pLocation, type);
    }
    
     
    xTrollxDudex likes this.
  11. Offline

    tamajpm

    Taketheword
    Thanks, but i have a little problem with the EntityType method. If i type it i get the error "missing return statement", becouse this error is showing up i put a "return false" after the last mob define, the iron golem. But if i do that i get the following error: "incopatible types required: org.bukkit.entity.EntityType found: boolean". By the way, i use Netbeans becouse i have one little problem with Eclipse. I fix this very soon, but how i can fix THIS error :p. Already thanks for your reply.
     
  12. Offline

    Taketheword

    tamajpm
    return null;

    But when you go to spawn the mobs use this:

    Code:
    EntityType type = getType(args[0]);
    if(type != null){
        for(int i = 0; i < amount; i++) {
            player.getWorld().spawnEntity(pLocation, type);
        }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  13. Offline

    tamajpm

Thread Status:
Not open for further replies.

Share This Page