Help to create a script to find which drinks you're missing from Trophy #106

mstieler

Member
So, while I thought I could actually do this, it turns out even with help pointing me in the right direction I still can't get this going.

What I'm trying to do is to get a CLI printout of the 66 Happy Medium drinks, or more specifically, which drinks are still needed to be consumed to get the trophy.

Bale had pointed me to string consumables = visit_url("showconsumption.php"); and that the range to look for is for i from 5573 to 5638 while checking the consumption page with contains_text(consumables, to_item(i)) (I'm probably paraphrasing that all sorts of incorrectly).

I'm pretty sure, once the base of it gets situated, I can attempt to tweak it to do some extra stuff. I'd prefer to not say just yet, just in case someone goes above and beyond and adds it anyways, but we'll see what winds up happening.

Also, I wasn't sure if this should go here or in Scripting Discussion. If needed, please move.
 

Winterbay

Active member
Have you managed to get any kind of printout or is nothing working?

You may need to check for "to_string(to_item(i))", but I'm not sure. Comparisions are not my strongest point :)
 

mstieler

Member
I guess you could say nothing's working, because, short of starting with "void main() {" I'm not certain just how to put it all together....
 

Ethelred

Member
I guess you could say nothing's working, because, short of starting with "void main() {" I'm not certain just how to put it all together....

Well, here's a quick and dirty skeleton that you could flesh out. At least it prints a list of the drinks. I've never consumed one, so I can't verify that the consumption test actually works. But, at least, it doesn't print any false positives.

Code:
#
#    Happy Medium Drink Checker
#
#    V 0.01        4/25/2012    Ethelred
#


void main(  )
{
    
    int ni;
    item it;
    string s;
    string consumables = visit_url("showconsumption.php");
    
    print( "Starting test.", "green");    
    for i from 5573 to 5638
    {
        it = to_item( i );
        s = to_string( it );
        ni = item_amount( it );
        print( "Currently have " + to_string( ni ) + " " + to_string( it ) + ".", "green");    
        if( contains_text(consumables, s ))
        {
            print( "Have consumed " + s + ".", "green");    
        }
    }
    print( "Ending test.", "green");    
        
    return;

}
 
Last edited:
Ninja'd! But here's an alias with output.

> ash string consumables = visit_url("showconsumption.php"); string to_drink; for i from 5573 to 5638 { if(!contains_text(consumables,to_string(to_item(i)))) { to_drink+=to_string(to_item(i))+", "; }} print(to_drink);

Drac & Tan, Transylvania Sling, Shot of the Living Dead, Buttery Knob, Slippery Knob, Flaming Knob, Grasshopper, Locust, Plague of Locusts, Red Dwarf, Golden Mean, Green Giant, Aye Aye, Aye Aye, Captain, Aye Aye, Tooth Tooth, Humanitini, More Humanitini than Humanitini, Oh, the Humanitini, Great Old Fashioned, Fuzzy Tentacle, Crazymaker, Zoodriver, Sloe Comfortable Zoo, Sloe Comfortable Zoo on Fire, Suffering Sinner, Suppurating Sinner, Sizzling Sinner, Firewater, Earth and Firewater, Earth, Wind and Firewater, Slimosa, Extra-slimy Slimosa, Slimebite, Cement Mixer, Jackhammer, Dump Truck, Fauna Libre, Chakra Libre, Aura Libre, Sazerorc, Sazuruk-hai, Flaming Sazerorc, Green Velvet, Green Muslin, Green Burlap, Mohobo, Moonshine Mohobo, Flaming Mohobo, Drunken Philosopher, Drunken Neurologist, Drunken Astrophysicist, Dark & Starry, Black Hole, Event Horizon, Herring Daquiri, Herring Wallbanger, Herringtini, Lollipop Drop, Candy Alexander, Candicaine, Caipiranha, Flying Caipiranha, Flaming Caipiranha, Punchplanter, Doublepunchplanter, Haymaker,
Returned: void

Yeah, I haven't drank any either. Boris hates Mediums.
 
Last edited:

Theraze

Active member
Also, look at Donovan's omnivore script, which looks at which of ALL food/drinks you haven't consumed. Take that and change it from looking through all food/drinks into just checking the desired item numbers, and you're done.
 

mstieler

Member
Alright, both Ethel's & Weather's script & alias work (showing which I have and which I haven't drank, respectively). Tweaking Ethel's script:
Code:
        if( !contains_text(consumables, s ))
        {
            print( "Have NOT consumed " + s + ".", "red");    
        }
So it will give me green text for each of the 66 drinks, counting how many I have in inventory (can this be set to exclude 0, so it only gives me a green reading for the ones I currently have at least 1 of?), and red text indicating which ones are still needed.
 

ereinion

Member
How about this further modification of Ethelred's script, which doesn't print the ones you've already drunk, prints the one you have in your inventory in green, and the ones you don't have in red:

PHP:
#
#    Happy Medium Drink Checker
#
#    V 0.01        4/25/2012    Ethelred. Modified by ereinion
#    

void main() {
  int ni; item it; string s;
  int j = 0;
  string consumables = visit_url("showconsumption.php");
    
  print( "Starting test.", "green");    
  for i from 5573 to 5638 {
    it = to_item( i );
    s = to_string( it );
    ni = item_amount( it );
    if( !contains_text(consumables, s )) {
      print( "Have NOT consumed " + s + ", of which you have " + to_string(ni) + " in your inventory.", (ni==0? "red" : "green"));
      j = j + 1;
    }
  }
  if (j==0) {
    print( "You have drunk all the drinks the spirit medium can produce!", "blue");
  } else {
    print("You have yet to drink " + to_string(j) + " of the drinks the spirit medium can produce.", "blue");
  }
  print( "Ending test.", "green");
}
As you may notice it then sums up how many of the drinks you've yet to consume at the end of the script, and prints that in blue.
 
Last edited:

Bale

Minion
And here's my modification to separate out the list of drinks I've already consumed so that I can enjoy the number going up.

PHP:
#
#    Happy Medium Drink Checker
#
#    V 0.01        4/25/2012    by Ethelred. Modified by ereinion and Bale
#    

void main() {
  int ni; item it; string s;
  boolean [item] consumed;
  string consumables = visit_url("showconsumption.php");
    
  for i from 5573 to 5638 {
    it = to_item( i );
    s = to_string( it );
    ni = item_amount( it );
    if( !contains_text(consumables, s ))
      print( "Have NOT consumed " + s + ", of which you have " + to_string(ni) + " in your inventory.", (ni==0? "red" : "green"));
    else consumed [it] = true;
  }
  if (count(consumed) == 66) {
    print( "You have drunk all the drinks the spirit medium can produce!", "blue");
  } else {
    print(" ");
    foreach it in consumed
      print("Already drunk: "+it, "green");
    print("You have yet to drink " + to_string(66 - count(consumed)) + " of the drinks the spirit medium can produce.", "blue");
  }
}
 

mstieler

Member
Sweet. Both of those work nicely. Now to apply this towards actually going and farming up some of those drinks I still need.
 

mstieler

Member
Ooh! New tweak, and hey I figured it myself. Change (in Bale's script)

Code:
      print( "Have NOT consumed " + s + ", of which you have " + to_string(ni) + " in your inventory.", (ni==0? "red" : "green"));
to
Code:
      print( "Have NOT consumed " + s + ", of which you have " + to_string(ni) + " in your inventory." + " Current Mall price " + mall_price( it ), (ni==0? "red" : "green"));

This will give you the Mall price of unconsumed drinks, in case you're wondering.

So it will give, if for instance you haven't consumed a Punchplanter, the following:

Have NOT consumed Punchplanter, of which you have 0 in your inventory. Current Mall price 70000
 

ereinion

Member
If you do this instead, it will be kinder to the servers, and might take a bit less time to run:
PHP:
print( "Have NOT consumed " + s + ", of which you have " + to_string(ni) + " in your inventory." + " Current Mall price " + (historical_age(it)>1.0? mall_price( it ) : historical_price(it)), (ni==0? "red" : "green"));
Nice tweak though, I had no idea the booze was that expensive!
 
Last edited:

charred

Member
And here's my modification to separate out the list of drinks I've already consumed so that I can enjoy the number going up.

PHP:
#
#    Happy Medium Drink Checker
#
#    V 0.01        4/25/2012    by Ethelred. Modified by ereinion and Bale
#    

void main() {
  int ni; item it; string s;
  boolean [item] consumed;
  string consumables = visit_url("showconsumption.php");
    
  for i from 5573 to 5638 {
    it = to_item( i );
    s = to_string( it );
    ni = item_amount( it );
    if( !contains_text(consumables, s ))
      print( "Have NOT consumed " + s + ", of which you have " + to_string(ni) + " in your inventory.", (ni==0? "red" : "green"));
    else consumed [it] = true;
  }
  if (count(consumed) == 66) {
    print( "You have drunk all the drinks the spirit medium can produce!", "blue");
  } else {
    print(" ");
    foreach it in consumed
      print("Already drunk: "+it, "green");
    print("You have yet to drink " + to_string(66 - count(consumed)) + " of the drinks the spirit medium can produce.", "blue");
  }
}

does the script see difference like firewater, earth and firewater, and earth wind, and firewater?
i bought 1 of everything to start and now the script says im done, but i still have 1 Aye Aye, 1 Firewater, and 1 Slimosa in inventory and no trophy. and if i go to my consumption, they are not listed
 

lostcalpolydude

Developer
Staff member
It's checking for the item's name anywhere on the page, and finds it in the names of other items. Change
PHP:
if( !contains_text(consumables, s ))
to
PHP:
if( !contains_text(consumables, ">" + s + "<" ))
and it should work.
 

Bale

Minion
My current version sorts drinks by current mall price.

Code:
#
#		Happy Medium Drink Checker
#
#		V 0.01				4/25/2012		by Ethelred. Modified by ereinion and Bale
#		

void main() {
	item it;
	boolean [item] consumed;
	item [int] missing;
	boolean [item] possess;
	string consumables = visit_url("showconsumption.php");
		
	for i from 5573 to 5638 {
		it = to_item( i );
		if( !contains_text(consumables, ">" + to_string( it ) + "<" )) {
			if(item_amount( it ) > 0)
				possess [it] = true;
			else
				missing [count(missing)] = it;
		} else consumed [it] = true;
	}
	if (count(consumed) == 66) {
		print( "You have drunk all the drinks the spirit medium can produce!", "blue");
	} else {
		foreach i in consumed
			print("Already drunk: "+i, "green");
		foreach i in possess
			print( "Have NOT consumed " + i + ", of which you have " + item_amount( i ) + " in your inventory.", "#FBB117");
		sort missing by mall_price(value);
		foreach n,i in missing
			print( "Have NOT consumed " + i + ", which you can purchase for "+ mall_price(i) +" meat.", "red");
		print(" ");
		print("You have yet to drink " + to_string(66 - count(consumed)) + " of the drinks the spirit medium can produce.", "blue");
	}
}
 

mstieler

Member
Okay, final tweak to ask for since I can't seem to get it to work:

Sort the consumed drinks by mall price as well. I've been able to add "currently selling for X meat" to it, but I tried adding
Code:
		sort consumed by mall_price(value);
above
Code:
		foreach i in consumed
like this portion of the script
Code:
		sort missing by mall_price(value);
		foreach n,i in missing
but I keep getting an error message:
Function 'mall_price( boolean )' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts. (Happy Medium Trophy.ash, line 26)

I'm confused, since it appears to be the same portion it's checking for the same thing; I did try changing
Code:
		foreach i in consumed
to
Code:
		foreach n,i in consumed
like the "missing" portion but it still didn't work.
 

Bale

Minion
Code:
boolean [item] consumed;
item [int] missing;

Notice the difference? I recommend that you only sort maps which are indexed by int because otherwise you're likely to get results that you dislike.

The former map only has simple boolean values and is indexed by the item because all I wanted was a simple list of items sorted alphabetically. The map of items would automatically be sorted alphabetically so it was a complete win. Boolean datatypes are the simplest so I used that and always set it to true since its value was unimportant to me.

The second map has a list of items which are indexed by integers from 0 on. I use sort to change the association of integers to items. The map is still sorted from 0 upwards after the sort. That does not change, but each integer is associated with a different item. You see why I recommend only sorting integer indexed maps?

To do what you desire I suggest that you change the datatype of consumed and all relevant assignments accordingly. (Check the handling of missing to see how it should be done.)
 
Last edited:
Just whipped this up real quick because I wanted a nice visual way to see what I needed. Thought I'd put it here in case others are looking for similar. It has room for improvement, and I already have a bunch more I want to add, but for now it's a pretty low-profile checklist. Drop it in relay and open it up in the browser.
 

Attachments

  • relay_Spirits.ash
    1.7 KB · Views: 75

Bale

Minion
That's nice. With a little more work that could be awesome! (I particularly would like un-tasted drinks to have mall price listed on a buy&drink button.)

Small bug: You need to add target='_blank' to links so that they open in a new tab.
 
Last edited:
Top