ZLib -- Zarqon's useful function library

It should probably be noted that the exe update does not work with the updated zlib, use the first jar file instead.
 
Or maybe you should just post a big red warning label in the thread for those who weren't following our discussion in the feature request forum.

Warning: You need to update to a daily build of KolMafia when you update zlib or else some scripts will stop working.

That would be useful as the warning message that comes up when zlib checks its version and tells you to "go here" to download the newest one. I got caught by this until I read this thread.

I guess it's the type of thing you only get caught by once though. I hope.
 
It should probably be noted that the exe update does not work with the updated zlib, use the first jar file instead.

I put in the request to get this updated for zlib, and for the use of bale's scripts.

I think it was ignored so users of the .exe file will have to wait until Monday to use their Zlib enabled scripts. The .jar works great in the meantime.
 
Last edited:
I should just mention that if for whatever reason (habit, comfort) you are limited to using the exe and don't want to try the more-current jars, and you still have ZLib 7 around, use that until the next exe is available, and everything will still work just fine. The only significant update to ZLib in 8 was the removal of some functions which were added to ASH, to avoid errors / overloading those functions (not sure which, actually).
 
Question!

ZLib's use_upto() currently returns the result of the ASH function use(), which gives unpredictable and essentially useless results. I am considering changing this function to instead return the number of items successfully used (meaning no longer in inventory -- thus the result will be 0 for items that are not consumed upon use, even if they were successfully used).

My question is: should I make this change? The return value would be more useful, but I'm not sure that anyone is even using the return value, and I also want to consider potential effort in rewriting existing scripts.
 
Hey zarqon I have a function that might be worth adding in some form to zlib:

Code:
location[monster] find_item_location(item to_find)
{
    // Return array
    location[monster] locs;

    // Loop through all monsters looking for the item drop
    foreach m in $monsters[]
    {
        int[item] drops = item_drops(m);
        foreach i in drops
        {
            if (to_find == i)
            {
                locs[m] = $location[none];
            }
        }            
    }

    // Now see if our monsters are found in a location (as opposed to fighting from an item for example)
    foreach l in $locations[]
    {
        monster[int] mons = get_monsters(l);

        foreach m in mons
        {
            if (locs contains mons[m])
            {
                locs[mons[m]] = l;
            }      
        }
    }

    print("The following monsters drop " + to_find + ":");
    foreach m in locs
    {
        print(m + " found in " + locs[m]);
    }

    return locs;
}
 
Last edited:
Cool! Here's a more compact version of same using some newer ASH capabilities:

Code:
location[monster] find_item_location(item to_find) {
   location[monster] locs;
   foreach l in $locations[]
      foreach num,m in get_monsters(l)
         foreach i in item_drops(m)
            if (to_find == i) locs[m] = l;
   print("The following monsters drop "+to_find+":");
   foreach m in locs print(m+" found in "+locs[m]);
   return locs;
}

What are some uses you're making of this? I can see it being useful in company with can_adv() for something like Ascend or Checklist, but are there other more trivial uses?
 
That's about the best usage. It's nice on an alias if you want to do a quick look up on what monster drops something.

The reason I had that first loop was to get a list of all monsters in the event the item you were looking for dropped from a monster that isn't found in a location but there are very few of those monsters. It wasn't taking very long to process regardless.
 
I think it would work well in determining where to adventure for NS required items. Mafia tells you what you need but don't tell you where to get it. If there is a way to get it to work for items that don't specifically drop from monsters that would be a ++. For example, black pepper.
 
Thanks for sharing this function Rinn. :)
As you mentioned Z, Rinn's function seems particularly useful for quest scripts. Right now whenever I have a group of items I need to obtain I hard code a map with the locations where the items drop. If there is a way to check the drop rates at particular locations an option to just return the location with the highest drop rate for the passed item would be nice. I'm not sure how many items this would actually effect however.
 
I think the best uses of this function are:

1) as an alias, as follows:

Code:
alias wheretofind => ash location[monster] locs; foreach l in $locations[] foreach num,m in get_monsters(l) foreach i in item_drops(m) if (i == to_item("%%")) locs[m] = l; print("The following monsters drop "+to_item("%%")+":"); foreach m in locs print(m+" found in "+locs[m]);

I've already aliased this. It's handy!

2) In concert with can_adv(), returning a single best possible location, which would probably often be used as the third parameter in obtain(). Unfortunately, mredge and FN Ninja made me realize this is a much bigger project than the original function. If it's considering drop rates it should also factor in multiple monsters in the same zone that drop an item, whether the item is pickpocket-only, whether it's a shirt and you lack Torso, etc.

This use seems like more of a project for a script, rather than a single function.
 
Hey, I've installed Zlib (version 8.0) to the scripts directory, and am running the latest java build ( version 7785 ) yet when I run Zlib.ash to set up the vars text file, and also whenever I run any script with imports Zlib (such as CounterChecker.ash by Bale) a box entitled Input pops up with the text "Please input a value for string setval" and a text box below for me to enter text below it. Following this, whenever I try to enter something, or leave it blank, it aborts with the message "Proper syntax is settingname = value" in red. I have no idea what I am meant to be entering in this box, nor what it is referring to?

