Importing SmartStasis main() function to your script, to modify combat queue?

fxer

Member
I've been using a custom script of mine for a few years now, but strange bugs pop up and I've always wondered if I was using script imports incorrectly or something. Below is the main() function that I copy-pasted from SmartStasis into my script fxer.ash, with two blocks of modifications as commented in the code: Actions that have to fire before SmartStasis takes an action, and Actions that can fire whenever SmartStasis chooses.

1st change: To use a nanorhino you have to use a muscle skill as your first skill (like Toss, if you cast entangling noodles that is Myst class and you can't Nanobrawny effect). So my mod is just to fire a macro directly to the server and not enqueue anything with smartstasis/batbrain.

Then you see build_custom(), which SS/Batbrain use to create the actions.

2nd change: Then I add a few more skills, if necessary, to the custom[] combat queue array. Such as Creepy Grin if it hasn't been used yet.

Those are my only additions but strange bugs pop up for me such as:

1) On firing the Romantic Arrow, mafia halts and says you're on your own, I've posted about it before here: http://kolmafia.us/showthread.php?1...for-a-simple-CCS&p=98824&viewfull=1#post98824

2) Recently a macro has started getting built that tries to use the Indigo Cup repeatedly in a combat, even though it's a once-per-combat item and is marked as such in BatFactors.txt, I've posted about it here: http://kolmafia.us/showthread.php?6...onsult-scripts&p=117925&viewfull=1#post117925

Hopefully this is just me being a bad scripter, so perhaps this code shows what obvious error I'm making and how to correct it. Anyone else had trouble firing romantic arrows from their scripts?


PHP:
// SmartStasish.ash Consult Script for your CCS, with additions
void main(int initround, monster foe, string pg) {
   act(pg);
   vprint_html("Profit per round: "+to_html(baseround()),5);

   	// *** MODIFICATIONS TO FIRE BEFORE SmartStasis ***

	// Attempt to get Nanobrawny buff from nanorhino
	if( my_fam() == $familiar[nanorhino] && $familiar[nanorhino].image == "nanorhinoc.gif"){
		// Track the number of nanorhino uses today
		set_property("_nanorhinoUses", get_property("_nanorhinoUses").to_int() + 1);
		//custom[count(custom)] = to_event("skill " + get_combat_skill("muscle").to_int(),"",1);
		abort("ready for nanorino combat skill!");
		macro("skill " + get_combat_skill("muscle").to_int()); // Need to fire this to server before SS tries entangling noodles or some such
	}

	// *** END BEFORE SmartStasis MODS ***

  // custom actions
   build_custom();

   	// *** MODIFICATIONS TO FIRE WHENEVER SmartStasis WANTS ***

	// Attempt to unleash the nanites if it will banish a monster
	if( have_effect($effect[nanobrawny]) >= 40 && get_banish_monsters("perm") contains foe){
		custom[count(custom)] = to_event("skill " + $skill[Unleash Nanites].to_int(),"",1);
		//macro("skill " + $skill[Unleash Nanites].to_int());
	}

	// Attempt to temporarily banish monsters if you have skills available
	if( get_banish_monsters("temp") contains foe ){
		// Pantsgiving (30 advs, 5 daily)
		if( have_skill($skill[Talk About Politics]) && get_property("_pantsgivingBanish").to_int() < 5){
			custom[count(custom)] = to_event("skill " + $skill[Talk About Politics].to_int(),"",1);
		}
		// Vivala mask (10 advs, 1 daily)
		else if( have_skill($skill[Creepy Grin]) && !get_property("_vmaskBanisherUsed").to_boolean() ){
			custom[count(custom)] = to_event("skill " + $skill[creepy grin].to_int(),"",1);
		}
		// Stinky cheese eye (10 advs, 1 daily)
		else if( have_skill($skill[Give Your Opponent the Stinkeye]) && !get_property("_stinkyCheeseBanisherUsed").to_boolean() ){
			custom[count(custom)] = to_event("skill " + $skill[Give Your Opponent the Stinkeye].to_int(),"",1);
		}
	}

	// Use the romantic arrow if we've got our Obtuse Angel with us
	if( my_fam() == $familiar[Obtuse Angel] && get_putty_monster() == foe){
		custom[count(custom)] = to_event("skill " + $skill[Fire a badly romantic arrow].to_int(),"",1);
	}

	// *** END WHENEVER SmartStasis MODS ***

   switch (m) {    // add boss monster items here since BatMan is not being consulted
      case $monster[conjoined zmombie]: for i from 1 upto item_amount($item[half-rotten brain])
         custom[count(custom)] = get_action("use 2562"); break;
      case $monster[giant skeelton]: for i from 1 upto item_amount($item[rusty bonesaw])
         custom[count(custom)] = get_action("use 2563"); break;
      case $monster[huge ghuol]: for i from 1 upto item_amount($item[can of Ghuol-B-Gone™])
         custom[count(custom)] = get_action("use 2565"); break;
   }
   if (count(queue) > 0 && queue[0].id == "pickpocket" && my_class() == $class[disco bandit]) try_custom();
    else enqueue_custom();
  // combos
   build_combos();
   if (($familiars[hobo monkey, gluttonous green ghost, slimeling] contains my_fam() && !happened("famspent")) || have_equipped($item[crown of thrones])) try_combos();
    else enqueue_combos();
  // stasis loop
   stasis();
   if (round < maxround && !is_our_huckleberry() && adj.stun < 1 && stun_action(false).stun > to_int(dmg_dealt(buytime.dmg) == 0) &&
       kill_rounds(smack) > 1 && min(buytime.stun-1, kill_rounds(smack)-1)*m_dpr(0,0)*meatperhp > buytime.profit) enqueue(buytime);
   macro();
   vprint("SmartStasis complete.",9);
}
 
