Modular Choice Override

rlbond86

Member
Modular Choice Override 1.3.1

Zlib recommened for update-checking functionality

This is my newest relay script, though it's really more of a framework.
Ever wanted to override a choice adventure, but been frustrated with mafia's lack of support? I have been. It's very difficult to override a single choice adventure and not interfere with other choice adventure overrides. This script is designed to make overriding choice adventures easy and conflict-free. I've also included several of my own relay override scripts:

  • Ronald/Grimace maps
  • The lost key
  • Zombie skills (Lure minions and summon minions)
  • Hyboria? I don't even... helper
  • Orcish Frat House blueprints - reequip your swashbuckling gear automatically
  • Pyramid override (separate zip)
  • Unpermery helper

-----------------------------------------------------

Here's how it works:

  1. Run this in your CLI to download:
    Code:
    svn checkout http://svn.code.sf.net/p/rlbond86-mafia-scripts/code/modular_choice_override/trunk
  2. To override choice adventure #N, create a script called "choice_N.ash" in your /relay folder. This script has a special syntax, discussed below.
  3. When you encounter that choice adventure, it will run the override() function in choice_N.ash.

The syntax for a choice override script is simple:

  1. Import "choice.ash" at the beginning of your script.
  2. Create a function "boolean override(PageData p)", which will be executed when the choice adventure is encountered.
  3. Do something inside this function. If you successfully use write() to output the page, return true. Otherwise, return false.

The PageData structure holds information about the choice adventure page.
  • p.page is a string which contains the HTML of the page. Use this instead of visit_url(), since the page has already been downloaded once.
  • p.fields is a map ( string[string] ) which contains the form fields. Use this instead of form_fields() for the same reason.

Here's an example override script:

choice_600.ash
Code:
import "choice.ash"  // this is REQUIRED in a choice override script. It imports the PageData record definition.
// choice 600: Summon Minion

boolean override(PageData p)
{
	string page = p.page; // get the text from the page
	string wakingDeadText = "<a href=\"http://kol.coldfront.net/thekolwiki/index.php/Waking_the_Dead\" target=\"_blank\">Waking the Dead</a>";

	// insert effect text if applicable
	if (have_skill($skill[Summon Horde]))
	{
		page = replace_string(page, "value=1> time(s)</form>", 
			"value=1> time(s)<br /><font size=-1>(10 turns " + wakingDeadText + ")</font></form>");
	}

	// write to relay browser
	write(page);
	return true;
}

That's the whole file. All the heavy lifting is done by choice.ash, so all you need to do is a little text replacement and output the results. As soon as you drop this into your relay/ folder, choice.ash will call it whenever it encounters choice #600.


If you have zlib, the script will check for updates automatically. If you don't, it'll just annoy you by spamming the CLI with a zlib error, but the script will still work perfectly well.


Changelog:

