Relay Override Scripting: Difference between revisions
imported>Zarqon |
imported>Zarqon |
||
Line 7: | Line 7: | ||
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, except with an ash extension instead of a php extension. For users who have enabled relay override scripts, mafia will automatically call xyz.ash every time the relay browser attempts to visit xyz.php. | #The name of the script must be the same as the page it is overriding, except with an ash extension instead of a php extension. For users who have enabled relay override scripts, mafia will automatically call xyz.ash every time the relay browser attempts to visit xyz.php. | ||
#Unless the script will display entirely new content | #Unless the script will display entirely new content, it should first load the unmodified page from KoL 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. | ||
<br /> | <br /> | ||
Here is an example of a relay script. | Here is an example of a relay script. Assuming it is named shore.ash, it will modify shore.php to reveal items that are needed for the level 6 tower monster. | ||
<div style="margin-bottom: 1em; border: dashed 1px green; padding: 1em; margin:0px 20px;"><syntaxhighlight> | <div style="margin-bottom: 1em; border: dashed 1px green; padding: 1em; margin:0px 20px;"><syntaxhighlight> | ||
// This script will only work if it is named shore.ash | // This script will only work if it is named shore.ash |
Revision as of 08:52, 30 April 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.
Note that in order to use relay override scripts, you must have the respective KoLMafia preference checked as shown:
Relay Script
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, except with an ash extension instead of a php extension. For users who have enabled relay override scripts, mafia will automatically call xyz.ash every time the relay browser attempts to visit xyz.php.
- Unless the script will display entirely new content, it should first load the unmodified page from KoL using the command visit_url() with no parameters.
- Then the contents of the page can be modified with replace_string() or other string manipulation functions.
- Finally, the modified page is written with the write() command.
Here is an example of a relay script. Assuming it is named shore.ash, it will modify shore.php to reveal items that are needed for the level 6 tower monster.
// 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
There are special kinds of relay scripts; scripts with user interfaces. As with a regular relay override script, they go in the "relay" directory. However, they don't override other pages; their entire content is scripted.
These scripts can be accessed under the relay drop-down from the top pane. Their names must start with "relay_" in order for them to show up there.
More information will be added later. In the meantime, here are two links: