(Help Req.) Script that consumes Food and Booze to max stat gain based on class

pastafresco

New member
A while ago i tried making a script that would consume maximum food and booze based on stats. My goal was to prioritize stat boosting foods/booze based on (1) Class stat (muscle for seal clubbers, etc.) (2) Moxie if not moxie class, Muscle if moxie class (3) Mysticality (unless Myst. class)... The goal is to raise the main stat up to 100 or so, then raise the other two stats up to 70. Once main is at 100 and others are at 70, then the script would return to boosting the main stat.

I'm not sure how well my script works, plus it's very inefficient scripting (i'm no programmer) so i figure that a more efficient script would both be better for the servers and be very useful for other KoLMafia users.

( I think the Request board was a reasonable place to post, but I think this board is better. I modified the subject slightly. If folks disagree, come discuss about the setup of the forum! I want to please as many as reasonably possible... -Daychilde ;D )
 

Attachments

  • Consumption.ash
    18.4 KB · Views: 85

Tirian

Member
Re: (Help Req.) Script that consumes Food and Booze to max stat gain based on cl

Well, I say that you are a programmer, since you have written a program! It's a program that's really long and nearly impossible to maintain, but it's a very solid start.

The sorts of things that I would do to start bringing the script under control is to see the places where you're doing the same thing more than twice and moving that functionality into another function. For instance, I might start with a few functions like this (this code is untested, btw, and the implementation of one of the functions is left as an exercise):

Code:
stat MyPrimaryStat()
{
  if( my_class() == $class[turtle tamer] || my_class() == $class[seal clubber])
   return $stat[muscle];
 if( my_class() == $class[accordion thief] || my_class() == $class[disco bandit])
   return $stat[moxie];
 return $stat[mysticality];
}

item Booze_4D (stat foo)
{
 if (foo==$stat[muscle]) return $item[fuzzbump];
 if (foo==$stat[moxie]) return $item[perpendicular hula];
 return $item[horizontal tango];
}

void drink_4D_to_bump(stat foo)
{
  item drink;
  drink = Booze_4D(foo);
  if (item_amount(drink) == 0)
  {
   drink = Booze_4D_other(foo);
   if (item_amount(drink) == 0)
   {
     buy(1, drink);
   }
  }
  use(1, drink);
}

This is a function that is in twelve separate places in your code, and writing one general function will shrink your code by a few pages and eliminate the fear that you mistyped something in one of the places. Plus it's easier to enhance if you ever want to make it a little more powerful.

You can do this sort of thing all through your script replacing your class-specific code with helper functions and class-blind functionality.
 
A snipet of code from the script:
Code:
//Make sure I have a bartender

void check_bartender( int meat)
{
 if( have_bartender() == false)
 {
  if( item_amount( $item[bartender-in-the-box]) < 1)
  {
   if( my_meat() < 8000)
   {
   meat = 8000 - my_meat();
   get_meat( meat);
   }
   if (can_interact()==true)
   {
    if( item_amount( $item[box]) < 1)
     buy( 1, $item[box]);
    if( item_amount( $item[spring]) < 1)
     buy( 1, $item[spring]);
    if( item_amount( $item[beer lens]) < 1)
     buy( 1, $item[beer lens]);
    if( item_amount( $item[smart skull]) < 1)
     buy( 1, $item[smart skull]);
    if( item_amount( $item[disembodied brain]) < 1)
     buy( 1, $item[disembodied brain]);
    if( item_amount( $item[E-Z Cook Oven™]) < 1)
     buy( 1, $item[E-Z Cook Oven™]);
   }
   create( 1, $item[bartender-in-the-box]);
  }
  use( 1, $item[bartender-in-the-box]);
 }
}
//End bartender check

This code will fail if you do not have 2 beer lenses. If you have 0, it will buy 1, and try to make a bartender, but wont be able to.

An alternate way:

Code:
if(item_amount($item[beer goggles]) < 1)
  {
  if(item_amount($item[beer lens]) < 2)
    buy((2 - item_amount($item[beer lens])), $item[beer lens]);
  }
Wont buy anything if you already have Beer Goggles,
Will only buy 1 if only 1 is needed, or 2 if you don't have any.
You could go even further on component testing like check for a bartender skull before checking for beer goggles.

Below is my method of drinking when I have a TPS which is to soon be revised to contain code to make a bartender instead of buying 1.

Code:
void CheckBartender()
  {
  if(have_bartender() == false)
    {
    if(item_amount($item[bartender-in-the-box]) < 1)
      buy(1, $item[bartender-in-the-box]);
    use(1, $item[bartender-in-the-box]);
    }
  }

int MyMaxInebriety()
  {
  int MaxDrunkness;
  MaxDrunkness = 0;
  if(can_drink() == true) 
    {
    MaxDrunkness = 14;
    if(have_skill($skill[liver of steel])) MaxDrunkness = 19;
    }
  return MaxDrunkness;
  }
//end MyMaxInebriety

//Credit Due to cjswimmer for the function "stat LookUpPrimaryStat"
//Originally Named "stat Lookup_PrimaryStat()" and taken from
//SoftcoreAscensionScript.ASH
//Reason For NameChange is format of the function.
//UnderScores are used between words in KOLMafia's built
//in Functions. Functions I put into Scripts do not Have Underscores.
//This helps in the debugging process.
stat LookupPrimaryStat()
  {	
  stat Results;
  if(my_class() == $class[turtle tamer] || my_class() == $class[seal clubber]) Results = $stat[muscle]; 
  if(my_class() == $class[pastamancer] || my_class() == $class[sauceror]) Results = $stat[mysticality]; 
  if(my_class() == $class[Disco Bandit] || my_class() == $class[accordion thief]) Results = $stat[moxie];
  return Results;
  }
//end LookupPrimaryStat

//you must know the recipe for the item.
void TPSDrinkIt(item fruit, item bottle, item base, item final)
  {
  while(my_inebriety() < (MyMaxInebriety() -6))
    {
    if(my_inebriety() > (MyMaxInebriety() -6)) 
      break;
    CheckBartender();
    if(item_amount(fruit) < 2)
      buy((2 - item_amount(fruit)), fruit);
    if(item_amount(bottle) < 1)
      buy(1, bottle);
    if (fruit == $item[lime])
      create(1, $item[skewered lime]);
    if (fruit == $item[cherry])
      create(1, $item[skewered cherry]);    
    if (fruit == $item[jumbo olive])
      create(1, $item[skewered jumbo olive]);
    CheckBartender();
    create(1, base);
    CheckBartender();
    create(1, final);
    use(1, final);
    }
  }

void DrinkViaTPS()
  {
  if(LookupPrimaryStat() == $stat[muscle])
    TPSDrinkIt($item[lime], $item[bottle of rum], $item[grog], $item[grogtini]);
  if(LookupPrimaryStat() == $stat[mysticality])
    TPSDrinkIt($item[cherry], $item[boxed wine], $item[sangria], $item[sangria del diablo]);
  if(LookupPrimaryStat() == $stat[moxie])
    TPSDrinkIt($item[Jumbo Olive], $item[bottle of gin], $item[dry martini], $item[dirty martini]);
  }
//end DrinkViaTPS

It's much shorter, but also doesn't do exactly what you want. It only drinks Primary Stat drinks. A Mild edit to the function void DrinkViaTPS() could easily make it do what you are wanting. DrinkViaTPS() is the function to call to drink to 12 drunkeness (18 with liver of steel).

I step through the entire creation process for making TPS drinks rather than to rely on kolmafia to do it for me. It's a control thing having to do with bartender explosion.

The script above is by no means a complete script, it is less than 1/10 of the script I am starting to use but still working on. I will be uploading the complete script in a new subject later. Later meaning in a few weeks.
 
[quote author=efilnikufecin link=topic=33.msg156#msg156 date=1144129850]An alternate way:

Code:
if(item_amount($item[beer goggles]) < 2)
 {
 if(item_amount($item[beer lens]) < 2)
  buy((2 - item_amount($item[beer lens])), $item[beer lens]);
 }
Wont buy anything if you already have Beer Goggles,
Will only buy 1 if only 1 is needed, or 2 if you don't have any.
You could go even further on component testing like check for a bartender skull before checking for beer goggles.[/quote]

There is a typo here:

Code:
if(item_amount($item[beer goggles]) < 2)

Should be:

Code:
if(item_amount($item[beer goggles]) < 1)
 
[quote author=Presto Ragu link=topic=33.msg157#msg157 date=1144130703]
There is a typo here:

Code:
if(item_amount($item[beer goggles]) < 2)

Should be:

Code:
if(item_amount($item[beer goggles]) < 1)
[/quote]

Smacks self having just pointed out a similar error in that post :p
 

pastafresco

New member
Re: (Help Req.) Script that consumes Food and Booze to max stat gain based on cl

to be honest, i'm probably not going to get around to working any more on this script til summer, but thanks for the edits anyways. They'll be helpful when I get around to working it again.
 
Top