Way to access Encounter Listing in script?

Malurth

Member
I'd like to make use of the apparently stored data of how many X monster I've fought that day, but I've failed find any info on that from my searching around. Anyone know a way to access this?

I guess I could implement a hackneyed custom solution, but I'd rather not have to.
 

Pazleysox

Member
This might work... Mind you, I haven't tested it

PHP:
int count;

	if (get_property("lastEncounter")=="monster")
count = count +1
if my_adventures() == 0
print ("I've encountered " + count + " monsters that I'm tracking today");

I believe something along those lines would work.

You can probably do it for multiple monsters too.

PHP:
int counta;
int countb;
int countc;

	if (get_property("lastEncounter")=="monster a") 
counta = counta + 1
	if (get_property("lastEncounter")=="monster b") 
countb = countb + 1
	if (get_property("lastEncounter")=="monster c") 
countc = countc + 1
if my_adventures() == 0
print("I've encountered " + counta + " monster a, " + countb + " monster b, " + countc " monster c today");

This would have to be a between battle script to look at the previous adventure.
 

Malurth

Member
Yeah, that would be the aforementioned hackneyed custom solution :p

I might instead implement those as kolmafia properties so it persists even if you close the client, but otherwise thanks for basically doing it for me, haha.

Although now that I think of it, I'm not sure how I would detect that they've been defeated or not, which is relevant to my intent...haven't searched it up yet, tho.

Also in retrospect that might not work with clingy monsters, since I'm not sure if between battle scripts run between multi-stage fights.
 
Last edited:

ckb

Minion
Staff member
I would think the best way of doing what you want is by parsing the session_logs().
You can then find the encounters, determine if they have been defeated, and you could record free and/or multi-stage fights.
I will leave the how as an exercise for the reader.
 

Pazleysox

Member
I would think the best way of doing what you want is by parsing the session_logs().
You can then find the encounters, determine if they have been defeated, and you could record free and/or multi-stage fights.
I will leave the how as an exercise for the reader.

HA! I already have a script that does most of this. lol

I never did figure out how to know if you've defeated a monster though
 

Malurth

Member
Well, I found this code snippet in another thread, from user "darkcodelagsniper":

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);
}

One would imagine you could just do contains_text(LastAdvTxt(), "You win the fight!") to find out, assuming that code snippet works as advertised. Haven't tried it yet tho.

Edit: well it's " wins the fight!" in the logs so that instead. And you also have to account for it just being the last encounter, since there can be multiple within that snippet.
 
Last edited:

Malurth

Member
Dang, clingy monsters are still a pain since both pre-adv and post-adv scripts won't run between stages in multi-stage fights, and you'd have to peek potentially the whole log since they can chain, and also have to avoid double-counting the same clingy monsters. I've yet to think of a not-ridiculous way of doing this in an afterAdventureScript/betweenBattleScript.

Also I'm pretty sure 1337 monsters are going to screw things up too, though I haven't encountered one during testing yet. Really wish mafia would just expose the Encounter Listing for scripting purposes :(
 
Top