Run combat: Difference between revisions
Jump to navigation
Jump to search
imported>StDoodle Created page with '{{ #vardefine:name|run_combat}}{{ #vardefine:return_type|buffer}}{{ FunctionPage| name={{#var:name}}| function_category=Adventuring| function1={{Function| name={{#var:name}}| a…' |
imported>Bale answered RFIs and provided AWESOME code sample that explains how and when to use it. |
||
Line 14: | Line 14: | ||
}}| | }}| | ||
function_description=Proceeds to run a combat using your current KoLmafia settings. This function returns the | function_description=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). For use with ''[[visit_url|visit_url()]]'' to handle combats that are initiated during a page load.| | ||
code1={{CodeSample| | |||
title=Code Sample| | |||
description=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.| | |||
code= | |||
<syntaxhighlight> | |||
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")) { | |||
m_choice.reset(page_text); | |||
m_choice.find(); | |||
choiceAdventure = m_choice.group(1); | |||
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); | |||
} | |||
if(page_text.contains_text("Combat")) | |||
run_combat(); | |||
return choiceAdventure.to_int(); | |||
} | |||
</syntaxhighlight>}}| | |||
see_also={{SeeAlso|adventure|adv1|visit_url}}| | see_also={{SeeAlso|adventure|adv1|visit_url}}| | ||
Line 22: | Line 47: | ||
special=Will return the text of the last combat encounter when called independently of a fight page.| | special=Will return the text of the last combat encounter when called independently of a fight page.| | ||
}} | }} | ||
Revision as of 06:37, 22 March 2010
Function Syntax
buffer run_combat()
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). For use with visit_url() to handle combats that are initiated during a page load.
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")) {
m_choice.reset(page_text);
m_choice.find();
choiceAdventure = m_choice.group(1);
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);
}
if(page_text.contains_text("Combat"))
run_combat();
return choiceAdventure.to_int();
}
See Also
Special
Will return the text of the last combat encounter when called independently of a fight page.