Max Health above 20?

Discussion in 'Plugin Development' started by Codex Arcanum, Apr 18, 2012.

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

    Codex Arcanum

    Is there any way to set an entity's current/maximum health to more than 20, or do I have to fake it?
     
  2. Offline

    Taco

    I'm pretty sure you have to fake it. If I remember correctly, bukkit doesn't allow values over 20 to be set for health.
     
  3. Offline

    ImminentFate

    you can try this:
    write out an event to give them godmode.
    then make a loop that checks for virtual damage to the player (obviously won't show by itself, because of godmode). You can use a check to see what mob or player hit them, and with what.
    This will be subtracted from an integer of health that you set.
    Play the hurt animation on the target player.
    Send a message to the player saying how many hearts they have left.
    Once their "Virtual Life" hits 20, set them to full health, and disable godmode.
    On their death event, restart the sequence.
    Or, just lessen the damage everything does to people :p
     
  4. Offline

    Codex Arcanum

    See, that's what I was referring to as "faking it", but thanks anyway.
     
  5. Offline

    ImminentFate

    ah right, lol :p
     
  6. Offline

    nisovin

    Bukkit prevents you from setting the health too high, but the server itself doesn't care. You can use reflection to set EntityLiving.health to a value higher than 20. I've done it before and it seems to work fine.
     
  7. Offline

    Codex Arcanum

    Could you explain to me how to go about doing this? I've never used reflection before. Feel free to say no if it's to complicated or lengthy.
     
  8. Offline

    r0306

    Not sure if this works but try it.
    Code:
    public Map<Player, Int> playerHealth = new HashMap<Player, Int>();
     
    @EventHandler
    public void onDamage(EntityDamageEvent event){
    Entity entity = event.getEntity();
    if (entity instanceof Player){
    Player player = (Player) entity;
    playerHealth.put(player, player.getHealth());
    if (player.getHealth() == 20) {
    int health = playerHealth.get(player);
    long healthLong = (long) health;
      if (health > 20){
      int Damage = event.getDamage();
      long DamageLong = (long) Damage;
      long scaleFactorLong = (healthLong / 20) / DamageLong;
      int scaleFactor = (int) scaleFactorLong;
      event.setDamage(scaleFactor);
      playerHealth.put(player, scaleFactor);
      }
    }
    }
    }
    
     
Thread Status:
Not open for further replies.

Share This Page