SmartStasis -- a complex script for a simple CCS

Sputnik1

Member
I used update clear using r9576, still getting this error

Function 'happened( string )' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts. (SmartStasis.ash, line 370)
 
Last edited:

Winterbay

Active member
Make sure you have the latest version of Batbrain.ash (and no old copy lying around in a folder reachable by Mafia). That function was added to Batbrain just a day or two ago.
 

asturia

Minion
When I'm using this script, it suddenly stops and I have to finish the fight by hand.
Here is a debug log from when it happens:
Code:
[700] Belowdecks
Encounter: grungy pirate
Round 0: Asturia wins initiative!
 > 1 MP costs 8.0μ.
 > 1 HP costs 3.2μ.
 > acoustic guitarrr (20.0 @ +35.0): 420μ * 27.0% = 113.4
 > grungy bandana (10.0 @ +35.0): 489μ * 13.5% = 66.015
 > grungy flannel shirt (5.0 @ +35.0): 343μ * 6.75% = 23.1525
 > Building options...
 > Options built! (41 actions)
 > acoustic guitarrr (20.0 @ +35.0): 420μ * 27.0% = 113.4
 > grungy bandana (10.0 @ +35.0): 489μ * 13.5% = 66.015
 > grungy flannel shirt (5.0 @ +35.0): 343μ * 6.75% = 23.1525
 > Monster: Grungy Pirate, ATT: 150, DEF: 135, HP: 130, Value: 627.57
 > You will die in 195 rounds.
 > Your attack will kill the monster in 9 rounds.
 > Building custom actions...
> 1/5 monsters drop goals here.
 > Custom actions built! (0 actions)
 > Executing macro: scrollwhendone; sub batround; if haseffect 264 || haseffect 282 || haseffect 283 || haseffect 284; abort "BatBrain abort: poisoned"; endif; endsub; pickpocket; call batround; if hpbelow 13; abort "BatBrain abort: Danger, Will Robinson"; endif; 
Round 1: Asturia executes a macro!
Round 1: Asturia tries to steal an item!
You acquire an item: grungy bandana
 > You snatched a grungy bandana (489μ)!
 > acoustic guitarrr (20.0 @ +35.0): 420μ * 27.0% = 113.4
 > grungy flannel shirt (5.0 @ +35.0): 343μ * 6.75% = 23.1525
 > Revised monster value: 561.55
 > Building options...
 > Options built! (41 actions)
 > acoustic guitarrr (20.0 @ +35.0): 420μ * 27.0% = 113.4
 > acoustic guitarrr (24.0 @ +35.0): 420μ * 32.4% = 136.08002
 > grungy flannel shirt (5.0 @ +35.0): 343μ * 6.75% = 23.1525
 > grungy flannel shirt (6.0 @ +35.0): 343μ * 8.1% = 27.783
 > Stasis action chosen: skill 7061
 > Top of the stasis loop.
 > Executing macro: scrollwhendone; sub batround; if haseffect 264 || haseffect 282 || haseffect 283 || haseffect 284; abort "BatBrain abort: poisoned"; endif; endsub; sub batsub1; skill 7061; call batround; endsub; call batsub1; repeat !hpbelow 138.0 && hpbelow 145 && !mpbelow 308.0 && !pastround 26; if hpbelow 13; abort "BatBrain abort: Danger, Will Robinson"; endif; 
Round 2: Asturia executes a macro!
Round 2: Asturia casts SPRING RAINDROP ATTACK!
You gain 27 hit points
You gain 23 Mojo Points
 > Building options...
 > Options built! (37 actions)
 > Stasis action chosen: skill 3004
 > This monster is not your huckleberry.
 > Stasis loop complete.
 > SmartStasis complete.

My CCS script is as follows:
Code:
[ default ]
consult Smartstasis.ash
skill shieldbutt

When I switch back to the previous version of SmartStasis and Batbrain, the problem goes away. I'm using the latest daily build of kolmafia.
 

Winterbay

Active member
Seeing as the last thing printed is the last line in SmartStasis there appears to be some kind of jinx when going from SmartStasis to the second line in the CCS. Do you have a shield? :)

(seeing as you just got 23MP I'm going to assume that lack of MP is not the reason)
 

asturia

Minion
Seeing as the last thing printed is the last line in SmartStasis there appears to be some kind of jinx when going from SmartStasis to the second line in the CCS. Do you have a shield? :)