Thanks,
 
Last edited:
ZLib, for the most part, should not be run directly. The only reason you would run ZLib directly is to edit an existing setting, and settings are created by the scripts that use them, not just by ZLib (although ZLib creates a few settings too). So, instead you should probably just run the script you want to run -- ignore ZLib unless there's a setting you need to configure.

CounterChecker is intended for use as a counterScript and should also not be run directly. See the relevant thread for instructions on how to use that script.
 
I know you were bitten by a regexp as a child, but if you're interested (for my recovery script) I recently rewrote check_version() to use regexp instead of excise(). Moving my changes back into zlib's check_version I get this:

Code:
void check_version(string soft, string prop, string thisver, int thread) {
   if (get_property("_version_"+prop) != "") return;
   print("Checking for updates (running "+soft+" ver. "+thisver+")...");
   matcher check_version = create_matcher("<b>"+soft+" (.+?)</b>" , visit_url("http://kolmafia.us/showthread.php?t="+thread));
   if (check_version.find()) {
      string ver = check_version.group(1);
      set_property("_version_"+prop,thisver);
      if (ver != thisver) {
          print("New version available: "+ver,"red");
          if (!user_confirm("A newer version of "+soft+" is available.  Continue anyway?"))
             abort(soft+" stopped.  Visit http://kolmafia.us/showthread.php?t="+thread+" for the latest version.");
      }
   } else { print("Unable to load current version info."); return; }
}
 
Funny, I just rewrote check_version() too. I threw in your change before posting the update since programmers seem to like regexes for some reason. *shudders*

ZLib now contains THREE (count them: three) regexes. I hope that makes it sufficiently impressive for all those other tiny-minded programmers that don't go near them, with or without poles of any length (such as myself).

Several vociferous participants in this thread will be happy with the latest update.
 
Ooooh! No more pop-up confirmation for a new version! :D

I hope those tweezers and gloves helped you with the regex. ;)
 
I think I should also mention this particular update in the thread:

You can now type "zlib vars" in the CLI to see all your current script settings. This is quite useful since you can also set vars using the CLI. ("zlib settingname = value")
 
I think there is a problem with the update setting in Zlib.
I get the following when I run it:
Code:
New Version of ZLib Available: : 8
Upgrade ZLib from : 9 to : 8 here: http://kolmafia.us/showthread.php?t=2072
Countdown: 25 seconds...
 
Holy hell... what happened....

ZLib is is pausing to try and make me update to ZLib: 8 during EVERY battle! Every script that uses ZLib is seriously slowed down for me, thanks to having to stop for this new version stuff! HALP!?

EX:
[8219] Beanbat Chamber
Encounter: beanbat
Round 0: braska wins initiative!
Adjusted combat item count: divine blowout
> Upgrade ZLib from : 9 to : 8 here: http://kolmafia.us/showthread.php?t=2072
> Checking for updates (running First Things First ver. 3.2)...
> You have a current version of First Things First.
> Checking for updates (running SmartStasis ver. 1.9.2)...
> You have a current version of SmartStasis.
Round 1: braska tries to steal an item!
Round 1: beanbat takes 45 damage.
You gain 148 Meat
You acquire an item: enchanted bean
You gain 4 Muscleboundness
You gain 1 Mysteriousness
You gain 4 Roguishness
> Upgrade ZLib from : 9 to : 8 here: http://kolmafia.us/showthread.php?t=2072

[8220] Beanbat Chamber
Encounter: beanbat
Round 0: braska wins initiative!
> Upgrade ZLib from : 9 to : 8 here: http://kolmafia.us/showthread.php?t=2072
Round 1: braska tries to steal an item!
You acquire an item: enchanted bean
Round 2: braska attacks!
Round 2: beanbat takes 550 damage.
You gain 179 Meat
You gain 1 Strongness
You gain 2 Magicalness
You gain 6 Sarcasm
> Upgrade ZLib from : 9 to : 8 here: http://kolmafia.us/showthread.php?t=2072

[8221] Beanbat Chamber
Encounter: beanbat
Round 0: braska wins initiative!
> Upgrade ZLib from : 9 to : 8 here: http://kolmafia.us/showthread.php?t=2072
Round 1: braska tries to steal an item!
You acquire an item: enchanted bean
Round 2: braska attacks!
Round 2: beanbat takes 23 damage.
You lose 5 hit points
Round 3: braska attacks!
Round 3: beanbat takes 13 damage.
You lose 4 hit points
You lose 1 hit point
You gain 132 Meat
You gain 3 Fortitude
You gain 3 Mysteriousness
You gain 3 Cheek
> Upgrade ZLib from : 9 to : 8 here: http://kolmafia.us/showthread.php?t=2072
 
Last edited:
The previous version stored the local script's version in the property, the new version stores the current version's. You need to clear that property. Try this.

> set _version_zlib =

_version_zlib =>

> zlib

Checking for updates (running ZLib ver. : 9)...
_version_zlib => : 9
You have a current version of ZLib.
 
Back
Top