[help] with custom monster spawn function

Discussion in 'Plugin Development' started by gummby8, Feb 24, 2012.

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

    gummby8

    So I am trying to write a function for a plugin called dungeonbuilder. You can create custom mobs that will spawn on a called event inside your dungeon. Currently I have figured out how to get a spider to shoot fireballs at a player using the following code
    Code:
    importPackage(java.lang);
    importPackage(org.bukkit.inventory);
    importPackage(org.bukkit);
    importPackage(org.bukkit.entity);
    importPackage(org.bukkit.util);
    importPackage(org.bukkit.craftbukkit.entity);
     
    function monster_spawn()
    {
        //How do we make a monster with a ton of health?  Do negative damage to it!
        //A bit counterintuitive but very easy to do.
        monster.damage(-80);
     
        startingloc = monster.getLocation().clone();
     
        thread = new Thread(function() {
            while(true)
            {
                if(monster.isDead())
                    return;
     
                if(Thread.currentThread().isInterrupted())
                    return;
     
     
                sleep = (Math.random() * 2000) + 1500;
     
                try
                {Thread.currentThread().sleep(sleep);
     
               
                    if(monster.getTarget() == null)
                        continue;
     
                   
                        world = monster.getWorld();
                        loc = monster.getLocation();
                        fireball = world.spawn(loc, org.bukkit.entity.Fireball); //Delete this line and the line after if you dont want to spawn a fireball
                        fireball.setShooter(monster);
     
                }
                catch(e)
                {
                    if(e.javaException instanceof InterruptedException)
                        return;
     
                    e.javaException.printStackTrace();
                    return;
                }
            }
        });
        thread.start();
        persistedObjects.put(monster.getUniqueId() + "thread", thread);
        persistedObjects.put(monster.getUniqueId() + "start", startingloc);
    }
       
     
     
     
     
     
    function monster_death()
    {
        world = monster.getWorld();
     
     
        //Spawn an item at the monster's location when he dies
        is = new ItemStack(Material.FIRE, 1);
        world.dropItem(monster.getLocation(), is);  //Delete this line if you dont want to spawn an item when it dies
     
     
    }
     
    function monster_damage()
    {
        world = monster.getWorld();
        //Make a ghast shrieking sound
        world.playEffect(monster.getLocation(), Effect.GHAST_SHRIEK, 0);
     
    }
    The spider spawns, shoot fireballs properly every 3ish seconds, drops an item when it dies, and screams like a ghast when it is harmed.

    My biggest concern now is spawning these special spiders in groups. Eventually, due to friendly fire, they all turn on each other. What I need help with is two things:

    1) I would like my custom mob to be immune to the fireball explosion event which I believe is referenced here http://jd.bukkit.org/doxygen/d1/d9c/EntityDamageEvent_8java_source.html
    I am not sure how to listen for that event and cancel it if it occurs, if that is even how I should go about it.

    2) I would also like to see if I could make the custom monster reset its target whenever it's target is not a player, thus eliminating quarrels between each other. Which I have no clue where to even start
     
  2. Offline

    stelar7

    1) EntityDamageByEntityEvent, check if the damager is a fireball and if the entity is the custom mob, if so, cancel the event

    2) check if the target is not a player, if so, set the target to null
     
  3. This is not java
     
    billofbong likes this.
  4. Offline

    billofbong

    Is that... JavaScript?
     
  5. Offline

    gummby8

    yes it ends up in a .js file
     
  6. Well, it doesn't need to be javascript when the ending is .js. It just tells the program what data IS EXPECTED. You could store a picture in a .txt file, but programs will not except a picture in a blank text file.
    This is just a little info.
     
  7. Offline

    billofbong

    Why is it JavaScript? The bukkit API is in Java. Explain please?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  8. Offline

    gummby8

    I didn't make the plugin, I am just using the tools the dev gave me. His plugin calls the .js file to modify spawned monsters.
     
Thread Status:
Not open for further replies.

Share This Page