Difference between revisions of "Relay Override Scripting"

From Kolmafia
Jump to navigation Jump to search
imported>Bale
(Created page with 'This is a means of changing KoL's web pages so that the user sees something different. There are two kinds of relay override scripts. The first is simply known as an Relay Script…')
 
imported>Bale
Line 4: Line 4:
 
For a simple Relay Script, there are several basic rules:
 
For a simple Relay Script, there are several basic rules:
 
#The name of the script must be the same as the page it is overriding. Mafia will automatically apply the override every time that page is called from KoL.
 
#The name of the script must be the same as the page it is overriding. Mafia will automatically apply the override every time that page is called from KoL.
#First the script will query KoL's page with the command [[visit_url|visit_url()]] with no parameters.
+
#First the script will query KoL's page using the command [[visit_url|visit_url()]] with no parameters.
 
#Then the contents of the page can be modified with [[replace_string|replace_string()]] or other string manipulation functions.
 
#Then the contents of the page can be modified with [[replace_string|replace_string()]] or other string manipulation functions.
 
#Finally, the modified page is written with the [[write|write()]] command.
 
#Finally, the modified page is written with the [[write|write()]] command.

Revision as of 22:56, 31 March 2010

This is a means of changing KoL's web pages so that the user sees something different. There are two kinds of relay override scripts. The first is simply known as an Relay Script. The second is a User Interface script.

Relay Script

For a simple Relay Script, there are several basic rules:

  1. The name of the script must be the same as the page it is overriding. Mafia will automatically apply the override every time that page is called from KoL.
  2. First the script will query KoL's page using the command visit_url() with no parameters.
  3. Then the contents of the page can be modified with replace_string() or other string manipulation functions.
  4. Finally, the modified page is written with the write() command.


Here is an example of a relay script. This will modify shore.php to reveal items that are needed for the level 6 tower monster. The script must be named shore.php in order to modify the correct page.

// This script will only work if it is named shore.ash
void main() {
   buffer results;
   // Get the basic shore page
   append(results, visit_url());
   
   // This will modify the Dude Ranch text if a stick of dynamite is needed
   void dynamite() {
      if(available_amount($item[stick of dynamite]) < 1)
         replace_string(results, "Distant Lands Dude Ranch Adventure",
          "<font color=\"green\"><b>Distant Lands Dude Ranch Adventure"
          +" (stick of dynamite needed)</b></font>");
   }

   // This will modify the Paradise Island text if a tropical orchid is needed
   void orchid() {
      if(available_amount($item[tropical orchid]) < 1)
         replace_string(results, "Tropical Paradise Island Getaway",
          "<font color=\"green\"><b>Tropical Paradise Island Getaway"
          +" (tropical orchid needed)</b></font>");
   }

   // This will modify the Ski Resort text if a barbed-wire fence is needed
   void fence() {
      if(available_amount($item[barbed-wire fence]) < 1)
         replace_string(results, "Large Donkey Mountain Ski Resort",
          "<font color=\"green\"><b>Large Donkey Mountain Ski Resort"
          +" (barbed-wire fence needed)</b></font>");
   }
   
   // Only do this if the character has no access to the mall
   if(!can_interact()) {   
      // If the character has a level 7 telescope, only check for the necessary item
      if(get_property("telescopeUpgrades") == "7")
         switch(get_property("telescope7")) {
         case "see a wooden beam":
            dynamite(); break;
         case "see a formidable stinger":
            orchid(); break;
         case "see a pair of horns":
            fence(); break;
         }
      // Check for all three items
      else {
         dynamite();
         orchid();
         fence();
      }
   }
   
   // Write the modified page to the web browser
   write(results);
}


User Interface Script

More information will be added later. In the meantime, here are two links: