Difference between pages "Zlib" and "Daily Deeds"

From Kolmafia
(Difference between pages)
Jump to navigation Jump to search
imported>Zarqon
 
imported>Darzil
 
Line 1: Line 1:
{{TOCright}}{{DISPLAYTITLE:ZLib (zlib.ash)}}
+
Basic daily deed customization allows you to show/hide elements on the daily deeds panel, and to reorder those elements as desired.  More advanced customization features include adding "custom deeds" that can perform a variety of tasks: everything from performing a CLI command, to using an item or casting a skill, to executing ASH scripts.
{{Attention|
 
This page details the use of functions in a script library. The information here is only useful to those who have followed the included steps to make use of these functions; they are not built-in to KoLmafia.
 
}}
 
== About ZLib ==
 
ZLib is a function library intended to make life easier for both script authors and script users.  A more detailed introduction, as well as the current version and instructions on installing it, can be found in the [http://kolmafia.us/showthread.php?2072 ZLib thread].
 
  
== String Functions ==
+
== Customizing Daily Deeds ==
  
{{HideLink|excise}}{{Function|
+
Daily Deeds customization essentially involves editing a user preference in order to specify the elements shown on the Daily Deeds panel.  Fortunately, a GUI exists to aid you in performing the most common tasks. This is reached by going to Preferences > Daily Deeds tab.
name=excise|
 
return_type=string|
 
parameter1={{Param|string|source}}|
 
parameter2={{Param|string|start}}|
 
parameter3={{Param|string|end}}|
 
p1desc=The original {{pspan|source}} string|
 
p2desc={{pspan|start}} after this string|
 
p3desc={{pspan|end}} before this string|
 
}}
 
This function returns a portion of the {{pspan|source}} string, from after the first occurrence of {{pspan|start}} to just before the first occurrence of {{pspan|end}}. If either {{pspan|start}} or {{pspan|end}} are missing, it will return an empty string. You can also supply either {{pspan|start}} or {{pspan|end}} as blank strings to specify the actual start or end of the {{pspan|source}} string.
 
  
{{HideLink|equals}}{{Function|
+
To edit which deeds are shown, look at the bottom of this panel.  Each element represents a line on your Daily Deeds panel.  Many of these are individual buttons; "Breakfast", for example, is a button that simply executes breakfast. Some deeds are more complicated, such as the "Demon Summoning" deed that adds a combobox filled with your currently known summons.  Still others simply represent informational lines of text displayed by default at the bottom.  You can rearrange these at will by dragging and dropping. Remove unwanted deeds by pressing the delete key; re-add them by dragging and dropping the appropriate element from the "Built-in Deeds" box up above.
name=equals|
 
return_type=boolean|
 
parameter1={{Param|string|s1}}|
 
parameter2={{Param|string|s2}}|
 
p1desc={{pspan|s1}} is a string.|
 
p2desc={{pspan|s2}} is the string to compare with {{pspan|s1}}.|
 
}}
 
Since string comparisons in ASH using == and != are case-insensitive, this function allows you to strictly compare two strings, including case sensitivity.
 
  
{{HideLink|vprint}}{{Function|
+
To start creating custom deeds, click the "add custom" button.  A GUI will pop up which will help you build custom command, item, skill, and/or text deedsCombo deeds for now (and likely forever) will need to be hand-coded if you want to use them.
name=vprint|
 
return_type=boolean|
 
parameter1={{Param|string|message}}|
 
parameter2={{Param|int|level}}|
 
}}
 
{{Function|
 
name=vprint|
 
return_type=boolean|
 
parameter1={{Param|string|message}}|
 
parameter2={{Param|string|color}}|
 
parameter3={{Param|int|level}}|
 
p1desc={{pspan|message}} and {{pspan|color}} are used as in the function {{f|print}}|
 
p2desc={{pspan|level}} controls the return value and specifies the verbosity level of the message|
 
}}
 
This function is an enhanced version of the ASH function {{f|print}}The {{pspan|message}} and optional {{pspan|color}} parameters are exactly like in print(), but the {{pspan|level}} parameter gives you a lot of additional control.  Specifically, it allows you to control the return value, specify the verbosity level of the output, and maybe even abort the script.
 
  
First, the return value.  If level is positive, it returns true.  If negative, it returns false.  If level is 0, vprint() will abort with the specified message. You can see now that vprint effectively replaces both {{f|abort}} and print.  I recommend it as your go-to function anytime you need to show anything in the CLI, for any reason.
+
==== Example ====
 +
The following image is created by this declaration
  
Having a boolean return value (as opposed to ASH's print returning void) allows you to include helpful information in your script easily, without needing to significantly edit your code.  For example:
+
<pre style="white-space:pre-wrap;">
{{CodeSample|
+
> get dailyDeedsOptions
code=
 
<syntaxhighlight>
 
// add debugging info to an if check:
 
if (somevar == 2 && vprint("somevar equals 2",10)) dosomething();
 
// add additional info to a return true/false:
 
if (everythingsgreat) return vprint("Everything's great!",7);
 
  else return vprint("Everything is not great.",-7);
 
</syntaxhighlight>}}
 
  
Secondly, level represents the verbosity of the message.  ZLib includes a script setting called "verbosity".  Users can adjust this value to specify how verbose they want scripts to be. If they set it to 1, they want the script to print almost nothing -- only the most important messages.  If they set it to 10, they want it to print a lot of details. The level of each vprint command thus determines whether or not the message will actually be printed. If the absolute value of level is more than verbosity, the message will not be printed.  For example, a user with the default verbosity of 3 would not see any of the example messages given above. This allows users to control the chattiness of scripts, and allows authors to include helpful debugging print statements which can be shown by setting verbosity high.
+
$CUSTOM|Text|Demonstration of customized Daily Deeds,$CUSTOM|Text|//\\//\\//\\ by Roippi //\\//\\//\\,$CUSTOM|Text| ,$CUSTOM|Text|This is a built-in deed:,VIP Pool,$CUSTOM|Text|So is this:,April Shower,$CUSTOM|Text| ,$CUSTOM|Text|This is a custom "Command" button that tracks a preference (hermitHax0red),$CUSTOM|Text|If/when hermitHax0red is true,| this deed is greyed out.,$CUSTOM|Text|When clicked|,| it gets clovers.,$CUSTOM|Command|Is the hermit hax0red?|hermitHax0red|hermit * clover,$CUSTOM|Text| ,$CUSTOM|Text|This is a custom line of text that also tracks some preferences:,$CUSTOM|Text|I've ascended |knownAscensions| times. My last adventure was in zone: |lastAdventure,$CUSTOM|Text| ,$CUSTOM|Text|This is a "Skill" type button. It has a few uses,| but usually tracks a multi-use skill with an arbitrary limit:,$CUSTOM|Skill|get me some BRICKOs|libramSummons|summon brickos|7,$CUSTOM|Text| ,$CUSTOM|Text|Lastly,| here is a multiple Command deed.,$CUSTOM|Text|You define the displayText,| an int preference,| the button command,| and the preference disabling threshold.,$CUSTOM|Text|It is up to you to make the preference track whatever your button is doing.,$CUSTOM|Command|Run my custom ASH script up to 5 times|_farmingLoops|call farm.ash|5,$CUSTOM|Text| ,$CUSTOM|Text|You can define your own preferences and call ash scripts with your button commands.,$CUSTOM|Text|I haven't demonstrated all of the different types and overloaded variants here,| but this should be a good starting place.,$CUSTOM|Text|Have fun.
 +
</pre>
  
'''Recommendations for Verbosity Levels in vprint()'''
+
: [[File:Ddprefs3.JPG]]
  
0: abort error
 
  
+/- 1: absolutely essential (and non-cluttering) information -- use very sparingly, since a verbosity of 1 is basically "silent mode"
+
== Custom Deeds ==
  
+/- 2: important and useful info -- this should generally be your base level for your most important messages
+
All deeds are specified by one comma-delimited preference "dailyDeedsOptions". Order matters. Built-in deeds are simply called by referring to their built-in name; these are viewable by pulling up the Daily Deeds tab and looking in the "Built-in Deeds" list.
  
+/- 4: interesting but non-essential information
+
Custom deeds provide the user with a way of adding buttons or text to their daily deeds panel that is not natively provided for. All deeds start with the keyword '''$CUSTOM''' followed by a pipe symbol, '''|'''. As you are constructing a custom deed, you separate the different arguments with pipes.
  
+/- 6: info which an overly curious person might like to see on their CLI
+
All deed types except for Text and Simple require a preference to track. If you want to add a button that is always enabled, use a dummy preference (you do not have to create one, just specify one that doesn't exist, such as "false").
  
+/- 10: details which are only helpful for debugging, such as "begin/end functionname()" or "current value of variable: value"
+
There are currently 6 different types of custom deeds. Remember that all of these "acceptable forms" are prefaced by $CUSTOM|.
  
 +
==== Simple ====
 +
As the name implies, this type of deed is the simplest to use.  Designed for users who do not want to muck around with preferences.
  
This will allow users who want extra levels of detail printed to see that detail without cluttering the CLI for users who don't prefer to see all the details. In addition, it allows users to specify a verbosity of 0 to see ONLY mafia output (no script output at all), which could prove handy.
+
acceptable forms:
  
The color parameter is optional.  If you omit it, the default color is black for positive values of level, and red for negative values. Usually, you won't be calling vprint() with the color parameter, unless you want to specify a different color or override the default colors.
+
Simple|displayText
  
{{HideLink|vprint_html}}{{Function|
+
Simple|displayText|command
name=vprint_html|
 
return_type=boolean|
 
parameter1={{Param|string|message}}|
 
parameter2={{Param|int|level}}|
 
p1desc={{pspan|message}} is used as in the function {{f|print_html}}|
 
p2desc={{pspan|level}} is a verbosity reference|
 
}}
 
Same as vprint() above, but wraps {{f|print_html}}.
 
  
{{HideLink|normalized}}{{Function|
+
Simple|displayText|command|maxUses
name=normalized|
 
return_type=string|
 
parameter1={{Param|string|mixvar}}|
 
parameter2={{Param|string|type}}|
 
p1desc={{pspan|mixvar}} is the string to normalize|
 
p2desc={{pspan|type}} is the datatype to normalize to, which can be any primitive type or any typed constant.  You can also specify "list of <type>", for a comma-delimited list of the given type.|
 
}}
 
Returns {{pspan|mixvar}}, normalized to the specified KoLmafia {{pspan|type}}. For example, normalized("badger", "familiar") would return "Astral Badger".  It can also normalize comma-delimited lists of any of these types if you specify "list of <type>" for {{pspan|type}}.  For example, normalized("bloop, dair go, possess", "list of monster") would return "Blooper, Dairy Goat, Possessed Silverware Drawer".
 
  
{{HideLink|join}}{{Function|
+
Simple|displayText|command|maxUses|toolTip|compMessage
name=join|
 
return_type=string|
 
parameter1={{Param|string [int]|pieces|ag=t}}|
 
parameter2={{Param|string|glue}}|
 
p1desc={{pspan|pieces}} is a map of strings which you want to join into a single string.|
 
p2desc={{pspan|glue}} is the string to put between the pieces.|
 
}}
 
This function is the opposite of the ASH function {{f|split_string}}.  It joins {{pspan|pieces}}together, inserting {{pspan|glue}} between each piece, and returns the assembly as a single string.  Useful for working with comma-delimited lists (or anything-delimited lists, actually).
 
  
{{HideLink|rnum}}{{Function|
+
*displayText - the text that will be displayed on the button
name=rnum|
+
*command - the command to execute. If not specified, will default to displayText.
return_type=string|
+
*maxUses - an arbitrary integer. Specifies a threshold to disable the button at. A counter in the form of <clicks>/<maxUses> will be displayed to the right of the button.
parameter1={{Param|int|n}}|
+
*toolTip - text that will display when you mouse over the button.
}}
+
*compMessage - message that displays when you have used the button (maxUses times if specified), rather than the button vanishing.
{{Function|
 
name=rnum|
 
return_type=string|
 
parameter1={{Param|float|n}}|
 
}}
 
{{Function|
 
name=rnum|
 
return_type=string|
 
parameter1={{Param|float|n}}|
 
parameter2={{Param|int|place}}|
 
p1desc={{pspan|n}} is a number|
 
p2desc={{pspan|place}} is the number of decimal places to round to|
 
}}
 
Returns your number {{pspan|n}} as a human-readable string. For ints, this means it adds commas where appropriate. For floats, it also rounds to the nearest {{pspan|place}} after the decimal. Default {{pspan|place}} for the float-only version is 2, although it may display fewer digits if they are 0's. Examples: rnum(12580) => "12,580", rnum(3.14152964,3) => "3.142", rnum(4.00008) => "4", rnum(123456789.87654321) => "123,456,789.88". Recommended as a substitute for to_string(int).
 
  
== Number Functions ==
+
After clicking a simple deed, the button will be immediately disabled unless maxUses>1 is specified.
  
{{HideLink|abs}}{{Function|
+
==== Command ====
name=abs|
+
execute a command with a button press
return_type=float|
 
parameter1={{Param|float|n}}|
 
p1desc={{pspan|n}} is any number.|
 
}}
 
Returns the absolute value of the number {{pspan|n}}.  Don't worry if you are working with integers, it will still work just fine.  This function already exists in many programming languages; ZLib makes it handily available in ASH.
 
  
{{HideLink|minmax}}{{Function|
+
acceptable forms:
name=minmax|
 
return_type=float|
 
parameter1={{Param|float|a}}|
 
parameter2={{Param|float|min}}|
 
parameter3={{Param|float|max}}|
 
p1desc={{pspan|a}} is the original number|
 
p2desc={{pspan|min}} is the minimum return value|
 
p3desc={{pspan|max}} is the maximum return value|
 
}}
 
Returns {{pspan|a}}, but no less than {{pspan|min}} and no more than {{pspan|max}}.  Another function common to many languages.
 
  
{{HideLink|set_avg}}{{Function|
+
Command|displayText|preference
name=set_avg|
 
return_type=void|
 
parameter1={{Param|float|to_add}}|
 
parameter2={{Param|string|which_prop}}|
 
p1desc={{pspan|to_add}} is the data point to add|
 
p2desc={{pspan|which_prop}} is the property to add data to|
 
}}
 
Useful for adding spading to scripts. Adds one more statistic to an average value being stored in a property. For example, calling this script three times with the values 2, 4, and 6 for {{pspan|to_add}} would result in the property {{pspan|which_prop}} containing "4.0:3", with 4.0 being the average of the three numbers added and 3 being the amount of numbers averaged.
 
  
{{HideLink|get_avg}}{{Function|
+
Command|displayText|preference|command
name=get_avg|
 
return_type=float|
 
parameter1={{Param|string|which_prop}}|
 
p1desc={{pspan|which_prop}} is the property to access|
 
}}
 
Returns an average value set by set_avg().
 
  
{{HideLink|eval}}{{Function|
+
Command|displayText|preference|command|maxUses
name=eval|
 
return_type=float|
 
parameter1={{Param|string|expression}}|
 
parameter2={{Param|float [string]|values|ag=t}}|
 
p1desc={{pspan|expression}} is the base expression|
 
p2desc={{pspan|values}} is a map of values to replace|
 
}}
 
By Jason Harper. Evaluates {{pspan|expression}} as a math expression, and allows you to substitute {{pspan|values}} for variables, as described in much greater detail here. A brief version of this documentation is also included in ZLib. (NB: This section needs more infoz.)
 
  
== Script Functions ==
+
Command|displayText|preference|command|maxUses|toolTip|CompMessage
  
{{HideLink|check_version}}{{Function|
+
*preference - the preference to track for enabling/disabling the buttonDefault threshold for disabling the button is 1 if maxUses is not specified.
name=check_version|
 
return_type=string|
 
parameter1={{Param|string|software}}|
 
parameter2={{Param|string|property}}|
 
parameter3={{Param|string|this_version}}|
 
parameter4={{Param|int|thread}}|
 
p1desc={{pspan|software}} is the script name, which must match the page source of the {{pspan|thread}} being parsed|
 
p2desc={{pspan|property}} is used as part of the name of the property saved to user preferences|
 
p3desc={{pspan|this_version}} is the version of the script currently running|
 
p4desc={{pspan|thread}} is the script's thread-number on kolmafia.us|
 
}}
 
Server-friendly once-daily version-checking. If the user hasn't checked yet today, visits the specified {{pspan|thread}} on the kolmafia.us forums to find the current version of your script. The thread must include <nowiki>"<b></nowiki>{{pspan|software}} {{pspan|version}}<nowiki></b>"</nowiki> for the version info to be successfully parsed. Optionally, you may include <nowiki>"[requires revision XXXX]"</nowiki> somewhere in your post if you want to indicate a required minimum revision of mafia. If a new version is available, it alerts the user in large text and provides an update linkThe return value is a blank string unless an update is found, in which case it is a <nowiki><div class='versioninfo'></nowiki> containing the update message. This allows this function to work equally well for relay scripts. The current version (and the last date checked) is stored in a data file "zversions.txt".  Example:
 
{{CodeSample|
 
code=
 
<syntaxhighlight>
 
check_version("Hardcore Checklist","checklist","1.2.7",1045);
 
</syntaxhighlight>}}
 
  
{{HideLink|load_current_map}}{{Function|
+
Further information regarding custom preferences and button enabling/disabling can be found [http://kolmafia.us/showthread.php?7347-Daily-Deeds-support&p=58295&viewfull=1#post58295 here].
name=load_current_map|
 
return_type=boolean|
 
parameter1={{Param|string|map_name}}|
 
parameter2={{Param|aggregate|destination}}|
 
p1desc={{pspan|map_name}} is the name of the map, without the file extension|
 
p2desc={{pspan|destination}} is a previously-declared map to load with data|
 
}}
 
Acts as a wrapper for the built-in {{f|file_to_map}} with automatic update capability. The first time the function is called for a given map each day, it will check [http://zachbardon.com/mafiatools/autoupdate.php Zarqon's Map Manager] to see if an update for the given {{pspan|map_name}} is available, and if so will load from there. Otherwise, it merely loads it from disk. (Note: you should not include a file extension, such as ".txt" in the {{pspan|map_name}} parameter.)
 
  
{{HideLink|setvar}}{{Function|
+
==== Item ====
name=setvar|
+
this button will use fuzzy matching to find the name of the item specified. Will execute "use <itemName>" when clicked. Will only be visible when you possess one or more of the item.
return_type=void|
 
parameter1={{Param|string|name}}|
 
parameter2={{Param|mixed|dfault}}|
 
p1desc={{pspan|name}} is the name of the setting|
 
p1desc={{pspan|dfault}} can be any primitive or ASH type (e.g. item, effect, coinmaster, etc.), but not an array, map, or record.|
 
}}
 
This function ensures that a ZLib script setting called {{pspan|name}} exists.  If not, it creates it and sets it to {{pspan|dfault}}.  If the setting already exists, it normalizes it to the same type as {{pspan|dfault}}, but otherwise does nothing.  Note that this function is for initializing settings, not for editing existing settings.  That is done by calling ZLib in the CLI.
 
  
==== For Users ====
+
acceptable forms:
  
* Script settings are now all saved in one place, separate from mafia properties. I've read more than one post wishing that script-defined settings and mafia properties would be separate. This provides a solution.
+
Item|displayText|preference
* Script settings are independent from scripts. This means that you will no longer need to edit scripts to adjust your settings. Further, when you download a script update, the script will still use your saved settings and you won't need to reset them!
 
* To see all of your current settings, type "zlib vars" in the CLI. You can also type "zlib <whatever>" to see a list of current settings and values containing <whatever>.  To change a setting, type "zlib settingname = value". If you're adjusting threshold, you can use "up" or "down" as the value to adjust your threshold relatively. This is almost exactly as convenient as mafia settings (possibly more so since you don't need to open a text file to find setting names!).
 
* If for some reason you prefer to open a text file, ZLib settings are stored in a file called vars_myname.txt in your data directory.
 
* Scripts that use Zlib script settings will only create these settings when you run them for the first time.  Attempting to edit a nonexisting setting won't work, so you'll need to run a script once (then, usually, mash the ESC key before it actually does anything) before you can configure it.  Script documentation should tell you which settings to change to get your desired behavior.
 
  
==== For Script Authors ====
+
Item|displayText|preference|itemName
  
* Script settings may now be used across scripts, in exactly the same way that mafia properties are. Basically, this works almost exactly like mafia properties, except that new settings can only be created by setvar() or manually editing the file ("zlib nonexistentsetting = value" will fail).
+
Item|displayText|preference|itemName|maxUses
* Settings are only stored if you run a script that defines/uses them. So your settings file will not contain any extraneous unused settings.
 
* Script authors can now test for a setting's existence, which means you can check to see if a user has used a given script. It's almost as good as a script_exists() function. This can allow scripts to work together with other scripts, if they exist!
 
* Scripts with overlapping or related functionality can be designed to access a single shared setting, in much the same way that my scripts have until now all shared a "threshold" mafia setting. Changing a single setting can now change the behavior of every script that accesses that setting.
 
  
==== Functional Details ====
+
Item|displayText|preference|itemName|maxUses|toolTip|compMessage
  
When importing ZLib, it loads a map of your script settings from vars_myname.txt. It is a basic string[string] map called vars. To access a script setting within an ASH script, use vars[varname]. To check if a setting exists you can simply use if (vars contains varname).
+
*itemName - the name of the item that will be used. If not specified, will default to displayText.
  
When a script calls setvar("threshold",4), ZLib checks to see if a variable called "threshold" already exists in vars. If so, since dfault is an integer, it ensures that the value is an integer using normalize() (saving changes if necessary), but unless normalization changed the value, nothing else happensIf "threshold" does not exist in vars, it creates it, sets it to 4, and saves the updated map back to vars_myname.txt.
+
==== Skill ====
 +
cast a skill that is tracked by a boolean or int preference. Will execute "cast <skillName>" when clickedWill not be visible if you don't know the skill.
  
==== Choosing Setting Names ====
+
acceptable forms:
  
The file of script settings will contain all script settings, sorted alphabetically. Also, there is no way to detect if a setting is unused, so if you decide to change the name, the old setting will never be deleted. '''Please think carefully about your setting names.''' If you have a setting named "setting1", a user will probably not have a clue which script that is for or what it does. True, this can be overcome with documentation, but it is far better to have settings that make sense just by looking at them.
+
Skill|displayText|preference
  
'''Recommendations:'''
+
Skill|displayText|preference|skillName
  
1. Use a name that clearly identifies what the setting is/does.
+
Skill|displayText|preference|skillName|maxCasts
  
2. Prefix your setting names with a script identifier. For example, here are some of my One-Click Wossname script settings:
+
Skill|displayText|preference|skillName|maxCasts|toolTip|compMessage
  
{{CodeSample|
+
*skillName- the name of the skill that will be cast. If not specified, will default to displayText. Must be specified if maxCasts are specified.
code=
 
<syntaxhighlight>
 
setvar("ocw_warplan","optimal");
 
setvar("ocw_change_to_meat",true);
 
setvar("ocw_nunspeed",false);
 
setvar("defaultoutfit","current");
 
setvar("ocw_f_default","zombie");
 
setvar("ocw_m_default","");
 
</syntaxhighlight>}}
 
Those settings which are specific to OCW are prefixed with "ocw_" so as to be found together in the settings file. However, some of the settings are usable across scripts, and are not so prefixed. For example, the "defaultoutfit" will be used by nearly all of my adventuring scripts that swap outfits, so no prefix is given.
 
  
== Adventuring Functions ==
+
==== Combo ====
  
{{HideLink|be_good}}{{Function|
+
$CUSTOM|Combo|displayText|preference1|<item block>
name=be_good|
 
return_type=boolean|
 
parameter1={{Param|string|johnny}}|
 
p1desc={{pspan|johnny}} is the thing you want to check -- usually an item or familiar|
 
}}
 
This function, originally created to check whether items were allowed in the Bees Hate You path, has been expanded to an all-purpose check to see whether something is acceptable in your current path.  For example, in a Trendy path, outdated items would not be_good.  Likewise, during Bees Hate You, a familiar containing a 'b' would not be_good.  In Fistcore, anything you hold in your hands is not allowed.  And so forth.
 
  
{{HideLink|tower_items}}{{Function|
+
$CUSTOM|Combo|displayText|preference1|maxUses|<item block>
name=tower_items|
 
aggregate=true|
 
return_type=boolean [string]|
 
}}
 
{{Function|
 
name=tower_items|
 
aggregate=true|
 
return_type=boolean [string]|
 
parameter1={{Param|boolean|combat_safe}}|
 
p1desc={{pspan|combat_safe}} is optional.  Supply it as true if you are in combat.|
 
}}
 
This handy function returns a map of the items you definitely need (value: true) or might need (value: false) to climb the tower.  You can check (tower_items() contains X) to determine whether an item has a nonzero chance of being required for the tower, or check tower_items(X) to determine whether an item has a 100% chance of being needed (i.e. it was indicated necessary by your telescope).  If you haven't yet checked your telescope yet this run, it will also do that to populate the relevant mafia properties, unless you have supplied the optional {{pspan|combat_safe}} parameter as true (you can't access your telescope during combat).
 
  
{{HideLink|have_item}}{{Function|
 
name=have_item|
 
return_type=int|
 
parameter1={{Param|string|to_lookup}}|
 
p1desc={{pspan|to_lookup}} is the item to count|
 
}}
 
A residual function, used by the following and probably in several other scripts. Returns the amount of an item you have both in your inventory and equipped. Similar but not equivalent to the ASH function {{f|available_amount}}, since this function completely ignores your closet and storage.
 
  
{{HideLink|isxpartof}}{{Function|
+
where the <item block> consists of an arbitrary number of:
name=isxpartof|
 
return_type=float|
 
parameter1={{Param|item|child}}|
 
parameter2={{Param|item|ancestor}}|
 
p1desc={{pspan|child}} is the ingredient/component you want to check.|
 
p2desc={{pspan|ancestor}} is the concoction you want to check.|
 
}}
 
In the sentence "child is X part of ancestor", this function returns X.  It assumes the minimum amount of other ingredients necessary.  For example, isxpartof($item[white pixel], $item[digital key]) returns 0.033333335 (1/30), since 30 white pixels are needed.  However, isxpartof($item[red pixel], $item[digital key]) returns 0.03125 (1/32), assuming 1 each of green and blue pixels and 29 other white pixels (rather than 30 each RGB pixels -- 1/90).  This function is used by has_goal(item) but may have uses in your own script.
 
  
{{HideLink|has_goal}}{{Function|
+
$ITEM|displayText|preferenceN|command|
name=has_goal|
 
return_type=float|
 
parameter1={{Param|item|check_me}}|
 
}}
 
{{Function|
 
name=has_goal|
 
return_type=float|
 
parameter1={{Param|monster|check_me}}|
 
}}
 
{{Function|
 
name=has_goal|
 
return_type=float|
 
parameter1={{Param|location|check_me}}|
 
p1desc={{pspan|check_me}} is the item, monster or locationto check|
 
}}
 
At the base of this function is the item parameter version, which returns the chance that the item {{pspan|check_me}} is or results in a goal. If the item is itself a goal or it's your current bounty item, returns 1.0. Otherwise, returns what percentage of a goal the item is, which could be nonzero in two cases: 1) you could get a goal by using the item (returns the chance of success), or 2) the item is an ingredient of a goal.  For example, with a goal of black pepper, has_goal($item[black picnic basket]) would return 0.58.
 
  
When supplied a monster as the parameter for {{pspan|check_me}}, returns the percent chance that encountering the given monster will result in a goal, taking into account +items, pickpocket availability (and +pickpocket), and Torso. For instance, with no +item and black pepper as a goal, has_goal($monster[black widow]) would return 0.087 (0.58 basket contains pepper * 0.15 basket drop rate). Also note that it will add multiple goals together, so with white pixels as a goal, a Blooper would return 2.1.
+
This is a cleaner way of collapsing a number of related command deeds into one combobox element. Note that there is no GUI to help you construct this, you must manually add it to your dailyDeedsOptions preference.
  
When supplied a location as the parameter for {{pspan|check_me}}, returns the chance that adventuring at a given location will yield a goal. For our black pepper example, has_goal($location[black forest]) would return 0.0174 (0.2 black widow appearance rate * 0.087 chance that a widow has black pepper). Presently this accounts for combat frequency modifiers but not Olfaction, and it will be off for areas with noncombats that grant goals, because it assumes that all noncombats do not yield items.
+
*Preference1 - The preference to track for enabling/disabling the '''entire combobox'''. Default threshold is 1 if maxUses is not specified.
 +
*Preference2 - The individual preference to disable each individual item in the combobox. Note that there is no way to supply maxUses for each individual element; 1 (or true) is always the max.
  
These functions also have an optional boolean parameter, usespec.  If supplied as true, these functions will use speculative values.  (See "whatif")
+
A common use of this deed is to create a custom Greatest American Pants combobox:
  
{{HideLink|obtain}}{{Function|
+
<pre style="white-space:pre-wrap;">
name=obtain|
+
$CUSTOM|Combo|GAPants|_gapBuffs|5|$ITEM|free spells|false|equip pants American; gap skill|$ITEM|elem & tough|false|equip pants American; gap structure|$ITEM|+25%ItemD|false|equip pants American; gap vision|$ITEM|+100%Mox|false|equip pants American; gap speed|$ITEM|5xCrit|false|equip pants American; gap accuracy</pre>
return_type=boolean|
 
parameter1={{Param|int|qty}}|
 
parameter2={{Param|string|condition}}|
 
parameter3={{Param|location|place}}|
 
}}
 
{{Function|
 
name=obtain|
 
return_type=boolean|
 
parameter1={{Param|int|qty}}|
 
parameter2={{Param|string|condition}}|
 
parameter3={{Param|location|place}}|
 
parameter4={{Param|string|filter}}|
 
p1desc={{pspan|qty}} is the quantity of the item or choice adventure desired|
 
p2desc={{pspan|condition}} is the item or choice adventure to use as a goal|
 
p3desc={{pspan|location}} is the place to adventure to obtain your goal|
 
p4desc={{pspan|filter}} is an optional combat filter used the same as in {{f|adventure}}|
 
}}
 
Attempts to get {{pspan|qty}} (minus existing) of {{pspan|condition}}, either by purchasing (if you have the KoLmafia preference set), pulling from Hangk's, or adventuring at the specified {{pspan|place}}. It also works with choice adventures.
 
  
{{HideLink|use_upto}}{{Function|
+
[[File:GAPdeed.png]]
name=use_upto|
 
return_type=boolean|
 
parameter1={{Param|int|qty}}|
 
parameter2={{Param|item|thing}}|
 
parameter3={{Param|boolean|purchase}}|
 
p1desc={{pspan|qty}} is the quantity to use|
 
p2desc={{pspan|thing}} is the item to use|
 
p3desc={{pspan|purchase}} is true if KoLmafia should purchase extras if you don't already have {{pspan|qty}}|
 
}}
 
Gets (if purchase is true) and uses {{pspan|qty}} of the item(s) {{pspan|thing}} if possible. Otherwise, uses as many as you have up to {{pspan|qty}}.
 
  
{{HideLink|resist}}{{Function|
+
==== Text ====
name=resist|
 
return_type=boolean|
 
parameter1={{Param|element|resist_it}}|
 
parameter2={{Param|boolean|really}}|
 
p1desc={{pspan|resist_it}} is the element to resist|
 
p2desc={{pspan|really}} is true to actually attemp resistance, false to check only|
 
}}
 
Returns whether you are able to resist a given element {{pspan|resist_it}}, or if {{pspan|really}} is true, attempts to actually achieve that resistance (casting buffs, changing gear, or equipping your Exotic Parrot) and returns its success.
 
  
{{HideLink|my_defstat}}{{Function|
+
acceptable forms:
name=my_defstat|
+
Text|pretty much anything.
return_type=int|
 
parameter1={{Param|boolean|usespec}}|
 
p1desc={{pspan|usespec}} is optional.  If true, uses speculative values rather than real values.|
 
}}
 
Returns the value of your buffed defense stat, taking into account Hero of the Half-Shell.
 
  
{{HideLink|get_safemox}}{{Function|
+
You can supply as many arguments as you want to a Text deed. Any argument that uniquely matches a preference will be replaced by that preference's value. If you want to use a comma in your text, immediately follow the comma with a pipe character so it will not be parsed as the end of the Text deed.
name=get_safemox|
 
return_type=int|
 
parameter1={{Param|location|where}}|
 
p1desc={{pspan|where}} is the location to check for safe moxie|
 
}}
 
Using mafia's location/monster data, returns the safe moxie of a given zone {{pspan|where}}.
 
  
{{HideLink|auto_mcd}}{{Function|
+
[[Category:Tech Support]]
name=auto_mcd|
 
return_type=boolean|
 
parameter1={{Param|int|check_me}}|
 
}}
 
{{Function|
 
name=auto_mcd|
 
return_type=boolean|
 
parameter1={{Param|monster|check_me}}|
 
}}
 
{{Function|
 
name=auto_mcd|
 
return_type=boolean|
 
parameter1={{Param|location|check_me}}|
 
p1desc={{pspan|check_me}} is the int, monster or location to check|
 
}}
 
If your ZLib setting "automcd" is true, automatically adjusts your mind-control device for maximum stat gains based on safe moxie and your ZLib "threshold" setting. Does not adjust for MCD-sensitive areas (certain bosses, Slime Tube), or areas with no known combats. Returns true unless KoLmafia is unable to do so, even though the script thinks it should be capable (still returns true if you can't currently access an mcd-changing device).
 
 
 
{{HideLink|best_fam}}{{Function|
 
name=best_fam|
 
return_type=familiar|
 
parameter1={{Param|string|type}}|
 
p1desc={{pspan|type}} is the type of familiar ability to check for|
 
}}
 
Returns your heaviest familiar of a given type (currently possible: items, meat, produce, stat, delevel). If your ZLib "is_100_run" setting is anything other than $familiar[none], returns that familiar (so you don't have to make the check in your script).
 
 
 
== Kmail Functions ==
 
 
 
{{HideLink|load_kmail}}{{Function|
 
name=load_kmail|
 
return_type=void|
 
parameter1={{Param|string|calledby}}|
 
p1desc={{pspan|calledby}} is optional and allows you to specify the name of the script calling this function, which will be submitted when the script visits api.php. The default value is "ZLib-powered-script".|
 
}}
 
This function parses your kmail inbox in a single server hit and loads it into the global variable "mail", which is of type kmessage[int].  A kmessage is a record type, with the following fields:
 
{{CodeSample|
 
code=
 
<syntaxhighlight>
 
record kmessage {
 
  int id;                  // message id
 
  string type;              // possible values observed thus far: normal, giftshop
 
  int fromid;              // sender's playerid (0 for npc's)
 
  int azunixtime;          // KoL server's unix timestamp
 
  string message;          // message (not including items/meat)
 
  int[item] items;          // items included in the message
 
  int meat;                // meat included in the message
 
  string fromname;          // sender's playername
 
  string localtime;        // your local time according to your KoL account, human-readable string
 
};
 
</syntaxhighlight>}}
 
 
 
Thus, after calling this function your inbox is very easy to work with.  You can foreach over each message if you like, accessing the fields for details.
 
 
 
{{HideLink|process_kmail}}{{Function|
 
name=process_kmail|
 
return_type=void|
 
parameter1={{Param|string|functionname}}|
 
p1desc={{pspan|functionname}} specifies the name of a function designed to parse kmail.|
 
}}
 
If you liked load_kmail(), you'll like this even better.  First off, this function loads your kmail into the mail variable if you haven't already done so.  Next, it calls a function named {{pspan|functionname}} on each kmail message.  The function must be at top level, accept a single kmessage parameter, and return a boolean.  For each kmail in your inbox, if the called function returns true, that message will be deleted once all messages have been processed.
 
 
 
Here's a simple example which will delete all messages from your lovely Pen Pal:
 
{{CodeSample|
 
code=
 
<syntaxhighlight>
 
boolean no_penpal(kmessage m) {
 
  if (m.fromname == "Your Pen Pal") return true;
 
  return false;
 
}
 
process_kmail("no_penpal");
 
</syntaxhighlight>}}
 
 
 
{{HideLink|send_gift}}{{Function|
 
name=send_gift|
 
return_type=boolean|
 
parameter1={{Param|string|recipient}}|
 
parameter2={{Param|string|message}}|
 
parameter3={{Param|int|meat}}|
 
parameter4={{Param|int [item]|goodies|ag=t}}|
 
}}
 
{{Function|
 
name=send_gift|
 
return_type=boolean|
 
parameter1={{Param|string|recipient}}|
 
parameter2={{Param|string|message}}|
 
parameter3={{Param|int|meat}}|
 
parameter4={{Param|int [item]|goodies|ag=t}}|
 
parameter5={{Param|string|inside_note}}|
 
p1desc={{pspan|recipient}} is the player to send to|
 
p2desc={{pspan|message}} is the outside message|
 
p3desc={{pspan|meat}} is the amount of meat to send|
 
p4desc={{pspan|goodies}} is a map of items & amounts to send|
 
p5desc={{pspan|inside_note}} is an optional inside message|
 
}}
 
Sends a gift to a player. Able to split large amounts of items. Returns true if the package is sent and false if not. See kmail() below.
 
 
 
{{HideLink|kmail}}{{Function|
 
name=kmail|
 
return_type=boolean|
 
parameter1={{Param|string|recipient}}|
 
parameter2={{Param|string|message}}|
 
parameter3={{Param|int|meat}}|
 
}}
 
{{Function|
 
name=kmail|
 
return_type=boolean|
 
parameter1={{Param|string|recipient}}|
 
parameter2={{Param|string|message}}|
 
parameter3={{Param|int|meat}}|
 
parameter4={{Param|int [item]|goodies|ag=t}}|
 
}}
 
{{Function|
 
name=kmail|
 
return_type=boolean|
 
parameter1={{Param|string|recipient}}|
 
parameter2={{Param|string|message}}|
 
parameter3={{Param|int|meat}}|
 
parameter4={{Param|int [item]|goodies|ag=t}}|
 
parameter5={{Param|string|inside_note}}|
 
p1desc={{pspan|recipient}} is the player to send to|
 
p2desc={{pspan|message}} is the outside message|
 
p3desc={{pspan|meat}} is the amount of meat to send|
 
p4desc={{pspan|goodies}} is an optional map of items & amounts to send|
 
p5desc={{pspan|inside_note}} is an optional inside message if sent as a gift|
 
}}
 
{{Function|
 
name=kmail|
 
return_type=boolean|
 
parameter1={{Param|kmessage|km}}|
 
p1desc={{pspan|km}} allows you to send a kmail supplied in kmessage format.  The only thing unusual here is that the "fromname" field will be used as the recipient.  The other fields will be used appropriately to call the above kmail function.|
 
}}
 
Sends a kmail to player {{pspan|recipient}}, returning true if the kmail is successfully sent. Handles splitting the {{pspan|message}} into multiple messages if the number of item types in {{pspan|goodies}} is too large. Returns the result of send_gift() if the intended {{pspan|recipient}} is unable to receive the {{pspan|message}} due to being in HC or somesuch. Note that you can also specify the {{pspan|inside_note}} to be used inside gifts in that case. Use "\n" to specify a new line in the {{pspan|message}}.
 
 
 
== More Information ==
 
<p>See the thread for ZLib on the mafia forum [http://kolmafia.us/showthread.php?2072 here].</p>
 
 
 
[[Category:Scripting]][[Category:ASH Function Libraries]]
 

Latest revision as of 20:04, 7 August 2016

Basic daily deed customization allows you to show/hide elements on the daily deeds panel, and to reorder those elements as desired. More advanced customization features include adding "custom deeds" that can perform a variety of tasks: everything from performing a CLI command, to using an item or casting a skill, to executing ASH scripts.

Customizing Daily Deeds

Daily Deeds customization essentially involves editing a user preference in order to specify the elements shown on the Daily Deeds panel. Fortunately, a GUI exists to aid you in performing the most common tasks. This is reached by going to Preferences > Daily Deeds tab.

To edit which deeds are shown, look at the bottom of this panel. Each element represents a line on your Daily Deeds panel. Many of these are individual buttons; "Breakfast", for example, is a button that simply executes breakfast. Some deeds are more complicated, such as the "Demon Summoning" deed that adds a combobox filled with your currently known summons. Still others simply represent informational lines of text displayed by default at the bottom. You can rearrange these at will by dragging and dropping. Remove unwanted deeds by pressing the delete key; re-add them by dragging and dropping the appropriate element from the "Built-in Deeds" box up above.

To start creating custom deeds, click the "add custom" button. A GUI will pop up which will help you build custom command, item, skill, and/or text deeds. Combo deeds for now (and likely forever) will need to be hand-coded if you want to use them.

Example

The following image is created by this declaration

> get dailyDeedsOptions

$CUSTOM|Text|Demonstration of customized Daily Deeds,$CUSTOM|Text|//\\//\\//\\ by Roippi //\\//\\//\\,$CUSTOM|Text| ,$CUSTOM|Text|This is a built-in deed:,VIP Pool,$CUSTOM|Text|So is this:,April Shower,$CUSTOM|Text| ,$CUSTOM|Text|This is a custom "Command" button that tracks a preference (hermitHax0red),$CUSTOM|Text|If/when hermitHax0red is true,| this deed is greyed out.,$CUSTOM|Text|When clicked|,| it gets clovers.,$CUSTOM|Command|Is the hermit hax0red?|hermitHax0red|hermit * clover,$CUSTOM|Text| ,$CUSTOM|Text|This is a custom line of text that also tracks some preferences:,$CUSTOM|Text|I've ascended |knownAscensions| times. My last adventure was in zone: |lastAdventure,$CUSTOM|Text| ,$CUSTOM|Text|This is a "Skill" type button. It has a few uses,| but usually tracks a multi-use skill with an arbitrary limit:,$CUSTOM|Skill|get me some BRICKOs|libramSummons|summon brickos|7,$CUSTOM|Text| ,$CUSTOM|Text|Lastly,| here is a multiple Command deed.,$CUSTOM|Text|You define the displayText,| an int preference,| the button command,| and the preference disabling threshold.,$CUSTOM|Text|It is up to you to make the preference track whatever your button is doing.,$CUSTOM|Command|Run my custom ASH script up to 5 times|_farmingLoops|call farm.ash|5,$CUSTOM|Text| ,$CUSTOM|Text|You can define your own preferences and call ash scripts with your button commands.,$CUSTOM|Text|I haven't demonstrated all of the different types and overloaded variants here,| but this should be a good starting place.,$CUSTOM|Text|Have fun.
Ddprefs3.JPG


Custom Deeds

All deeds are specified by one comma-delimited preference "dailyDeedsOptions". Order matters. Built-in deeds are simply called by referring to their built-in name; these are viewable by pulling up the Daily Deeds tab and looking in the "Built-in Deeds" list.

Custom deeds provide the user with a way of adding buttons or text to their daily deeds panel that is not natively provided for. All deeds start with the keyword $CUSTOM followed by a pipe symbol, |. As you are constructing a custom deed, you separate the different arguments with pipes.

All deed types except for Text and Simple require a preference to track. If you want to add a button that is always enabled, use a dummy preference (you do not have to create one, just specify one that doesn't exist, such as "false").

There are currently 6 different types of custom deeds. Remember that all of these "acceptable forms" are prefaced by $CUSTOM|.

Simple

As the name implies, this type of deed is the simplest to use. Designed for users who do not want to muck around with preferences.

acceptable forms:

Simple|displayText

Simple|displayText|command

Simple|displayText|command|maxUses

Simple|displayText|command|maxUses|toolTip|compMessage

  • displayText - the text that will be displayed on the button
  • command - the command to execute. If not specified, will default to displayText.
  • maxUses - an arbitrary integer. Specifies a threshold to disable the button at. A counter in the form of <clicks>/<maxUses> will be displayed to the right of the button.
  • toolTip - text that will display when you mouse over the button.
  • compMessage - message that displays when you have used the button (maxUses times if specified), rather than the button vanishing.

After clicking a simple deed, the button will be immediately disabled unless maxUses>1 is specified.

Command

execute a command with a button press

acceptable forms:

Command|displayText|preference

Command|displayText|preference|command

Command|displayText|preference|command|maxUses

Command|displayText|preference|command|maxUses|toolTip|CompMessage

  • preference - the preference to track for enabling/disabling the button. Default threshold for disabling the button is 1 if maxUses is not specified.

Further information regarding custom preferences and button enabling/disabling can be found here.

Item

this button will use fuzzy matching to find the name of the item specified. Will execute "use <itemName>" when clicked. Will only be visible when you possess one or more of the item.

acceptable forms:

Item|displayText|preference

Item|displayText|preference|itemName

Item|displayText|preference|itemName|maxUses

Item|displayText|preference|itemName|maxUses|toolTip|compMessage

  • itemName - the name of the item that will be used. If not specified, will default to displayText.

Skill

cast a skill that is tracked by a boolean or int preference. Will execute "cast <skillName>" when clicked. Will not be visible if you don't know the skill.

acceptable forms:

Skill|displayText|preference

Skill|displayText|preference|skillName

Skill|displayText|preference|skillName|maxCasts

Skill|displayText|preference|skillName|maxCasts|toolTip|compMessage

  • skillName- the name of the skill that will be cast. If not specified, will default to displayText. Must be specified if maxCasts are specified.

Combo

$CUSTOM|Combo|displayText|preference1|<item block>

$CUSTOM|Combo|displayText|preference1|maxUses|<item block>


where the <item block> consists of an arbitrary number of:

$ITEM|displayText|preferenceN|command|

This is a cleaner way of collapsing a number of related command deeds into one combobox element. Note that there is no GUI to help you construct this, you must manually add it to your dailyDeedsOptions preference.

  • Preference1 - The preference to track for enabling/disabling the entire combobox. Default threshold is 1 if maxUses is not specified.
  • Preference2 - The individual preference to disable each individual item in the combobox. Note that there is no way to supply maxUses for each individual element; 1 (or true) is always the max.

A common use of this deed is to create a custom Greatest American Pants combobox:

$CUSTOM|Combo|GAPants|_gapBuffs|5|$ITEM|free spells|false|equip pants American; gap skill|$ITEM|elem & tough|false|equip pants American; gap structure|$ITEM|+25%ItemD|false|equip pants American; gap vision|$ITEM|+100%Mox|false|equip pants American; gap speed|$ITEM|5xCrit|false|equip pants American; gap accuracy

GAPdeed.png

Text

acceptable forms: Text|pretty much anything.

You can supply as many arguments as you want to a Text deed. Any argument that uniquely matches a preference will be replaced by that preference's value. If you want to use a comma in your text, immediately follow the comma with a pipe character so it will not be parsed as the end of the Text deed.