A complex problem with Quests

Discussion in 'Plugin Development' started by wydgabriel, Nov 20, 2016.

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

    wydgabriel

    Hello guys.
    Before any question, I have to say that Im brazilian and Im sorry about my bad english.
    So, Im developing a MMORPG server and Im having some problem with Quests plugin.
    https://www.spigotmc.org/resources/quests.3711/.
    Im making some quests with ''Kill Mob Objective'', and I coded some skills/abilities to kill monsters like fire serpent,meteor and so.
    Well, in some part of the code (DAMAGE), I have this:

    Code:
     
    dealDamage(p, z, dano, EntityDamageEvent.DamageCause.CUSTOM);
    
    where P is player damager (skill), z is LivingEntity, and Dano the damage double.

    So, dealDamage method:
    Code:
    EntityDamageByEntityEvent dmgEvent = new EntityDamageByEntityEvent(damager, damaged, cause, damage);
            Bukkit.getServer().getPluginManager().callEvent(dmgEvent);
    
    And then the method EntityDamageByEntityEvent (Custom cause):
    Code:
                    if (z.getHealth() - dano <= 0) {
                        e.setDamage(0.1);
                        z.damage(z.getHealth());
    
                    } else {
                        z.setHealth(z.getHealth() - dano);
                        e.setDamage(0.1);
    
                    }
    
    
    Note: that method is to prevent vanilla armor damage reduction.

    So, with that damage method, when I kill Quests objetive mobs, they dont count.
    My method with sword attacks is the same, but the cause is other, and it works!

    Someone knows how to fix that?

    Thanks guys!
     
  2. Offline

    Zombie_Striker

    @wydgabriel
    You can't just call your own method. Bukkit uses its event to get all the information it needs for events/ scoreboards, stats, ect. The way bukkit checks if you killed an entity is it sees if the entity's health minus the damage is less than 0. What you need to do is check if the health - damage will be less than 0, and if so, let bukkit work the way it should. If that is the case, don't change the health and damage values.

    Also, don't call that event. Instead, let bukkit dictate whether a player actually hit an entity.
     
  3. Offline

    wydgabriel

    Thanks for your answer!
    The ''dano'' variable is not the default event damage, I have to call z.damage(dano) otherwise LivingEntity will just receive the default damage of the event.
     
  4. Offline

    wydgabriel

  5. Offline

    Zombie_Striker

    @wydgabriel
    That's the thing; you cannot use your method when the entity dies. Just make to only use that method if the entity will not be killed by the damage. If it will die, let bukkit handle the event.
     
Thread Status:
Not open for further replies.

Share This Page