(seeing as you just got 23MP I'm going to assume that lack of MP is not the reason)
Yep, I have a pilgrim shield equipped.
Lack of MP is not the problem as you said.
I'm going to start with an empty kolmafia and see what will happen then.
 

asturia

Minion
It also happens when I use a complete new Mafia installation. :(
Something strange is going on.
What can I provide you so you can sort it out?
If it's possible at all that is.
 

Winterbay

Active member
Try changing the CCS to
Code:
consult smartstasis
"skill shieldbutt"

To see if somehow saying to Mafia to use it as a verbatim macro helps at all?
 

Winterbay

Active member
That's a shame. Are you doing this from the CLI or the Relay browser?
If you are in the CLI try going to the relay browser, enter a combat and use the "Script" button that Mafia provides. This could potentially give some kind of information about what is happening.
 

asturia

Minion
I was running it from the CLI.
I've run it now from the Browser and here is what I get:
Code:
[IMG]http://images.kingdomofloathing.com/adventureimages/hairclog.gif[/IMG]You're fighting a malevolent hair clog
HP: 95, Atk: 105, Def: 90
Drops: gob of wet hair (40)
[IMG]http://images.kingdomofloathing.com/itemimages/hkatana.gif[/IMG]A plump spring raindrop
sliced into a million bits:
a refreshing mist.[IMG]http://images.kingdomofloathing.com/itemimages/hp.gif[/IMG]You gain 23 hit points.[IMG]http://images.kingdomofloathing.com/itemimages/mp.gif[/IMG]You gain 21 Mojo Points.Concentrating on your navel, you zoom out of the way, and your opponent is unable to reach you.
You don't have or can't use skill #7061, macro aborted.

It seems that it stops on skill #7061, Spring Raindrop Attack.
Which I should have available since I have a Haiku Katana equipped.
 

Winterbay

Active member
It appears to be using the skill (as indicated by the use text) and then somehow trying to use it again...

The macro SmartStasis is submitting is:
Code:
scrollwhendone;

sub batround;
	if haseffect 264 || haseffect 282 || haseffect 283 || haseffect 284;
		abort "BatBrain abort: poisoned";
	endif;
endsub;

sub batsub1;
	skill 7061;
	call batround;
endsub;

call batsub1;

repeat !hpbelow 138.0 && hpbelow 145 && !mpbelow 308.0 && !pastround 26;

if hpbelow 13;
	abort "BatBrain abort: Danger, Will Robinson";
endif;
Meaning that it is trying to do a call to batsubl followed by a repeat which will call batsubl again which will fail since you have already used the skill.

I wonder if this is not a problem with BALLS where it seems to consider "hpbelow 145" to be true if your hp is 145. Try chaning line 411 to:
Code:
(my_stat("hp") < my_maxhp() ? " && hpbelow "+my_maxhp() - 1 : "")+
and see if that helps?
 

slyz

Developer
Does BatBrain know that you can only use Spring Raindrop Attack only once per katana equipped? From the KoLWiki page:
KoLWiki said:
Only one haiku katana skill can be used per equipped sword per battle.
 

Winterbay

Active member
Ahh, no it doesn't. It consideres all skills to be multi-usable as far as the stasis_action()-function is concerned, that function only skips items that are non-multiusable. If the cheapest option you have is a skill it will decide that this is the best you can do and then obviously crash as seen here.
 

asturia

Minion
Ahh, no it doesn't. It consideres all skills to be multi-usable as far as the stasis_action()-function is concerned, that function only skips items that are non-multiusable. If the cheapest option you have is a skill it will decide that this is the best you can do and then obviously crash as seen here.
So at the moment I'm better off using the old version of SmartStasis and Batbrain untill you update it?
Thanks for the great script and support.
 

Winterbay

Active member
Changing stasis_action() to
Code:
// retrieve specific or best-suited actions from opts
advevent stasis_action()	// returns most profitable lowest-damage action
{
	sort opts by value.att;
	sort opts by -to_profit(value);
	sort opts by max(dmg_dealt(value.dmg), monster_stat("hp") / max(1,maxround - round) + 5);
	foreach i,opt in opts	// skip non-multi-usable items
	{
		if ((contains_text(opt.id,"use ") && !to_item(excise(opt.id,"use ","")).reusable) || opt.id == "skill 7091"))
			continue;
		vprint("Stasis action chosen: "+opt.id,9);
		return opt;
	}
	return new advevent;
}

Will make it not stop for that reason, but otoh it will probably not use raindrop at all instead which most likely is overkill.

Edit: If you use the skill once is the skill then not available in the relay browser or can you choose it more than once but it will only work once?
 
Last edited:

Theraze

Active member
The current version appears to abort without warning if I have Bs sting me (wearing Bs in Beecore) and I get the jump. Running ashq run_combat() will finish up the battle without problems, but it gets annoying to type 15-20 times per character before the B-thing triggers in my brain. :)