Well, keeping the fact that you're running custom actions tied into your 'intelligent' scripts that cause them to potentially choke because it's already built the page and created the 'status' before you send custom actions to change the status and make it no longer in the state it was when it built the page...

From what you said, you're running SS twice. In your custom script, as well as through WHAM - which calls SS itself through its own wrapper. From your description of your CCS, it would probably be much easier to just import WHAM rather than SS and modify the WHAM main instead...
 
Well, keeping the fact that you're running custom actions tied into your 'intelligent' scripts that cause them to potentially choke because it's already built the page and created the 'status' before you send custom actions to change the status and make it no longer in the state it was when it built the page...

From what you said, you're running SS twice. In your custom script, as well as through WHAM - which calls SS itself through its own wrapper. From your description of your CCS, it would probably be much easier to just import WHAM rather than SS and modify the WHAM main instead...

Thanks Theraze, my CCS reads:
1: call fxer.ash
2: call wham.ash

So would that cause SS to run twice in the same loop? I thought my script would be complete then pass processing off to WHAM (and SS)
 
Hmm... call, or consult? Do those do the same thing? I know all of mine use consult.

But very simply, yes. Your fxer.ash script above does the stasis with lines like:
Code:
  // stasis loop 
   stasis();
WHAM.ash does this:
Code:
		vprint("WHAM: Running SmartStasis", "purple", 3);
		SmartStasis();
which does this:
Code:
	// stasis loop
	stasis_WHAM();
	macro();
	vprint("WHAM: SmartStasis complete.", "purple", 7);
So yes... you're doubling up the stasis. :) While 'once' items SHOULD only trigger one time, there had been some fun confusion regarding getting the jump on rounds and it marking as different fights a while in the past. I believe that bug got fixed, but still... the duplication of executions might be causing issues for you.

Or maybe it's as simple as the different between call and consult. Maybe.
 
Hmm... call, or consult? Do those do the same thing? I know all of mine use consult.

Sorry you're right, it's consult not call. Even then though I thought the stasis() in my script would be complete, so when WHAM calls SmartStasis() it would see there is nothing to do and simply move on?

In either case, do you think trying to modify the WHAM main() function would be the easiest/only way to achieve what I'm trying to do? Trigger buffs from the nanorhino and use banishing items at the beginning of combats etc?
 
I am not sure how persistent the BatBrain "have done this"-map is so it may be that having it show up in different scripts called after eachother may lead to unwanted issues.
If you want to add specific stasising and whatnot things I'd suggest looking if it would be possible to add them to build_custom_WHAM() which is where I put in things I think should be done as part of that but that SS may not do.
 
Thanks Winterbay I'll check that option. Would I need to cut and paste any changes I make back into wham.ash whenever it was updated via svn if I go this route?
 
If you make the changes in the "\svn\winterbay-mafia-wham"-folder they should be merged whenever an updated is pushed out.
 
I'd suggest looking if it would be possible to add them to build_custom_WHAM() which is where I put in things I think should be done as part of that but that SS may not do.

This has been working well Winterbay, thanks for the tip. I can get things like temporary banishers to work (ex: pantsgiving, creepy grin, stinkeye), but one that isn't working is setting up the Nanorhino's permanent banish.

Inside your method I've added the code:
PHP:
	// Attempt to get Nanobrawny buff from nanorhino
	if( my_fam() == $familiar[nanorhino] && get_property("_nanorhinoCharge").to_int() == 100){
		encustom(get_action($skill[Toss]));
	}

But when I enter combat a bunch of other things happen before Toss and then the combat is over (pickpocket, pocket crumbs, zombo's eye and done). Is there a way to prioritize Toss so the buff happens immediately before the combat could possibly end?
 
There is a function "pre_brain()" which is called before BatBrain has had any chance to do anything. I would assume that if you were to add a
Code:
macro("skill " + to_string(to_int($skill[toss])));
in there it should run before anything batbrain/smartstasis/WHAM does and trigger what you want it to trigger.
 
That set me on the right track. I was actually able to get Toss to fire using a plain encustom() command in build_custom_wham(), however what would not work was Unleash Nanites, which auto kills and banishes the monster. Maybe WHAM/SS sees Toss won't kill the monster so it allows it, but knows Nanites will kill the monster so doesn't do it? Although WHAM simply attacks with weapon and deals 8000dmg on the next move instead of unleashing nanites...

Moving this into pre_brain() looks to be doing the trick though, thanks winterbay!

PHP:
	// Attempt to unleash the nanites if it will banish a monster
	if( have_effect($effect[Nanobrawny]) >= 40 && get_banish_monsters("perm") contains foe){
		vprint("Enqueuing Unleash Nanites to banish: " + foe, 4);
		macro("skill " + to_string(to_int($skill[unleash nanites])));
	}
 
I believe I fixed the Nanites issue you just mentioned with the recent BatBrain update. There was a bug which made that skill get ignored sometimes (not show up in opts[]) even when it was available.

Also, the indigo cup firing twice is a known bug in SS. (Known to me, anyway.) SS will submit repeat conditions even for items marked "once".

So take comfort -- your scripting problems are mostly my fault, not yours!
 
Back
Top