ereinion
Member
Because some PvPers like to steal items when attacking , and I both want swagger and a small enough inventory that I don't have to spend ages searching through it for what I want, it happens fairly regularly that an item is stolen from me that I want to reacquire. I suppose I could simply check to see if it is in my inventory to save a server hit (the inventory is stored internally in mafia, right?), but partly as an intellectual exercise and partly because that was what I thought of first, I ended up writing an ash-script which looks in the archives to see what items I've lost since I last logged on. The following code-snippet is what I've come up with so far, and I am curious if this is the right approach to what I want to do:
As you can see I am only printing the information found so far, I guess that may be as far as I take this script too 
However there are a few things I got curious about writing the script:
I am looking forward to be enlightened
Code:
void main() {
string pvp_string = visit_url("peevpee.php?place=logs");
int firstOfMine = index_of(pvp_string, "view]</small></a><td><a href=" + "\"" + "showplayer.php?who=" + to_string(my_id())); //"
string pattern = "(?<=\\/Lost)[^<]+";
string[int, int] items_lost;
// If the first fight I initiated isn't in the first 100 figths, we want the bigger version of the archive
if (firstOfMine == -1 && pvp_string.contains_text("Show More")) {
pvp_string = visit_url("peevpee.php?place=logs&mevs=0&oldseason=0&showmore=1");
firstOfMine = index_of(pvp_string, "view]</small></a><td><a href=" + "\"" + "showplayer.php?who=" + to_string(my_id())); //"
}
// We only want to search the string between the first [view] and the first fight I initiated.
if (!(firstOfMine == -1)) {
pvp_string = substring(pvp_string, index_of(pvp_string, "[view]"), firstOfMine);
}
items_lost = group_string(pvp_string, pattern);
foreach i,j in items_lost {
if (j==0) {
print("Index(" + i + ", " + j + "): " + items_lost[i][j]);
}
}
}

However there are a few things I got curious about writing the script:
- Is it a good idea to reduce the size of the string I want to search first, as I am doing in the first couple of if-statements?
- Related to the first, should I load the longer archive straight away, or should I first see if the last fight I initiated is in the shorter archive containing the 100 most recent fights? In my experience it is quite seldom the first will be necessary.
- What do you think of the pattern I came up with? I think it should work for all cases?
- Why am I using a multi-dimensional map to loop through the results? I am having a bit of trouble understanding the wiki-page on group_string. Sorry, I am kind of new to regexes
I am looking forward to be enlightened
