Run combat

From Kolmafia
Jump to navigation Jump to search

Function Syntax

buffer run_combat()

buffer run_combat(string filter )

  • filter is a macro or the name of a combat filter function defined elsewhere in your script, with the same behavior as in the 3-paramater version of adventure(). An empty string can be passed to use your battle action or CCS as normal. Essentially, this allows the scripter to put a CCS or macro into a script.

Proceeds to run a combat using your current KoLmafia settings. This function returns the HTML from the final round of combat (not just what is displayed, but all markup). Most commonly used to finish up combats started via visit_url().

Another handy use for this function is to finish up combats that were started in the relay browser, or were interrupted (causing mafia to pop up the minibrowser). Typing "ashq run_combat()" into the CLI will finish up the combat for you using your current CCS/battle action. Note that "ashq" is necessary rather than "ash" to avoid spewing the entire combat results page into the CLI.

Code Sample

This is a personalized version of adv1() that is capable of returning information about which adventure is encountered so that you can look for a specific choice adventure. If a combat is encountered instead of a choice adventure, run_combat() is used.

int run_adv(location place) {
   string page_text = to_url(place).visit_url();
   string choiceAdventure = "-1";
   matcher m_choice = create_matcher("whichchoice value=(\\d+)", page_text);
   while(page_text.contains_text("choice.php")) {
      choiceAdventure =;
      string choice_num = get_property("choiceAdventure"+ choiceAdventure);
      if(choice_num == "0") abort("Manual Control for "+ choiceAdventure);
      if(choice_num == "") abort("Unsupported Choice Adventure!");
      page_text = visit_url("choice.php?pwd&whichchoice="+ choiceAdventure +"&option="+ choice_num);
   return choiceAdventure.to_int();

See Also

adventure() | adv1() | visit_url() | run_choice() | run_turn()


Will return the text of the last combat encounter when called independently of a fight page.

Using run_combat() to execute fights will not do the normal post-fight processing that mafia normally performs with adv1 or adventure.

  • it will not cause your afterAdventureScript to run
  • it will not trigger post-combat restoration
  • it will not check if adventuring goals have been met
  • it does not obey counter aborts (e.g. fortune cookie)
  • it does not update mafia's custom quest progress properties (e.g. palindomeDudesDefeated)