auto BHH and friends

Suggestion: Don't put the link inline. It hides it and removes the ability to see download statistics.
 
I've updated the script to allow for the larger bounties, (it won't fax in the larger ones, but doesn't abort now, it just returns a FAIL message).
 
This is the version I'm using now, which doesn't need a data file. It's probably not as fully-featured as some of the previously posted versions -- including my own -- but it gets the job done. Now with handy color coding!

Once bounty info is added to proxy records, this can be streamlined even further, but getting rid of the data file was at least a step in the right direction.

<removed, better posted below>
 
Last edited:
Using your new bounty from 122, I get this when it accepts a bounty:
> bounty *

7 bits of wilted lettuce from Fernswarthy's Ruins
6 worthless pieces of yellow glass from Dungeons of Doom
40 coal buttons from Ninja Snowmen
Accepting the hunt for 40 coal buttons from Ninja Snowmen...
40 coal buttons from Ninja Snowmen
Bounty hunt failed.
Not sure why... running bounty * again will hunt, but the aborting without adventuring is somewhat odd and not the way it ran when it had a data file. My guess is that it's not properly populating the 'bounty' data type before the bounty is accepted, but not sure...
 
Found it. Ran a count(bounty) and found that every time it ran visit_bhh, it added additional bounties without clearing the list. The first line of visit_bhh needs to wipe the bounty list... I'm using the following function for visit_bhh (with only a single line of change) that actually works with bounty * successfully.
PHP:
string visit_bhh(string query) {
   foreach b in bounty remove bounty[b];
   string page = visit_url("bhh.php?pwd"+query);
   if (page.contains_text("I can't assign you a new one")) { bounty.clear(); return page; }
   matcher biggles = create_matcher("(?:bring me |<b>)(\\d+) (.+?)(?:,|</b>)",page);
   while (biggles.find()) {
      int b = count(bounty);
      bounty[b].what = to_singular(biggles.group(2));
      bounty[b].amount = biggles.group(1).to_int();
      bounty[b].where = bounty_loc(bounty[b].what);
      bounty[b].avail = can_has_bounty(b);
      vprint(bstring(b), bounty[b].avail ? "green" : "red",3);
   }
   if (count(bounty) == 1) foreach i,r in bounty
      print("Now hunting: "+bstring(i)+" (hunted so far: "+item_amount(r.what)+")","blue");
   return page;
}
 
At the top, or in the "can't assign" line? I see this:
PHP:
   if (page.contains_text("I can't assign you a new one")) { bounty.clear(); return page; }
but that only applies if you've already got a bounty assigned... the problem was when doing bounty go or bounty *, it would begin by running the count and then accept_best_bounty. The problem there goes to accept_bounty, which runs this:
PHP:
   visit_bhh("&action=takebounty&whichitem="+bounty[n].what.to_int());
   return (count(bounty) == 1);
Because it hasn't locked the bounty yet, it considers that to be an additional bounty, and believes there to be 4 bounties available instead of 3 or 1. Running bounty again after that gives the expected "I can't assign you a new one" message and clears the bounty record.

Edit: Replaced the earlier "remove" line I had in 125 by putting this after the "can't assign" line, and tested it works:
PHP:
   else if (page.contains_text("All right, then\!  Get out there and collect")) { bounty.clear(); }

Still does have this error when finishing up a bounty though:
Conditions satisfied after 9 adventures.
Visiting the Bounty Hunter Hunter...
You acquire an item: filthy lucre
Bounty hunt failed.
Requests complete.
Believe that obtain might be returning false even though it gets the right result in the end... at least, that's the only reason I can come up with it failing to display the total available lucre.
 
Last edited:
Hmmm, my visit_bhh() looks like this:

