Spawning Mobs Without Armor

Discussion in 'Spigot Plugin Development' started by floory565, Aug 2, 2016.

  1. floory565

    Moderator

    Hey all,

    Suppose I have set up a command (eg. /spawnskeleton) that spawns a skeleton. As with the natural spawning of Skeletons, there is a random chance that the Skeleton I spawn will be equipped with armor (eg. gold chest piece). How would I make it so that the Skeleton I spawn is guaranteed to spawn WITHOUT armour?

    P.S. I have an idea that involves setting the equipment slots (helmet, chestplate, leggings, boots) of the Skeleton to null, but I am unable to test this right now.

    Any ideas?

    Thanks!
     
  2. I don't think world.spawn() or world.spawnEntity() spawns an entity with a chance of them having armor on. Though if this is the case, your idea of setting their armor contents to null should work.
     
  3. Can't you change make separate commands. For example, you have one that spawns just the regular skeletons, the. You have the other command one that spawns them with a random chance with armor.


    Sent from my iPhone using Tapatalk
     
  4. Listen to creature spawn event if its a skeleton or whatever mob, check if it has armor, if so remove armor
     
  5. floory565

    Moderator

    From my experience it has. When setting to null, there is sometimes a chance it will spawn with armor, but if I move away and out of sight, then return to the mob, the armor is gone. Weird.
    Even though it spawns a regular skeleton, there is a chance it spawns with armor. I need to make sure that it doesn't.
    I'd probably create my own method that checks if the mobs spawned using the command have any unwanted armor. I guess that would work.
     
  6. Setting its armor contents to null should do the job. Have you tried setting each one individually, like the following?
    Code (Java):

    skeleton.getEquipment().setHelmet(null);
    skeleton.getEquipment().setChestplate(null);
    skeleton.getEquipment().setLeggings(null);
    skeleton.getEquipment().setBoots(null);
     
     
  7. floory565

    Moderator

    Yes, and the following happens:
     
  8. That's strange. I'm not sure if this would work, but have you tried setting the armor contents to null at least 1 tick after the entity spawned?
     
  9. floory565

    Moderator

    I haven't, but as soon as I'm able to (about 4 hours from now), I'll definitely give that a try.
     
  10. .setHelmet(new ItemStack(Material.AIR)) works for me.
     
  11. floory565

    Moderator

    If I were to spawn a large number of skeletons with all equipment slots set to air, would there be a noticeable difference in terms of lag as opposed to normal skeletons?
     
  12. I don't think so, but if it does try the other things that were said. I guess if you are still experiencing issues setting it to air, you can just kill it if it spawns with armor lol.
     
  13. I think skeletons have hidden armor these days... and AimBot. :mad:
     
  14. floory565

    Moderator

    I can vouch for aimbot.
     
    • Agree Agree x 1
  15. To solve aimbot, just change the velocity of the vector when they shoot to be straight up!
     
  16. How about skeleton.remove()? Or even better:
    Code (Java):

    @EventHandler
    public void onSpawn(EntitySpawnEvent event)
    {
        Entity e = event.getEntity();

        if (e.getType() == EntityType.SKELETON)
        {
            for (int rage = 500; rage > 0; rage--)
            {
                e.getWorld().createExplosion(e.getLocation(), rage);
            }
        }
    }
     
    That will solve all of your problems.
     
    • Winner Winner x 2
    • Informative Informative x 1
    • Useful Useful x 1