Edit: Logs!
Request 2 of 17 (Knob: Cobb's Knob Harem) in progress...
[1179] Cobb's Knob Harem
Encounter: Knob Goblin Harem Guard
Strategy: C:\Program Files (x86)\KoLMafia\ccs\default.ccs [default]
Round 0: Theraze wins initiative!
You lose 8 hit points
Profit per round: ActionProfitDamageOtherbase; Star Starfish (0μ)0μ8.17 (0 μ/dmg)MP: 8.17
Monster: Knob Goblin Harem Guard, ATT: 49, DEF: 44, HP: 42, Value: 140.31
You will die in 158 rounds.
Your attack will kill the monster in 1 rounds.
Round 1: Theraze executes a macro!
Round 1: Theraze casts LASAGNA BANDAGES!
You gain 11 hit points
Round 2: Theraze executes a macro!
Round 2: Theraze casts ENTANGLING NOODLES!
Round 3: Gorg floats behind your opponent, and begins to glow brightly. Starlight shines through your opponent, doing 24 damage, and pours into your body.
Round 3: knob goblin harem guard takes 24 damage.
You gain 24 Mana Points
You're on your own, partner.
Click here to continue in the relay browser.
You're fighting a Knob Goblin Harem Guard
HP: 18, Atk: 49, Def: 44
Drops: Knob Goblin deluxe scimitar (10), Knob nuts (15)

As you enter the harem, you hear a high-pitched voice: "Stop, Intruder!"
You turn and see a Knob Goblin Harem Guard, all muscles and gruff demeanor. They have the same air of distracted peevishness that people get when they misplace their car keys, only way, way worse. You wonder what they could have lost that they're missing so much they've got to be jerks all the time.
You get the jump on him.
The Bs in your observational glasses sting you in the part of you that's wearing your observational glasses.

You lose 8 hit points.

Edit2: Maybe not tied into the Bs, but something else jump-related? In both cases, I won initiative and the relay screen just shows that...
Request 6 of 15 (Knob: Cobb's Knob Harem) in progress...
[1185] Cobb's Knob Harem
Encounter: Knob Goblin Harem Girl
Strategy: C:\Program Files (x86)\KoLMafia\ccs\default.ccs [default]
Round 0: Theraze wins initiative!
Profit per round: Action Profit Damage Other base; Star Starfish (0μ) 37.99μ 8.17 (0 μ/dmg) MP: 8.17
Monster: Knob Goblin Harem Girl, ATT: 49, DEF: 44, HP: 42, Value: 151.59
You will die in 212 rounds.
Your attack will kill the monster in 1 rounds.
Round 1: Theraze executes a macro!
Round 1: Theraze casts ENTANGLING NOODLES!
Round 2: Gorg floats behind your opponent, and begins to glow brightly. Starlight shines through your opponent, doing 32 damage, and pours into your body.
Round 2: knob goblin harem girl takes 32 damage.
You gain 32 Mana Points
You're on your own, partner.
Click here to continue in the relay browser.
You're fighting a Knob Goblin Harem Girl
HP: 10, Atk: 49, Def: 44
Drops: disease (10), Knob Goblin harem veil (20), Knob Goblin harem pants (20), finger cymbals (5), harem girl t-shirt (2 cond), swindleblossom (0 cond)


This is one of the Harem Girls from Cobb's Knob. You know what they say about Knob Goblin Harem Girls, don't you? It's all true.​
You get the jump on her.
 
Last edited:

Winterbay

Active member
Did you start any of those fights in the relay browser?

Also, it is possible that the loss of HP due to the Bs pushes you below the m_dpr() or similar function that batbrain/smartstasis uses for calculation of when to abort? (I don't have the code here so can't check atm)
 

zarqon

Well-known member
Looks like these are complications resulting from making the repeat conditions in the stasis macro more lax as an effort to reduce server hits for farmers. Previously, the stasis action would abort whenever (among other checks) your HP or MP changed at all. That meant that most skills would only be cast once per macro since they cost MP, and even free restores like Burrowgrub and Spring Raindrop would only run once due to the HP/MP gain. Then, BB would rebuild the combat options from your page text and skills which are no longer available would be absent from the list. However, this mostly translated to one server hit per action -- no different from non-macrofied play.

So the change made was to allow HP and MP gain without ending the repeat loop, until max MP/HP was reached, or until you have enough MP to cast your most expensive skill -- in other words, potential restore goals. This means far fewer server hits for farmers -- it cut one of my multis' daily operations time in half.

However, it looks like this should be reverted, since presently there are too many things which prompt KoL errors due to the source running out before the repeat conditions do -- I keep getting similar aborts from Burrowgrub running out, and these other reports lead me to believe that this was a change made too soon. Without a mechanism for knowing how many instances of an action are available, this change is causing more harm than good. I'll revert that and look for a better way to reduce server hits.

Also, for future reference, whenever mafia aborts the combat without any specific error message (technically after SS is done), it's safe to assume it's due to SS's previous macro prompting a KoL error. That's what the deal was before with "pickpocket; repeat", and with Noodles vs. unstunnable monsters, etc. These errors are good because they help us iron out flaws in BatBrain's combat foresight and macrofication, but they're annoying in that they're pretty hard to track down.

If, after I revert the stasis loop conditions, you still get one of these mystery errors, please post the combat with verbosity 9 so we can see the macro being submitted -- ideally with the actual resultant page text from submitting that macro, as asturia did above. Being able to see the actual KoL abort error is very helpful. Thanks.

EDIT: Long ago I aliased that run_combat command, but recently I added a line so now it's "fight => ashq refresh_status(); run_combat();" -- it's pretty handy. That refresh_status is necessary because if your connection timed out simply calling run_combat() won't prompt a login.
 
Last edited:
Top