KoLmafia Guide: Logout script

From KoLMafia
Jump to: navigation, search

We are putting a lot of stuff we learned together for this next one. It is a script you would run right before logging out for the day. It automatically does all the stuff that you probably want to do before logging out. We will learn a few new things here, but you know most of it already.

a) We've seen the buffBot and Wait code already. In this case, we want to have Ode to Booze readied BEFORE we drink our nightcap!

b) For a moxie player with Superhuman Cocktailcrafting, you can improve components. You always wanna use all 10 usages per day. Note the stills_available() function. I then buy some basic booze if needed, then use create() to make the appropriate upgrade to that booze. You can change this to whatever booze/fruit improvement you wish.

c) You can see my lame PvP script. A better alternative is probably to say, "IF i have any attacks remaining, Print a warning to the user and then Abort". I figure that if I am ready to log out, I don't want to mess with PvP.

d) So I actually cobbled enough meat (thanks to Crimbo) to buy a Libram! I want to be sure to use up any remaining mana to use the Libram...especially if I have forgotten to use it at all that day!

I use a new loop, the While loop. As long as my MP is enough to cast the Love Song, then I cast it.

Bonus) A smart thing to do here is to include usage of any 'per day' MP restores. I don't actually HAVE any at the moment, but Nunnery MP regen, VIP clan key, and whatever other stuff that hasn't been used up already could be used. You would do so by adding another while loop most likely that says, "While you still have a way to restore your mana for free, do so, then Do the Libram summon loop".

f) Note how you change outfits. This requires you to have previously saved a specific custom outfit called 'TimeGainer', by equipping items that give more PvP or Adventures per day. Changing outfits is super helpful and you can use this command to great effect. Obviously, name it whatever you'd like.

g) Note my comment below the change outfits. You can simply 'maximize adv' to make Mafia auto-outfit with you to max out adventure gains. I'd save off a specific outfit instead though as I combine both PvP and adventures. But the Maximize call can be pretty handy... lets say you are making a Hobopolis script. Being able to Maximize a particular resistance can be really handy.

h) At the very end, I overdrink my nightcap cocktail. I ASSUME I am at right under maximum drunkenness. Therefore I don't do any checks. Also note that a DRINK command probably won't work. Mafia will prevent you from overdrinking unless you specifically override that preference with the Overdrink command. Note that I overdrink at the END of the script, since you are basically done once you are drunk.

i) You can always add whatever else you want for a logout script like this. Make reminders to use up your 1/day stuff, and abort the script if you have not. Maybe you want to summon a demon every day and either want to do it automatically or warn you if you have not done so. KoLmafia breakfast can handle most of this stuff for you though.

j) Finally, if you wanted you could go back to the Breakfast tab and include this as your new 'logout script'. When you log out of KoLmafia, it will first run this script before quitting. I prefer to run it manually, but you can certainly automate it if desired. (see our Breakfast Lesson above for details)

void main ()
  #### Obtain Ode to Booze for nightcap.
  ## You will want Ode first thing in the morning anyways right?
  ## Modify by sending the right meat amount to your buffBot of choice.
  cli_execute("csend 1 meat to KolaBuff");

  ## Wait for the buff to appear.
  if(have_effect($effect[Ode to Booze]) < 1)
   repeat {wait(5); refresh_status();}
   until (have_effect($effect[Ode to Booze]) > 1);

  #### Improve any spirits at the still.  If you can't do so, it ought to continue on.
  ## How many uses of the still are left?
  int stillsLeft = stills_available();

  ## If we don't have enough, go buy some of the basic booze.
  if ( item_amount( $item[bottle of sake] ) < stillsLeft)
    buy( stillsLeft - item_amount( $item[bottle of sake] ), $item[bottle of sake] );

  ## Now, create the upgraded Spirit:
  create(stillsLeft, $item[bottle of Pete's Sake]);

  #### Did I forget to PvP? If I forgot, I probably just wanna do it the easy way.

  ## Use my libram.
  ## MP cost increases each time, so we have to recalculate in a loop.
  while( my_mp() >= mp_cost($skill[Summon Candy Hearts]) )
	use_skill(1, $skill[Summon Love Song]);

  #### Need to change outfits to equip my +adventures/PvP items.
  ## Note we do this after the Libram thing so we don't lose any MP thru equipping.

  ## NOTE: You could also do a cli_execute("maximize adv"); if you don't have a specific outfit saved.

  #### Get and drink our nightcap.
  if ( item_amount( $item[White canadian] ) == 0)
    buy( 1 , $item[White canadian] );

  ## The overdrink command is used, as otherwise Mafia's overdrink protection would prevent drinking.
  cli_execute("overdrink White canadian");

  #### Todo:  Check your nun usage or other 1/day stuff not covered during breakfast.

Continue to Post-Lesson 5: Creating an Auto-adventuring Script