Solved How to spawn a mob?

Discussion in 'Plugin Development' started by austinv11, Mar 28, 2014.

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

    austinv11

    Note: I'm relatively new plugin development, so please go easy on me

    So I want to take the relative coords of the player and spawn a "boss" mob (as in customized potion effects and equipment) around 25 blocks away.

    Thanks for your help!
     
  2. Offline

    2MBKindiegames

    Hi there,

    WELCOME TO BUKKIT!

    First off all, to solve this problem, you need to provide a bit more information. Like WHEN you want that to happen, or what kind of mob. Here's an example of a code wich will spawn a Zombie with Gold Chestplate and Diamond Sword when the player types: "/command"

    Code:java
    1. @EventHandler
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    3. if (cmd.getName().equalsIgnoreCase("command")) {
    4. if (sender instanceof Player) {
    5. Player player = (Player) sender;
    6. World world = player.getWorld();
    7. Location loc = player.getLocation().clone();
    8. loc.add(-25+(int)(Math.random()*25), 0, -25+(int)(Math.random()*25));
    9. LivingEntity entity = (LivingEntity) world.spawnEntity(loc, EntityType.ZOMBIE);
    10. EntityEquipment ee = entity.getEquipment();
    11.  
    12. ItemStack chestplate = new ItemStack(Material.GOLD_CHESTPLATE);
    13. ee.setChestplate(chestplate);
    14.  
    15. ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
    16. ee.setItemInHand(sword);
    17. }
    18. }
    19. return false;
    20. }
     
    _Yooxa_ likes this.
  3. Offline

    AmbaDev

    2MBKindiegames
    I see you do exelent job telling people your code for their own help, bu I think you should add notes to what ech line does, or tell him what to do with words, because this is like TheBCBroz, who just writes the code, and expects us to understand what we are doing, but we actually only know how to do what he just did.
     
  4. Offline

    Maurdekye

    AmbaDev and the funny thing is, that even with the confusing way he explains it, to someone experienced enough to understand it he really doesn't know what he's doing at all, and seems like he's trying to act cool by typing really fast and explaining things minimally.
     
  5. Offline

    2MBKindiegames

    AmbaDev
    Yeah, I myself am very good at 'unwriting' code (= Extracting from the context what it does) but you're probably right.

    Here's a commented version:
    Code:java
    1. @EventHandler
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    3. if (cmd.getName().equalsIgnoreCase("command")) {
    4. if (sender instanceof Player) {
    5. //Gets the player and the world he's in
    6. Player player = (Player) sender;
    7. World world = player.getWorld();
    8. //Get the player location
    9. //NOTE: The ".clone()" must be there when working with Locations!
    10. Location loc = player.getLocation().clone();
    11. //Makes the location a bit random
    12. loc.add(-25+(int)(Math.random()*25), 0, -25+(int)(Math.random()*25));
    13. //Preparing for adding items
    14. LivingEntity entity = (LivingEntity) world.spawnEntity(loc, EntityType.ZOMBIE);
    15. EntityEquipment ee = entity.getEquipment();
    16.  
    17. //Adding chestplate
    18. ItemStack chestplate = new ItemStack(Material.GOLD_CHESTPLATE);
    19. ee.setChestplate(chestplate);
    20.  
    21. //Adding weapon (Can be anything!)
    22. ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
    23. ee.setItemInHand(sword);
    24. }
    25. }
    26. return false;
    27. }
     
  6. Offline

    austinv11

    Thanks guys! I think this is more than enough, I'm not completely stupid so I think I can modify this code to work with me.
     
  7. Offline

    2MBKindiegames

    austinv11
    You're very welcome! If you need any more help, just PM me or create a new topic!
    PS: Nobody said you were stupid!
     
Thread Status:
Not open for further replies.

Share This Page