Bug - Not A Bug Post Adventure script is fired after zone warning

Nappa

Member
I was toying around with a script idea I had and ended up with the conclusion that a post adventure script would probably be able to do what I wanted (parse some info from each fight). Not having worked with such a script before I decided to make a simple test script to see when and how such a script triggers, but I found out it was also triggering after displaying a zone warning.

The script:
Code:
void main ()
{
 matcher mm = create_matcher( "acquire an item: <b>(.*?)</b>", run_combat() );
 
 if( find( mm ) ) {
	print( "Found the following item(s) in your last fight:", "green" );
	print( " = " + group( mm, 1 ), "green" );
	while( find( mm ) ) {
		print( " = " + group( mm, 1 ), "green" );
	}
  } else { 
    print( "Last fight, no item for you!","red" );
  }
}

The results: After fighting a battle, it properly listed my winnings. Subsequently I moved to a high level zone where I didn't meet the stat recommendations. However, after the zone warning was loaded, the after adventure script was triggered again and printed the items a second time in the CLI. I don't think that's the intended behavior.

And since this question is related I might as well ask it here: is there a script moment that only triggers after actual combats? That's what I'm actually looking for, because if the post adventure script is also triggered after a (fightless) choice adventure, run_combat() will still hold the same value...
 

Theraze

Active member
It's not a guarantee of success, because I don't know if you can tell which queue item is most recent, but one way to tell if your last combat adventure was in a different zone and you only had non-combats is something like this:
Code:
> ash (my_location().combat_queue.split_string(";")[0].to_monster() == last_monster())

Returned: false
My last_monster() fought overall was a suckubus, the most recent monster I fought at my_location() [the barrels] was a mimic, and so they don't match.
 

lostcalpolydude

Developer
Staff member
The queue is in order, so on that front it's fine. However, it would fail for wandering monsters.

I think
Code:
to_monster( get_property( "lastEncounter" ) ) != $monster[none]
would work well.
 

Fluxxdog

Active member
Another thing is the code is working exactly as intended. Look at this line here:
Code:
matcher mm = create_matcher( "acquire an item: <b>(.*?)</b>", run_combat() );
run_combat() returns the current combat page if you're currently in a combat after running your CCS. Outside of combat, it will return the last combat page you accessed. Since the zone warning is not a combat, run_combat() is giving you the results of the last combat you fought in before the warning.

afterAdventureScripts will trigger after any adventure, combat or no. If you want to narrow down to just after fights, you could try checking against
Code:
if(get_property("lastEncounter").to_monster!=$monster[none]) {
   do_stuff_here();
}
There are bound to be exceptions where monster names and non-coms overlap.

On a side note, the ASH function extract_items() should serve you much the same purpose as the regex.

Edit: semi-ninja'd
 

Nappa

Member
Thanks for the input, all. I'll try these approaches some time soon.

I understand the post adventure script is triggered after choice adventures, I just wasn't sure if it should trigger upon displaying the zone warning message since technically you can consider this a 'non adventure' (at least that's what I did ;) ). But if it's actually by design, someone should probably mark this thread as 'Not a bug'.
 
Top