PHP:
string visit_bhh(string query) {
   bounty.clear();
   string page = visit_url("bhh.php?pwd"+query);
   matcher biggles = create_matcher("(?:bring me |<b>)(\\d+) (.+?)(?:,|</b>)",page);
   while (biggles.find()) {
      int b = count(bounty);
      bounty[b].what = to_singular(biggles.group(2));
      bounty[b].amount = biggles.group(1).to_int();
      bounty[b].where = bounty_loc(bounty[b].what);
      bounty[b].avail = can_has_bounty(b);
      vprint(bstring(b), bounty[b].avail ? "green" : "red",3);
   }
   if (count(bounty) == 1) foreach i,r in bounty
      print("Now hunting: "+bstring(i)+" (hunted so far: "+item_amount(r.what)+")","blue");
   return page;
}

If that's not what's in the script I posted above, then I must have changed it soon afterwards, without reposting here -- which I don't recall doing. I feel kind of like I should be admitted to the moxie guild for stealing my own pants. :)
 
Apparently. :D That explains some of the confusion. Even checked the version in 122 again to make sure I wasn't crazy. It's still a possibility, but not regarding that. Heh.

Edit: Guess it works better if you're doing something that involves can_adv to make sure you have hp. :)

Edit2: But it's still failing in the end:
Conditions satisfied after 10 adventures.
Visiting the Bounty Hunter Hunter...
You acquire an item: filthy lucre
Bounty hunt failed.
 
Last edited:
Here's a quick rewrite to use the new bounty proxy record info. It's quite a bit faster when visiting the BHH to determine the current status.

It still returns false in the end for some reason. Didn't have time to debug. I seldom use this script in such a way that the return value matters, so I've been ignoring that.

I'm sure there's a better way, but I think I'll use this for now.

<removed, better posted below>
 
Last edited:
It's possible that the issue is the uncaptured visit_url. I was having Rinn's Level 10 script abort when I changed it to plant the bean (with visit_url) instead of use it, which doesn't seem to make sense, but the aborting stopped as soon as it was captured. I'll try to test it in a day or two.
 
Found the problem... it's obtain. The issue is that obtain finishes by checking if you have at least n of the cond item... but mafia automatically turns in the bounty, so by the time it finishes checking, you have 0 of the bounty item.

I'd probably suggest a bountyobtain function... something like this:
PHP:
boolean bountyobtain(int n, string cond, location locale) {
   cli_execute("conditions clear");
   add_item_condition(n - have_item(cond), to_item(cond));
   set_location(locale);
   if (adventure(my_adventures(), locale)) return vprint("Out of adventures.",-1);
   visit_bhh("");
   return (count(bounty) == 0);
}

boolean hunt_bounty() {
   if (count(bounty) > 1 && !accept_best_bounty(to_boolean(vars["do_smallest_bounty"]))) return false;
   foreach i,r in bounty {
     print("Adventuring for "+bstring(i)+"...");
     if (!bountyobtain(r.bounty_count,r,r.bounty)) return false;
     vprint("You have "+available_amount($item[filthy lucre])+" filthy lucre.",3);
   }
   return (count(bounty) == 0);
}

Edit: Using the bountyobtain function:
Conditions satisfied after 46 adventures.
Visiting the Bounty Hunter Hunter...
You acquire an item: filthy lucre
You have 2 filthy lucre.
Bounty hunt successful.
Requests complete.
 
Last edited:
I tried changing hunt_bounty() like so:

PHP:
boolean hunt_bounty() {
   if (count(bounty) > 1 && !accept_best_bounty(to_boolean(vars["do_smallest_bounty"]))) return false;
   foreach i,r in bounty {
     vprint("Adventuring for "+bstring(i)+"...",2);
     obtain(r.bounty_count,r,r.bounty);
	 if (get_property("currentBountyItem") != "") return false;
   }
   return vprint("You have "+available_amount($item[filthy lucre])+" filthy lucre.",3);
}

Will see if it works tomorrow.
 
