Script help

This is a pair of scripts for stasising the basement for mimic farming, due to the creatures there having a 50 round limit. The first script attempts to get to check for all the appropriate consumables, then use them, then check for all needed potions, then use them. I'm using specified items in lieu of something like eatdrink because I'm on the vesper consumption leaderboards, and the remainder of the optimal diet is unlikely to change. For the adventuring script, I want it to fling turns at Fernswarthy's grandfather 100 times to charge my stinky cheese, then fling the rest of my turns without the cheese equipped. Then nightcap and put on rollover gear.

How could I get it so it chooses the correct chocolate class instrument for anyone?

I tried to make it so that it would calculate how many buff potions of each type I would need based on how many turns I have (adding an additional 5 to account for a time's arrow), but I almost certainly did it incorrectly. I also need to factor in any existing turns of the buff somehow.

How can I get it to automatically replace a bartender if mine explodes in the midst of its duties?

I'll be running and getting a free runaway 20% of the time. How can I either fix it so I use 100 combats, as opposed to 100 turns, or make it so it automatically unequips the stinky cheese item as soon as it's completely charged?

As you can tell, I didn't put much effort into the second script, because I'm almost certain I would have gotten everything pretty much 100% wrong, due to the basement potentially needing different commands, and my inability to figure out how to set something that's not an item as a goal.

Do I need to specifiy that I want the script to use a CCS, or will it default to what I have selected in the custom combat tab?

Code:
	{
	if (have_item($items[fishy fish lasagna]) < 4)
		print ("Plenty of lasagna")
	else
		{
		print ("You need lasagna")
		abort
		{
		{
	if (have_item($items[milk of magnesium]) < 0)
		print ("Plenty of milk")
	else
		{
		print ("You need milk")
		abort
		{
		{
	if (have_item($items[potion of the field gar]) < 0)
		print ("Plenty of Field Gar potions")
	else
		{
		print ("You need Field Gar potions")
		abort
		{
	if(have_effect($effect[Ode to Booze]) < 19)
		cast 2 ode to booze	
	if(have_effect($effect[Ode to Booze]) < 18)
	   	print ("Plenty of ode")
	else
		{
		print ("You need ode")
		abort
		{
	if (have_item($items[mojo filter]) < 0)
		print ("Plenty of mojo filters")
	else
		{
		print ("You need a mojo filter")
		abort
		{
	if (have_item($items[coffee pixie stick]) < 3)
		print ("Plenty of piie sticks")
	else
		{
		print ("You need pixie sticks")
		abort
		{
	if (have_item($items[go-wassail]) < 0)
		print ("Plenty of wassail")
	else
		{
		print ("You need wassail")
		abort
		{
	if (have_item($items[tiny plastic sword]) < 0)
		print ("TPS present")
	else
		{
		print ("Where's the TPS?")
		abort
		{
	if (have_item($items[jumbo olive]) < 3)
		print ("Jumbo olives present")
	else
		{
		print ("Need more jumbo olives")
		abort
		{
	if (have_item($items[dry vodka martini]) < 3)
		print ("Dry vodka martini present")
	else
		{
		print ("Need more dry vodka martinis")
		abort
		{
	if (have_item($items[chocolate stolen accordion]) < 3)
		print ("Chocolate present")
	else
		{
		print ("Need chocolate")
		abort
		{
	

	use potion of the field gar
	use milk of magnesium
	use chocolate stolen accordion
	eat 5 fishy fish lasagna
	use 3 coffee pixie stick
	use mojo filter
	use coffee pixie stick
	drink go-wassail
	mix vesper
	drink vesper
	mix vesper
	drink vesper
	mix vesper
	drink vesper
	mix vesper
	
	int choraleShotsNeeded [(my_adventures()+5)/20]
	int petSprayNeeded [(my_adventures()+5)/10]
	int punctualPotionsNeeded [(my_adventures()+5)/30]
	
	if (have_item($items[recording of Chorale of Companionship]) < choraleShotsNeeded)
		print ("Chorale present")
	else
		{
		print ("Need chorale")
		abort
		{
		
	if (have_item($items[potion of punctual companionship]) < punctualPotionsNeeded)
		print ("Punctual potions present")
	else
		{
		print ("Need punctual potions")
		abort
		{
		
	if (have_item($items[Travoltan trousers]) < 0)
		print ("Travoltans present")
	else
		{
		print ("Need Travoltans")
		abort
		{
		
	equip ( [pants], Travoltan trousers )
	buy petSprayNeeded knob goblin pet-buffing spray
	use petSprayNeeded knob goblin pet-buffing spray
	use punctualPotionsNeeded potion of punctual companionship
	use choraleShotsNeeded recording of Chorale of Companionship

Code:
outfit (stasis1)
use_familiar (stocking mimic)
fold loathing legion helicopter
equip( [familiar], loathing legion helicopter )
Print ("Adventuring with stinky cheese")
Fling self and Fernswarthy's grandfather using a CCS until cheese is fully charged, buffs run out, or there's a probem (beaten up, out of MP mid combat)
outfit (stasis2)
Print ("Stinky cheese charged, finishing turns")
Fling self and Fernswarthy's grandfather using a CCS until no turns remain, buffs run out, or there's a probem (beaten up, out of MP mid combat)
use_familiar (disembodied hand)
fold loathing legion moondial
maximize (adv)
cast ode
if(have_effect($effect[Ode to Booze]) > 5)
drink vesper
else
{
print ("Problem casting ode)
abort
}
Print ("Mission accomplished.  Now get back to work.")

I tried, I really did. It's not too ugly is it?
 

Theraze

Active member
How could I get it so it chooses the correct chocolate class instrument for anyone?
This is from EatDrink, believe it came from Bale originally:
Code:
class [item] class_choco;
    class_choco [$item[chocolate seal-clubbing club]] = $class[Seal Clubber];
    class_choco [$item[chocolate turtle totem]] = $class[Turtle Tamer];
    class_choco [$item[chocolate pasta spoon]] = $class[Pastamancer];
    class_choco [$item[chocolate saucepan]] = $class[Sauceror];
    class_choco [$item[chocolate disco ball]] = $class[Disco Bandit];
    class_choco [$item[chocolate stolen accordion]] = $class[Accordion Thief];
Then you can just check if the item is the right class. Alternatively, you could swap it from class [item] to item [class] and that should allow checking based on class directly.

I tried to make it so that it would calculate how many buff potions of each type I would need based on how many turns I have (adding an additional 5 to account for a time's arrow), but I almost certainly did it incorrectly. I also need to factor in any existing turns of the buff somehow.
Code:
	int choraleShotsNeeded =ceil(to_float(my_adventures()+5)/20);
	int petSprayNeeded = ceil(to_float(my_adventures()+5)/10);
	int punctualPotionsNeeded = ceil(to_float(my_adventures()+5)/30);
Basically, we set our int (with =) to round up (ceil) a float (to_float) so that we get a proper, accurate number. :)

How can I get it to automatically replace a bartender if mine explodes in the midst of its duties?
Just use the rebuild bartender preference. Nothing special script-wise for that.

I'll be running and getting a free runaway 20% of the time. How can I either fix it so I use 100 combats, as opposed to 100 turns, or make it so it automatically unequips the stinky cheese item as soon as it's completely charged?
I'd suggest doing something like:
Code:
for combats from 1 to 100 {
adv1($location[fern basement], 1, "");
}
 

Paragon

Member

You say you are mimic farming the basment due to 50 turn limit rather then 30... I would just like to point out that the mimic stops giving meat after the tenth round... unless you are attempting to heal yourself it doesn't matter how many rounds the fight has beyond 10.
 

Bale

Minion
Deathless Assassin, I'm not sure why none of the previous respondents failed to mention the single most glaring error with both your scripts. You cannot freely mix CLI and ASH commands. They are two separate languages and cannot be mixed without concern. You need to decide if you are writing an ASH script (in which case it will have the extension .ash) or a CLI script (in which case it will have the extension .txt). After that there are ways of adding the other language into your script if you need to do so.

In an ASH script you can add CLI by using cli_execute("use potion of the field gar"); although that is simply the same thing as the ASH command, use(1, $item[potion of the field gar]);

Or in a CLI script you can run an ash command by prefacing it with ash, such as ash if (item_amount($items[mojo filter]) > 0) print("Plenty of mojo filters"); else abort("You need a mojo filter");

I recommend using ASH if you are going to use if statements since it is much more flexible than anything in CLI and is kinda hard to read when you compress them into a single line of CLI.

Hint: In ash, the abort command looks like this: abort("Reason for aborting"). If you leave off the stuff in parenthesis you are trying to use the CLI abort command.

Hint2: Commands in ash need to end in semi-colons. Note the semi-colons I used in the previous examples. They are important.

Hint3: I'm not sure what was up with lines like if (have_item($items[mojo filter]) < 0) but have_item is not an ASH command. (And I don't know why less than 0 would be a good thing!) The correct command (as shown in a previous example) is to check item_amount() to find out how many of an item you actually have and compare that to the amount you want. Actually, mafia can even purchase the items if you are lacking . I'd rewrite that section like this:

Code:
if(retrieve_item(1, $items[mojo filter]))
   use(1, $items[mojo filter]);
else abort("You need a mojo filter");

The above example uses retrieve_item() to ensure that you have at least 1 mojo filter. It is equivalent to the CLI command "acquire". It returns true if you already have 1 or it manages to purchase the missing mojo filters. The example then uses the filter if you can acquire it (so you don't need another line to use it later) or aborts if it cannot. Note that retrieve_item() will fail to purchase the mojo filter if it it's price is higher than mafia's autoBuyPriceLimit which has a default value of 20,000 meat. You probably wouldn't want to purchase a mojo filter at that price anyway, but it can be a problem if you want to purchase cyclops eyedrops. Working around that value requires the buy() command.
 
Last edited:

lostcalpolydude

Developer
Staff member
I suggest using a mood or betweenBattleScript to check _stinkyCheeseCount using to_int( get_property( "_stinkyCheeseCount" ) ). If it's >= 100 and you're wearing any, switch to other gear. Then it will work the way you want even if you do something else first.
 
The 50 round limit generates more MP for burning. I'm also avoiding using the script for purchasing, I usually prefer to make things myself, and I have clannies with cannon fodder turns for wok access, etc. I'm a hoarder by nature, so it's unlikely the abort messages will ever pop up due to lack of items.

Otherwise, I think I managed to make the script less embarrassing. I know I didn't fix everything, but I'm probably at a good waypoint to post my progress:

Code:
class [item] class_choco;
    class_choco [$item[chocolate seal-clubbing club]] = $class[Seal Clubber];
    class_choco [$item[chocolate turtle totem]] = $class[Turtle Tamer];
    class_choco [$item[chocolate pasta spoon]] = $class[Pastamancer];
    class_choco [$item[chocolate saucepan]] = $class[Sauceror];
    class_choco [$item[chocolate disco ball]] = $class[Disco Bandit];
    class_choco [$item[chocolate stolen accordion]] = $class[Accordion Thief];
	{
	
	if (item_amount($items[fishy fish lasagna]) > 4)
		print ("Plenty of lasagna");
	else
		abort ("You need lasagna");
		
	if (item_amount($items[milk of magnesium]) > 0)
		print ("Plenty of milk");
	else
		abort ("You need milk");

	if (item_amount($items[potion of the field gar]) > 0)
		print ("Plenty of Field Gar potions");
	else
		abort ("You need Field Gar potions");
		
	if(have_effect($effect[Ode to Booze]) < 19)
		cast 2 ode to booze;
	if(have_effect($effect[Ode to Booze]) > 18)
	   	print ("Plenty of ode");
	else
		abort ("You need ode");
		
	if (item_amount($items[mojo filter]) > 0)
		print ("Plenty of mojo filters");
	else
		abort ("You need a mojo filter");
		
	if (item_amount($items[coffee pixie stick]) > 3)
		print ("Plenty of piie sticks");
	else
		abort ("You need pixie sticks");
		
	if (item_amount($items[go-wassail]) > 0)
		print ("Plenty of wassail");
	else
		abort ("You need wassail");
		
	if (item_amount($items[tiny plastic sword]) > 0)
		print ("TPS present");
	else
		abort ("Where's the TPS?");
		
	if (item_amount($items[jumbo olive]) > 3)
		print ("Jumbo olives present");
	else
		abort ("Need more jumbo olives");
		
	if (item_amount($items[dry vodka martini]) > 3)
		print ("Dry vodka martini present");
	else
		abort ("Need more dry vodka martinis");
		
	if (item_amount($items[class_choco]) > 0)
		print ("Chocolate present");
	else
		abort ("Need chocolate");

	use(1, $item[potion of the field gar]);
	use(1, $item[milk of magnesium]);
	use(1, $item[class_choco]);
	eat(5, $item[fishy fish lasagna]);
	use(3, $item[coffee pixie stick]);
	use(1, $item[mojo filter]);
	use(1, $item[coffee pixie stick]);
	drink(1, $item[go-wassail]);
	mix(1, $item[vesper]);
	drink(1, $item[vesper]);
	mix(1, $item[vesper]);
	drink(1, $item[vesper]);
	mix(1, $item[vesper]);
	drink(1, $item[vesper]);
	mix(1, $item[vesper]);
	drink(1, $item[vesper]);
	mix(1, $item[vesper]);
	
	int currentChorale = have_effect($effect[chorale of companionship])
	int currentPunctual = have_effect($effect[Stickler for Promptness])
	int currentPetting = have_effect($effect[heavy petting])
	
	int choraleShotsNeeded =ceil(to_float(my_adventures()+5-currentChorale)/20);
	int petSprayNeeded = ceil(to_float(my_adventures()+5-currentPetting)/10);
	int punctualPotionsNeeded = ceil(to_float(my_adventures()+5-currentPunctual)/30);
	
	if (item_amount($items[recording of Chorale of Companionship]) > choraleShotsNeeded)
		print ("Chorale present");
	else
		abort ("Need chorale");
		
	if (item_amount($items[potion of punctual companionship]) > punctualPotionsNeeded)
		print ("Punctual potions present");
	else
		abort ("Need punctual potions");
		
	if (item_amount($items[Travoltan trousers]) > 0)
		print ("Travoltans present");
	else
		abort ("Need Travoltans");
		
	equip ( [pants], Travoltan trousers );
	buy(petSprayNeeded, $item[knob goblin pet-buffing spray]);
	use(petSprayNeeded, $item[knob goblin pet-buffing spray]);
	use(punctualPotionsNeeded, $item[potion of punctual companionship]);
	use(choraleShotsNeeded, $item[recording of Chorale of Companionship]);
	}

Code:
int cheesiness = ( get_property( "_stinkyCheeseCount" ) )

{
outfit (stasis1);
use_familiar (stocking mimic);
fold loathing legion helicopter;
equip( [familiar], loathing legion helicopter );
while cheesiness < 100
	adv1($location[fern basement], 1, "Adventuring with stinky cheese");

adventure( int, $location[fern basement], "Stinky cheese charged, finishing turns" );

use_familiar (disembodied hand);
fold loathing legion moondial;
maximize (adv);
cast ode;

if(have_effect($effect[Ode to Booze]) > 5)
	drink(1, $item[vesper]);
else
	abort ("Problem casting ode);

Print ("Mission accomplished.  Now get back to work.");
}

Does my attempt at a while loop to charge stinky cheese work? Will automation automatically stop if I get beaten up, run out of MP, or some other problem? What's the ash command for folding the legion knife? I couldn't find it on the wiki. I tried to factor in existing turns of an effect when calculating how many potions I'll need, did I get that right? I'll feel awesome if I did.
 

Theraze

Active member
With chocolates, I'd suggest this:
Code:
item [class] class_choco;
    class_choco [$class[Seal Clubber]] = $item[chocolate seal-clubbing club];
    class_choco [$class[Turtle Tamer]] = $item[chocolate turtle totem];
    class_choco [$class[Pastamancer]] = $item[chocolate pasta spoon];
    class_choco [$class[Sauceror]] = $item[chocolate saucepan];
    class_choco [$class[Disco Bandit]] = $item[chocolate disco ball];
    class_choco [$class[Accordion Thief]] = $item[chocolate stolen accordion];
Switched to be sorted by class, as I suggested. Then...
Code:
if (class_choco[my_class()] != $item[none]) use(1, class_choco[my_class]);
 

Catch-22

Active member
What's the ash command for folding the legion knife? I couldn't find it on the wiki.

Sometimes I find it easier to look no further than ashref/help in KoLmafia. The "help" command in the CLI will give you help for CLI commands, whereas "ashref" will give you commands for use in ASH.

The neat thing is, you can also search for help based on a specific keyword, like so:

Code:
> ashref fold

> help fold

fold[?] item - produce item by using another form, repeated as needed.
heapdump - creates a heap snapshot which is used to help debug memory problems (requires use of the JDK instead of the JRE, requires Java 1.6+). Heap snapshot files are separate from debug logs but will be placed in the same folder. Please note that heap dumps are a KoLmafia memory snapshot so they may contain your KoL passwords. As such, please be mindful of how you share these files.
jmap - creates a heap snapshot which is used to help debug memory problems (requires use of the JDK instead of the JRE, requires Java 1.6+). Heap snapshot files are separate from debug logs but will be placed in the same folder. Please note that heap dumps are a KoLmafia memory snapshot so they may contain your KoL passwords. As such, please be mindful of how you share these files.

As you can see, there's no "fold" mentioned anywhere in the ashref (sadface), but hey, there's a "fold" command in CLI, and it seems to be what you're after :) You've already been made aware of the cli_execute() ASH function, so the ASH version would be cli_execute("fold legion loathing helicopter") etc.
 

Bale

Minion
Does my attempt at a while loop to charge stinky cheese work? Will automation automatically stop if I get beaten up, run out of MP, or some other problem?

Sorry, definitely not working for the following reasons.
  • get_property( "_stinkyCheeseCount" ) returns a string, not an int. You'll need to use to_int() to convert it.
  • cheesiness will not be automatically updated. It is set only when you tell it to be set at the beginning, and then it is never changed unless you add a command to change it. It is better to never use the variable at all.
  • I see that you're using a combat filter for adv1. That's a complicated thing to do. Judging by your level of scripting knowledge I'm fairly sure you don't understand what that means. It is not the name of a CCS.
  • If you want to change a CCS do it with set_property("customCombatScript", "Adventuring with stinky cheese");
  • Your formatting of a while statement is just wrong.
I'd recommend doing it like this: (Assuming I properly interpreted your intent to change your Custom Combat Script... If I'm wrong, please correct me and we can figure out how it should be done.)

Code:
set_property("customCombatScript", "Adventuring with stinky cheese");
while( to_int(get_property( "_stinkyCheeseCount")) < 100 )
	adventure(1, $location[Fernswarthy's Basement]);

set_property("customCombatScript", "Stinky cheese charged, finishing turns");
adventure( my_turncount(), $location[Fernswarthy's Basement]);



What's the ash command for folding the legion knife? I couldn't find it on the wiki.

There is no ash command for folding the legion knife. It should be done like this:

Code:
if(item_amount($item[loathing legion helicopter]) < 1)
   cli_execute("fold loathing legion helicopter");

Edit: Catch-22 ninja'ed me about folding while I was writing this essay! Though I like to have an item_amount() check before folding, just in case I already have the item.

I tried to factor in existing turns of an effect when calculating how many potions I'll need, did I get that right? I'll feel awesome if I did.

You should feel awesome! Congratulations.
 
Last edited:
Top