Getting playeffect() to work

Discussion in 'Plugin Development' started by kabbage, Jun 10, 2012.

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

    kabbage

    I've been trying to use the playeffect() method to create a visual effect around an entity, but can't produce any results whatsoever. I don't even get an error message, simply nothing happens.

    Could someone post code that uses playeffect() to create any type of visual effect on an entity? I simply can't figure out how to do it.
     
  2. Offline

    Suprem20

    Simple method to play an effect:

    Code:
        public void playEffect (Location loc) {
           
            World world = loc.getWorld();
            world.playEffect(loc, Effect.GHAST_SHRIEK, 5);
        }
     
  3. Offline

    kabbage

    I need to get a visual effect to work, though. Not a sound. Using a visual effect with that code produces nothing.
     
  4. Offline

    Suprem20

    Change the effect type? Effect.(something else)
     
  5. Offline

    kabbage

    I've tried that
    public void playEffect (Location loc) {

    World world = loc.getWorld();
    world.playEffect(loc, Effect.MOBSPAWNER_FLAMES, 5);
    }

    Nothing happens with Effect.SMOKE and Effect.ENDER_SIGNAL either.

    No effect is produced.
     
  6. Offline

    Suprem20

    Well, when are you calling the method?
     
  7. Offline

    kabbage

    I have it in a repeating task that runs every second, which is in onEnable()
    It runs for all entities on the server, or should, anyway.
     
  8. Offline

    Suprem20

    Post the code please...
     
  9. Offline

    kabbage

    Code:
    getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
        @Override
        public void run() {
            List<World> ws = getServer().getWorlds();
            List<Entity> ents = ws.get(0).getEntities();
            for(int i = 0; i < ents.size(); i++) {
            Entity entity = ents.get(i);
            Location loc = entity.getLocation();
            entity.getWorld().playEffect(loc, Effect.MOBSPAWNER_FLAMES, 0, 50);
            entity.getLocation().getBlock().setType(Material.FIRE);
            }
        }
    }    
    Multiple numbers have been tried in the 3rd and fourth paramaters.
    The line that places fire under the entity is there to confirm that the code is finding the entities in the server.
     
  10. Offline

    Suprem20

    Is the fire being placed but not the effect? If so, you only run the task once on server startup, I'd recommend looking at this: Link!
     
  11. Offline

    Adamki11s

    From the api docs

    Some effects don't need data so I think that param can sometimes be discarded, see below.

    As you can see your radius of 50 is probably too large so you are not seeing the events. I would recommend setting the radius, 4th param to about 2 or 3 and leave the 3rd parameter, data as 0, and then change if needed.

    This is how I successfully create a smoke effect in my Warzone plugin.

    Code:
    w.playEffect(new Location(w, x, y, z), Effect.SMOKE, 10);
    If you want to see the entire class : https://github.com/Adamki11s/Warzon.../Adamki11s/Warzone/WarzonePlayerListener.java
     
  12. Offline

    Suprem20

    I dun goof?
     
  13. Offline

    Adamki11s

    Huh?
     
  14. Offline

    kabbage

    The fire is placed constantly, wherever the entity is, fire is created underneath it. It's not only being run at server start up.
    I tried a few more tries with different parameters, including the ones you posted, and still get no effect.

    Code:
    getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                    List<World> ws = getServer().getWorlds();
                    List<Entity> ents = ws.get(0).getEntities();
                    for(int i = 0; i < ents.size(); i++) {
                    Entity entity = ents.get(i);
                    Location loc = entity.getLocation();
                    entity.getWorld().playEffect(loc, Effect.MOBSPAWNER_FLAMES, 0, 2);
                    entity.getWorld().playEffect(loc, Effect.MOBSPAWNER_FLAMES, 2, 2);
                    entity.getWorld().playEffect(loc, Effect.MOBSPAWNER_FLAMES, 2);
                    entity.getWorld().playEffect(loc, Effect.SMOKE, 10);
                    }
                }
            }, 0L, 5L);
     
  15. Offline

    Suprem20

    Were my explanations adequate to the resolution of this gentleman's problem?
     
  16. Offline

    Adamki11s

    I don't know you'll have to ask him :p. It never hurts to have more information though.
     
  17. Offline

    ferrybig

    getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
    Thats wrong, causes bugs, use

    getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {

     
    Ne0nx3r0 and V10lator like this.
  18. Offline

    kabbage

    It doesn't cause any noticeable bugs for me. I tried changing it to what you suggested, regardless, and it still doesn't produce any effect...
     
  19. Make sure you have particles turned on in your minecraft settings. I had forgotten it
     
  20. Offline

    fireblast709

    minecraftcookiefan This thread is dead for over three years now, please let it rest in peace :p.
     
  21. Offline

    SleepyDog

    Look at the date before you comment :p
     
  22. lol didn't notice
     
Thread Status:
Not open for further replies.

Share This Page