Was the last encounter a combat?

I'm trying to track lovebug currency drops using a post adventure script, using
Code:
run_combat().contains_text(<lovebug currency drop text>)
The problem being that run_combat() returns the page text from last time I fought a combat, so will trigger again if I encounter a noncombat. I need a way to tell if the last encounter was a combat in order to avoid this.

The first thing I came up with is:
Code:
to_monster(get_property("lastEncounter")) == last_monster()
but this fails for Dreadsylvanian monsters because
Code:
"Stinkfur, Woman Chewer" != $monster[Stench Werewolf]

Are there any better solutions anyone can think of?
 

ckb

Minion
Staff member
Is this recorded in the session logs? It probably is... but I have not confirmed for lovebug currency drops. There is this in one of my logs:

Code:
After Battle: A love firefly flits flirtatiously around your head.
You gain 4 Enchantedness

You can access the log of your last adventure with this bit of code I wrote:
PHP:
string LastAdvTxt() {
	string lastlog = session_logs(1)[0];
	int nowmark = last_index_of(lastlog,"["+to_string(my_turncount())+"]");
	return substring(lastlog,nowmark);
}

Edit: not sure exactly what you are trying to track, but you could also just post-process all of this after all your adventures too from the complete session log.
 
Last edited:
That's a useful method, but it has similar drawbacks - if the encounter is an NC that doesn't take an adventure, then LastAdvTxt() will return the session log of the previous encounter.

I could post-process at the end of the session, but I'm interested in seeing a running total.
 

Theraze

Active member
Could 'cheat' a little bit by saving the combat and noncombat queues to a string, and then whichever changes is the last type of adventure used. Or if you just want to track on a new combat, just save the combat queue and if isn't the same as last time it processed your after adventure script...

my_location().combat_queue for that queue.
 

Theraze

Active member
They're still a noncombat even if it doesn't take an adventure, right? I'd expect the proper handling to tell you that you picked that noncombat to skip and therefore it won't show up again for the next 20 adventures or whatever...
 

ckb

Minion
Staff member
That's a useful method, but it has similar drawbacks - if the encounter is an NC that doesn't take an adventure, then LastAdvTxt() will return the session log of the previous encounter.

I guess that is true... but it will also include the text of the NC as well. It should be possible to parse the string returned by LastAdvTxt() to check for that, and make accommodation accordingly.
I think you can search for "["+(to_string(my_turncount())+1)+"]" to check if you encountered a non-turn taking encounter.
 

heeheehee

Developer
Staff member
They're still a noncombat even if it doesn't take an adventure, right? I'd expect the proper handling to tell you that you picked that noncombat to skip and therefore it won't show up again for the next 20 adventures or whatever...

Not all noncombats have options to skip/banish them. Examples: Curtains in ballrooom, various ones in Cyrpt, Louvre. Perhaps the issue is that you're conflating the intended function of the combat / noncombat queue with something else entirely (attempted tracking of KoL's internal mechanism for introducing uniformity versus a rolling list of recent encounters).

I suspect r15648 was made with this issue in mind, so that get_property("lastEncounter") == to_string(last_monster()) would be a sufficient check.

I guess that is true... but it will also include the text of the NC as well. It should be possible to parse the string returned by LastAdvTxt() to check for that, and make accommodation accordingly.
I think you can search for "["+(to_string(my_turncount())+1)+"]" to check if you encountered a non-turn taking encounter.

On top of that, I guess some monsters have a FREE designation in attributes (hipster fights, various seals). This isn't comprehensive, though, so I'd think that's potentially worthy of a bug report.
 
I suspect r15648 was made with this issue in mind, so that get_property("lastEncounter") == to_string(last_monster()) would be a sufficient check.
The r15648 change doesn't affect lastEncounter though, so that method still won't work for monsters with procedurally generated names.

I'm trying out this version of ckb's function with the change suggested above:
Code:
	string LastAdvTxt() {
		string lastlog = session_logs(1)[0];
		int nowmark = max(last_index_of(lastlog,"["+my_turncount()+"]"),last_index_of(lastlog,"["+(my_turncount()+1)+"]"));
		return substring(lastlog,nowmark);
	}
Seems to work great! :)
 
Top