Damage Modification

Discussion in 'Plugin Development' started by Jakesully123456, May 23, 2015.

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

    Jakesully123456

    Hello,
    I am writing a simple damage modification plugin, and I have 2 questions. How do I determine the item in hand of a non-player living entity (i.e. a zombie)? Additionally, how do I modify the health of every livingentity in a world?
     
  2. Offline

    I Al Istannen

  3. Offline

    Jakesully123456

    @I Al Istannen
    Thanks, now my second question, how do I change the default health value for a certain type of mob?
    For example, I want all creepers to have 80HP.
     
    Last edited: May 23, 2015
  4. Offline

    I Al Istannen

  5. Offline

    Zombie_Striker

    @I Al Istannen
    No, that just sets the max health, not their actual health
    @Jakesully123456
    Cast the entity to a Damageable and set their Health using .setHealth() and their max health using .setMaxHealth();.
     
  6. Offline

    Jakesully123456

    @Zombie_Striker @I Al Istannen
    That is not the issue. I know how to set the health, I need a method to ensure that all mobs are given the appropriate health value. Can I set it on mob spawn, should I schedule. Repeating event to constantly set all entities per world to have more health? I need a method to ensure all mobs are at the modified health value.
     
  7. Offline

    567legodude

    @Jakesully123456 I know that there is an event for mob spawns, so just use that event, and then used the methods mentioned above to set their health the way you want to.
     
  8. Offline

    Zombie_Striker

    @Jakesully123456
    Code:
    public void onEnable(){
    for(World wo: getServer().getWorlds()){
    for(Entity e : wo.getEntities()){
    // set health
    }
    }
    }
     
  9. Offline

    I Al Istannen

    @Zombie_Striker You do know, that most certainly (except reloads) no chunks will be loaded at the onEnable()? Afaik this won't do anything then.

    @Jakesully123456
    You would have to either check with the spawn event or the ChunkLoad event. But again, at the moment the ChunkLoad event is called, no entites are in the chunk. I had that iussue before. You would need to wait a tick before scanning the chunk from the chunkLoadEvent.

    ChunkLoadEvent: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/world/ChunkLoadEvent.html
    CreatureSpawnEvent: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/entity/CreatureSpawnEvent.html
    And you need to set the max health before, read this: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/Damageable.html#setHealth(double)
    and after that set the health.
     
  10. Offline

    Jakesully123456

    Any other ways to do it?
     
  11. Delete the world, put your plugin and create a new one .
     
  12. Offline

    Jakesully123456

    @MaTaMoR_ that, for many reasons is not possible. I'll manage it through chunk load events.
     
Thread Status:
Not open for further replies.

Share This Page