1.0.0: Initial release
1.1.0: Use page text before checking form field data, to fix one choice adventure calling another. Do not override wumpus choice adventure (#360). Added new relay scripts.
1.3.0: Fixes some choice adventures from being overridden.
1.3.1: Migrated to SVN.
 

Attachments

Last edited:
Clever. I'll have to take a look at the lost key one. That choice adventure always confuses the heck out of me when I do it...
 
I was trying to wrap my head around why you'd want this, and then I *think* I got it...

Say person A has script X that does stuff you really like for adventure 9875, but the script also does stuff you think is borderline brain-dead (mmm, dead brains) to adventure 9110; you'd rather uses person B's way of handling the latter choice adv., but their script doesn't have the cool mods to adventure 99875. This is a way to more easily get around that issue, right?
 
I was trying to wrap my head around why you'd want this, and then I *think* I got it...

Say person A has script X that does stuff you really like for adventure 9875, but the script also does stuff you think is borderline brain-dead (mmm, dead brains) to adventure 9110; you'd rather uses person B's way of handling the latter choice adv., but their script doesn't have the cool mods to adventure 99875. This is a way to more easily get around that issue, right?

More or less. This lets different choice adventure overrides exist together without any interference.
 
I assume what I posted here didn't work?

That method downloads the page twice -- which sometimes can cause problems with choice adventures since it visits the url a second time -- and form_fields() does not work from within a called script. This method passes the HTML text and form fields dynamically to solve those issues. I started from a similar position but needed to solve these problems.
 
Last edited:
That method downloads the page twice -- which sometimes can cause problems with choice adventures since it visits the url a second time -- and form_fields() does not work from within a called script. This method passes the HTML text and form fields dynamically to solve those issues. I started from a similar position but needed to solve these problems.

Ah, righto. Yeah, I think the only way to overcome those issues is to have people to change the original choice overrides so they can be imported, like the way you've done it.

Wasn't criticizing you btw, just wondering if you had seen what I posted and if it actually worked.
 
I haven't checked this script out yet, but if I use this for a choice adventure where I always pick the same choice is it able to auto-matically pick that choice without user interaction, or can I only rewrite the html output so the choice I always pick says something like "Pick this one!"?
 
Your override can pick a choice for you, since it can submit URLs too. Or it can simply decorate the page and add whatever you want to the page.
 
New update! A few bugs fixed. Also, I added a new Hyboria? I don't even... helper script and a script which puts on your swashbuckling gear automatically after you get cap'm caronch's dentures.
 
Very nice script! However I just tried using it to override the "Tales of Dread" choice adventure (#767), and ran into a slight problem:

When you click the 'use' link for the Tales of Dread in your inventory, there is no way that choice.ash can determine the choice adventure number, and the override script isn't called.
But as soon as you click on a tale to read it, the choice_767.ash script is called. Trouble is, if you haven't unlocked any tales, there's nothing you can click which will allow the override to get called.

When I was testing my choice_767.ash script, I ended up just adding the following 2 lines to choice.ash just before the "// if THAT doesn't work, give up." comment:

Code:
    if ((choiceNum == 0) && (page.contains_text("Click a story title to the left to read a Tale of Dread.")))
                choiceNum = 767;

But perhaps there's a better way to handle this? I assume it's because the Tales page is implemented as a choice adventure with no form to submit?
 
The usage of choice.php by KoL in the last couple of months is a Brave New World.

Using certain items redirects into choice.php?forcechoice-0 (or something like that) and you end up in choice.php with only the text on the page itself to let you figure out which one it is. The "haven't unlocked any tales" case is an (extremely) temporary condition which will prevent that from working.

If you want to handle that condition, your solution sounds plausible.
 
The usage of choice.php by KoL in the last couple of months is a Brave New World.

Using certain items redirects into choice.php?forcechoice-0 (or something like that) and you end up in choice.php with only the text on the page itself to let you figure out which one it is. The "haven't unlocked any tales" case is an (extremely) temporary condition which will prevent that from working.

If you want to handle that condition, your solution sounds plausible.

No kidding. It seems like more and more things are being hacked together lately. Some familiars (like the Reanimator) even call main.php?reanimator=something to do their stuff now. It's very odd and hard to work around.

EDIT: The Tales of Dread thing has been fixed.
 
Last edited:
there's a lot of choice adventures where this sort of thing seems to be happening:

I imagine this is fallout from the earlier choice adventure issues (and probably a known issue). I wish I had a list of all the ones I'm noticing, but this is an example from my current GCLI.

Code:
[401] Barrrney's Barrr
Encounter: Arrr You Man Enough?
Detecting     installation status of choice #187 (detected from page text)...
Unable     to invoke choice_187
Choice #187 is not     installed or contains an error.

Detecting     installation status of choice #187 (detected from page text)...
Unable     to invoke choice_187
Choice #187 is not     installed or contains an error.


[402] Barrrney's     Barrr
Encounter: Arrr You Man Enough?
Detecting     installation status of choice #187 (detected from page text)...
Unable     to invoke choice_187
Choice #187 is not     installed or contains an error.

Detecting     installation status of choice #187 (detected from page text)...
Unable     to invoke choice_187
Choice #187 is not     installed or contains an error.
 
Back
Top