farm script won't finish combat

Hi, I'm fairly new to KoL and very new to scripting, but I love KoL and am having fun trying to write simple scripts. I want to thank all of you for your very useful scripts and especially the developers for this great program!!

I am having a few problems with a couple of scripts I've been trying to write. :(

I'm running Windows XP SP2, Java 1.6.0_11, and KoLmafia v13.3.1.

I made my first farming script but it won't finish combat. Everything seems to work fine until my character loses initiative. Upon initiative loss the combat won't progress; my character doesn't do anything and the rounds just keep going up.

Here's the script:

Code:
void main (){
	While( my_adventures() > 0)	
	visit_url("rats.php?where=1");
}

The gCLI looks like this:

[842] Typical Tavern Quest
Encounter: drunken rat
Round 0: UB3r 31337 HaX0R wins initiative!
Round 1: UB3r 31337 HaX0R attacks! (auto-attack)
Round 1: You gain 16 Meat
Round 1: drunken rat takes 32 damage.
You gain 16 Meat
You acquire an item: rat whisker
You gain 1 Muscleboundness
You gain 2 Mysteriousness

[843] Typical Tavern Quest
Encounter: drunken rat
Round 0: UB3r 31337 HaX0R loses initiative!

[843] Typical Tavern Quest

[843] Typical Tavern Quest

[843] Typical Tavern Quest

[843] Typical Tavern Quest

[843] Typical Tavern Quest

[843] Typical Tavern Quest

[843] Typical Tavern Quest

[843] Typical Tavern Quest
:eek:
In order to break the loop I open the web browser and manually attack. In witch case I get:

[843] Typical Tavern Quest
Round 19: UB3r 31337 HaX0R attacks!

[843] Typical Tavern Quest
Round 19: You gain 15 Meat
Round 19: drunken rat takes 31 damage.
You gain 15 Meat
You acquire an item: rat whisker
You gain 1 Beefiness
You gain 1 Smarm
Encounter: drunken rat
Round 0: UB3r 31337 HaX0R wins initiative!
Round 1: UB3r 31337 HaX0R attacks! (auto-attack)
Round 1: You gain 13 Meat
Round 1: drunken rat takes 30 damage.
You gain 13 Meat
You acquire an item: rat whisker
You gain 2 Beefiness
You gain 2 Enchantedness
You gain a Mysticality point!

And then the script continues until I lose initiative again. I'm not sure this is even a scripting problem, but I don't know what to do?:confused: Any help would be much appreciated! Thank you.
 

Bale

Minion
You've got a very simple problem actually. While visit_url("rats.php?where=1") will start a fight, it will not do anything to attack or use skills so you are left with an unfinished fight and each successive visit_url() only leaves you twiddling your thumbs while you're stuck in round 1 of the unfinished combat.

To actually fight, what you need is:

Code:
void main (){
	While( my_adventures() > 0) {
		visit_url("rats.php?where=1");
		run_combat();
	}
}
 

Grotfang

Developer
Related question:

Code:
int hobos_killed = 0;

string page_text = visit_url( "adventure.php?snarfblat=167" );

while( !contains_text( page_text , "Attention -- A Tent!" ) && hobos_killed < 162 )
{
	if( contains_text( page_text , "Combat" ) )
	{
		run_combat();
		hobos_killed = hobos_killed + 1;
	}
	else if( contains_text( page_text , "choice.php" ) )
	{
		page_text = run_choice( page_text );
	}
	page_text = visit_url( "adventure.php?snarfblat=167" );
}
if ( hobos_killed == 162 )
{
	abort ( "Killed enough hobos" );
}

When this script has killed 162 hobos it is meant to stop. However, it will call visit_url( "adventure.php?snarfblat=167" ); before it ends, leaving me in combat with my 163rd hobo twiddling my thumbs. Is there any way to stop it from visiting adventure.php after killing 162? At the moment I just open a browser window and CLEESH away, but it would be nice to be able to prevent it from happening in the first place.
 

Rinn

Developer
call the visit_url only once at the top of the while loop, or surround the second visit_url with a check to if you haven't killed enough hobos
 

Spiny

Member
Modify the 2nd visit_url to:

Code:
if ( hobos_killed < 162) page_text = visit_url( "adventure.php?snarfblat=167" );
 

zarqon

Well-known member
I would use repeat-until instead of while. Then you only need one visit_url() command, at the top of the loop rather than the bottom.
 

zarqon

Well-known member
Also: you probably should also run a contains_text() on run_combat() to make sure you actually won the combat, or hobos_killed could be inaccurate if you are defeated.
 

Grotfang

Developer
Good point. Hadn't really considered that as I was planning to abort the script on the event that you become beaten up. It's intended for hamster runs, so I figured if it is possible to get beaten up, I'd probably want to stop.
 
Top