Last edited:
Apparently not...
Conditions satisfied after 4 adventures.
Visiting the Bounty Hunter Hunter...
You acquire an item: filthy lucre
Bounty hunt failed.
Requests complete.
Replaced my copy with yours and got the fail. I think you'd need to capture the obtain... turn it back into this:
PHP:
     (!obtain(r.bounty_count,r,r.bounty));

Edit: Nope, still got this with obtain being captured:
Conditions satisfied after 33 adventures.
Visiting the Bounty Hunter Hunter...
You acquire an item: filthy lucre
Bounty hunt failed.
Requests complete.
Just to clarify, had this (and it didn't work):
PHP:
boolean hunt_bounty() {
   if (count(bounty) > 1 && !accept_best_bounty(to_boolean(vars["do_smallest_bounty"]))) return false;
   foreach i,r in bounty {
     vprint("Adventuring for "+bstring(i)+"...",2);
     (!obtain(r.bounty_count,r,r.bounty));
     if (get_property("currentBountyItem") != "") return false;
   }
   return vprint("You have "+available_amount($item[filthy lucre])+" filthy lucre.",3);
}
Ah... appears the problem is the currentBountyItem property. Threw in this check:
PHP:
     (!obtain(r.bounty_count,r,r.bounty));
     vprint("Adventured for "+get_property("currentBountyItem")+"...",2);
     if (get_property("currentBountyItem") != "") return false;
And got this display:
Conditions satisfied after 30 adventures.
Visiting the Bounty Hunter Hunter...
You acquire an item: filthy lucre
Adventured for 0...
Bounty hunt failed.
Requests complete.
Checked and that appears right:
> pref bounty

currentBountyItem (user, now '0', default 0)
So instead of looking for "" we should be looking for "0" and then it should work...

Edit2: Yep!
Conditions satisfied after 19 adventures.
Visiting the Bounty Hunter Hunter...
You acquire an item: filthy lucre
You have 2 filthy lucre.
Bounty hunt successful.
Requests complete.
 
Last edited:
bounty.ash fails if the bounty chosen is the Haunted Wine Cellar.

The problem is that mafia has 5 locations containing that bounty. If more than one location is found by visit_bhh(), then accept_bounty() return false so it fails.

I fixed this by adding a line to visit_bhh() like this:

Code:
string visit_bhh(string query) {
   bounty.clear();
   string page = visit_url("bhh.php?pwd"+query);
   foreach l in $locations[] {
      [COLOR="#FF0000"]if ($locations[Haunted Wine Cellar (Northwest), Haunted Wine Cellar (Northeast), Haunted Wine Cellar (Southwest), Haunted Wine Cellar (Southeast)] contains l) continue;[/COLOR]
	  if (l.bounty == $item[none] || !contains_text(page,l.bounty.bounty_count+" "+to_plural(l.bounty))) continue;
      bounty[count(bounty)] = l.bounty;
      avail[l.bounty] = can_has_bounty(count(bounty)-1);
      vprint(bstring(count(bounty)-1), avail[l.bounty] ? "green" : "red",3);
   }
   if (count(bounty) == 1) foreach i,r in bounty
      print("Now hunting: "+bstring(i)+" (hunted so far: "+item_amount(r)+")","blue");
   return page;
}
visit_bhh("");

maybe it would be better to replace $locations[] with a list of all actual bounty locations?
 
I think the current system is better, as it allows for new/unknown bounties to be possibly accepted without needing the script to be modified each time. But that's my opinion... take it as you will. :)
 
I think the current system is better, as it allows for new/unknown bounties to be possibly accepted without needing the script to be modified each time. But that's my opinion... take it as you will. :)

I can agree with that. That means the script will just have to exempt the duplicate locations and search a lot of extras.
 
Bale, I like your fix. Although, if you care about a few milliseconds it should probably go after the following line.

In the interest of making it easier for visitors to this thread, here's one with all the fixes thus far.
 

Attachments

You're right about the order. However I'm surprised you didn't turn the two if statements into a single statement connected with ||.
 
Back
Top