ZLib r25 Updates!
Three lovely new functions have made their way into the latest ZLib:
float isxpartof(item child, item ancestor)
Returns what percentage of an item a given ingredient is. For example,
isxpartof(white pixel, digital key) returns 0.033333 (1/30th). However,
isxpartof(red pixel, digital key) returns 0.03125 (1/32nd), not 1/90th, since it assumes the minimum amount of items needed (29 white pixels + 1 of each red/blue/green).
has_goal(item) now uses this new function, so if you're using SS, monsters dropping ingredients of goals will be considered for unsafe pickpocketing and goals Olfaction.
string join(string[int] pieces, string glue)
The opposite of
split_string(), or the same as PHP's
implode() -- joins all of the pieces of an array of strings together using
glue. Useful for working with comma-delimited lists.
void load_kmail()
Uses KoL's server-friendly api.php to load your inbox (up to 100 kmails) into a global map of records named "mail". The records contains all the same info that KoL provides:
PHP:
record kmessage {
int id; // message id (you'll need this to delete the message)
string type; // possible values observed thus far: normal, giftshop
int fromid; // sender's playerid
int azunixtime; // unix timestamp of Arizona time
string message; // message (stripped of anything after the <center> tag)
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 preferences, human-readable string
};
kmessage[int] mail;
Thus, ZLib makes it super easy for scripters to parse incoming kmail, since it also splits items and meat (safely) into their own fields. Just call
load_kmail() in your script and all of your kmail will be readily available for foreaching.
There's also a new version of
kmail() which accepts a kmessage as the parameter -- with the notable idiosyncrasy that it sends the mail
to the name specified in "fromname".