Difference between revisions of "Monster hp"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
(Created page with '{{ #vardefine:name|monster_hp}}{{ #vardefine:return_type|int}}{{ FunctionPage| name={{#var:name}}| function_category=Adventuring| second_category=In-combat Consulting| function…')
 
imported>Eliteofdelete
 
(9 intermediate revisions by 5 users not shown)
Line 5: Line 5:
 
FunctionPage|
 
FunctionPage|
 
name={{#var:name}}|
 
name={{#var:name}}|
function_category=Adventuring|
 
second_category=In-combat Consulting|
 
  
 
function1={{Function|
 
function1={{Function|
Line 23: Line 21:
 
p1desc={{Pspan|check_me}} is the (optional) monster to get the HP of|
 
p1desc={{Pspan|check_me}} is the (optional) monster to get the HP of|
 
}}|
 
}}|
function_description=Returns the HP of the specified monster {{pspan|check_me}}. If {{pspan|check_me}} is not specified, it defaults to the last monster you encountered. This function adjusts for know effects (such as monster level modifications).</p>
+
function_description=Returns the HP of the specified monster {{pspan|check_me}}. If {{pspan|check_me}} is not specified, it will return the HP of the current monster if you are in a fight (i.e. you're calling the function from an [[In-combat Consulting]] script), or the HP of the last monster you encountered otherwise.  If you are in a fight, this will return the monster's current HP to the best of KoLmafia's knowledge.</p>
<p>This function can be used from within an [[In-combat Consulting]] script to help determine your fight strategy. When used this way, it isn't necessary to specify a monster, as the function will default to the one currently being fought. It will update the information returned each time it is called, to the best of KoLmafia's knowledge.|
+
<p>The return value includes monster level modifications.  This means that for monsters with unknown HP, the return value will initially be equivalent to monster_level_adjustment().</p>
 +
<p>If you want to know the monster's raw HP without being modified by monster level adjustments, it is available through the monster.'''raw_hp''' proxy field.|
  
needscode=yes|
+
code1={{CodeSample|
 +
title=Code Samples|
 +
description=Following code is a simplified function of weapon damage. It will tell how many rounds it takes to kill a monster based on its HP.|
 +
code=
 +
<syntaxhighlight>
  
see_also={{SeeAlso|monster_attack|monster_defense}}|
+
void kill (string monstername) {
 +
  monster mon = to_monster(monstername);
 +
  int hp = monster_hp(mon);
 +
  int def = max(0, monster_defense(mon));
 +
  int weaponstat = buffed_hit_stat();
 +
  int total_dmg;
 +
  string rounds;
 +
  float weapon_multi, weapon_dmg, elemental_dmg;
 +
  if (current_hit_stat() == $stat[moxie] && item_type(equipped_item($slot[weapon])) != "knife")
 +
      weapon_multi = .75;
 +
  else weapon_multi = 1.0;
 +
  weapon_dmg = numeric_modifier("weapon damage");
 +
  foreach it in $elements[]{
 +
      string dmg = it+" damage";
 +
      elemental_dmg += numeric_modifier(dmg);
 +
  }
 +
  total_dmg = floor((weaponstat*weapon_multi)-def+weapon_dmg+elemental_dmg);
 +
  total_dmg = max(0, total_dmg);
 +
  if (total_dmg > 0)
 +
      rounds = to_string(max(1, round(hp/total_dmg)));
 +
  else rounds = "infinity";
 +
  print("Your expected damage on "+mon+" is "+total_dmg+". Assuming you always hit, it will take "+rounds+" round(s) to kill "+mon+".", "blue");
 +
}
 +
kill("bar");
 +
</syntaxhighlight>|
 +
moreinfo=
 +
Note: The example does not take crits/fumbles/hit chances into account. For more information on weapon damage see [http://kol.coldfront.net/thekolwiki/index.php/Weapon_Damage Weapon Damage].
 +
}}|
 +
 
 +
see_also={{SeeAlso|monster_attack|monster_defense|monster_initiative|monster_element}}|
 
more_info=For the current discussion of what's being tracked in-combat for monster level adjustments, please see [http://kolmafia.us/showthread.php?3452 this thread].|
 
more_info=For the current discussion of what's being tracked in-combat for monster level adjustments, please see [http://kolmafia.us/showthread.php?3452 this thread].|
special=When not logged in, this function returns 0 if no monster is specified.|
+
special=If no monster is specified and no monster has been fought in this session, this function returns 0. This is because mafia forgets the value of {{f|last_monster}} when it logs out.|
 
}}
 
}}
{{RFI|Is the information about the self-updating nature of the return value correct?|Is the not-logged-in value correct?}}
+
 
 +
[[Category:Adventuring]][[Category:In-combat Consulting]]

Latest revision as of 03:10, 13 September 2019

Function Syntax

int monster_hp()

int monster_hp(monster check_me )

  • check_me is the (optional) monster to get the HP of

Returns the HP of the specified monster check_me. If check_me is not specified, it will return the HP of the current monster if you are in a fight (i.e. you're calling the function from an In-combat Consulting script), or the HP of the last monster you encountered otherwise. If you are in a fight, this will return the monster's current HP to the best of KoLmafia's knowledge.

The return value includes monster level modifications. This means that for monsters with unknown HP, the return value will initially be equivalent to monster_level_adjustment().

If you want to know the monster's raw HP without being modified by monster level adjustments, it is available through the monster.raw_hp proxy field.

Code Samples

Following code is a simplified function of weapon damage. It will tell how many rounds it takes to kill a monster based on its HP.

void kill (string monstername) {
   monster mon = to_monster(monstername);
   int hp = monster_hp(mon);
   int def = max(0, monster_defense(mon));
   int weaponstat = buffed_hit_stat();
   int total_dmg;
   string rounds;
   float weapon_multi, weapon_dmg, elemental_dmg;
   if (current_hit_stat() == $stat[moxie] && item_type(equipped_item($slot[weapon])) != "knife")
      weapon_multi = .75;
   else weapon_multi = 1.0;
   weapon_dmg = numeric_modifier("weapon damage");
   foreach it in $elements[]{
      string dmg = it+" damage";
      elemental_dmg += numeric_modifier(dmg);
   }
   total_dmg = floor((weaponstat*weapon_multi)-def+weapon_dmg+elemental_dmg);
   total_dmg = max(0, total_dmg);
   if (total_dmg > 0)
      rounds = to_string(max(1, round(hp/total_dmg)));
   else rounds = "infinity";
   print("Your expected damage on "+mon+" is "+total_dmg+". Assuming you always hit, it will take "+rounds+" round(s) to kill "+mon+".", "blue");
}
kill("bar");

Note: The example does not take crits/fumbles/hit chances into account. For more information on weapon damage see Weapon Damage.

See Also

monster_attack() | monster_defense() | monster_initiative() | monster_element()

More Information

For the current discussion of what's being tracked in-combat for monster level adjustments, please see this thread.

Special

If no monster is specified and no monster has been fought in this session, this function returns 0. This is because mafia forgets the value of last_monster() when it logs out.