spawning a monster in a specific location

Discussion in 'Plugin Development' started by nitrousspark, Sep 22, 2012.

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

    nitrousspark

    how do i do this?
    i have world.spawnEntity(null, EntityType.ZOMBIE);
    and i know that i cant put null in there but how would i put coordinates
     
  2. Offline

    kyle1320

    nitrousspark
    Code:
    world.spawnEntity(new Location(world, x, y, z), EntityType.ZOMBIE);
     
    Kodfod likes this.
  3. Offline

    LemonBro3

    kyle1320

    I have this code
    Code:
    player.getWorld().spawnEntity(playerLocation, EntityType.VILLAGER);
    Obviously 'playerLocation' is the player's location, but when I test it, all it does is spawn the Villager for less than a second and it'll disappear. Any ideas?
     
  4. Offline

    Kodfod

  5. Offline

    CarPet

    Does anyone feel like supplying some code of how to detect what coords you enter for example /zombie x y z so that would do whatever coords you put in and spawn a zombie?

    Thanks if you try
     
  6. Kodfod spawnCreature() is deprecated and nothing more than a wrapper for spawnEntity()
    https://github.com/Bukkit/CraftBukk...a/org/bukkit/craftbukkit/CraftWorld.java#L313

    LemonBro3 Maybe another plugin removes it instantly?

    CarPet Pseudocode, yes:
    Code:
    on command do
        if the one executing the command is not a player
            exit
        if length of arguments is higher than 2 do
            try the following
                int x = Integer.parseInt(args[0]); //This is the only line of real Java code in that example!
                int y is the parsed arg 1
                int z is the parsed arg 2
            if we had a NumberFormatException while trying
                tell the player how to use the command
                exit
            World world is the world the player is in
            Location loc is a new location based on the world, x, y and z
            if the chunk at the location isn't loaded
                load the chunk at the location
            spawn a zombie at loc
        else
            tell the player how to use the command
     
    Kodfod likes this.
  7. Offline

    CarPet

    Real code please I am noob in this area... :p
     
  8. Offline

    Kodfod

    Here is what he told you to do. You can not copy and paste. =P


    [​IMG]



    Fixed picture and code...
     
    chasechocolate and V10lator like this.
  9. Kodfod But you mixed up Location loc and spawn. Also the if/else for chunk loading is a bit weird. I re-wrote that part (ignore the red underlining, lazy... :p):
    [​IMG]
     
  10. Offline

    Kodfod


    i just caught that while you posted that i fixed the picture above with fixed code =P

    Edit: Yes i re-wrote the code and left out the if(cmd.getName()......) stuff but they can figure out to put that in the right spot

    Edit 2: Nah Went back and helped them out with the pic being fixed
     
  11. Kodfod Well, the if/else is still weird. It's basically duplicated code except for the chunk loading line. That's why my fix has only that part in the if. ;)
     
  12. Offline

    Kodfod

    kk will do it your way =P
     
  13. Offline

    LemonBro3

    V10lator
    Thanks for the help! Now I just have to find out which plugin is interfering.
     
  14. Offline

    CarPet

    I am noobing it up, how would you make it to where they can set how many they want to spawn and what mob?
     
  15. Offline

    AstramG

    For the amount, I don't know any actual code of doing this (since I'm new to scripting), but you can make a loop of the command for an argument which will be how many interval's it computes the command.
     
  16. Offline

    Sabersamus

    Code:java
    1.  
    2. int i = args[number];
    3. int amount = 0;
    4. while(amount < i){
    5. //spawn creature;
    6. amount++;
    7. }


    Should work
     
  17. Sabersamus args[number] is a String, you can't cast a String to a int. This should work:
    Code:java
    1. try
    2. {
    3. for(int i = 0; i < Integer.parseInt(args[number]); i++)
    4. {
    5. //spawn creature;
    6. }
    7. }
    8. {
    9. sender.sendMessage(ChatColor.RED+args[number]+" isn't a valid number");
    10. }
     
  18. Offline

    Sabersamus

    Yeah I know that, I was just half asleep, sorry
     
Thread Status:
Not open for further replies.

Share This Page