Chow mein creation script, advice needed please

Bishy

New member
hi, i created a quick script that should, after i farm the kitchen, decide the max chow meins i can create, buy non-kitchen items and create a chow mein for me, however its not creating the correct amount, i know its probably something simple but i'm not really that sure whats happening. any advice would be appreciated
Code:
noodles = item_amount( $item[dry noodles]);
spices = item_amount( $item[spices]);
knobsausage = item_amount( $item[Knob sausage]);

if(noodles >= spices && noodles >= knobsausage) countofitems = noodles;
if(spices > noodles && spices > knobsausage) countofitems = spices;
if(knobsausage > noodles && knobsausage > spices) countofitems = knobsausage;



  if( item_amount( $item[herbs]) < countofitems)
  {
 cli_execute("outfit filthy hippy disguise");
buy((countofitems - item_amount( $item[herbs])), $item[herbs]);

  }
  if( item_amount( $item[knoll mushroom]) < countofitems)
  {
buy((countofitems - item_amount( $item[knoll mushroom])), $item[knoll mushroom]);

  }
  if( item_amount( $item[MSG]) < countofitems)
  {
buy((countofitems - item_amount( $item[MSG])), $item[MSG]);

  }
create(countofitems, $item[Knob sausage chow mein]);

}

im assuming its just a simple error in the if statements here
Code:
if(noodles >= spices && noodles >= knobsausage) countofitems = noodles;
if(spices > noodles && spices > knobsausage) countofitems = spices;
if(knobsausage > noodles && knobsausage > spices) countofitems = knobsausage;
 

Veracity

Developer
Staff member
You are trying to figure out how many to make by deciding which of (spices, noodles, and knob sausage) you have the least of. Well, actually, as coded, you are deciding which you have the MOST of. Sort of. You are not quite doing that, since you use >= in one if and > in the other ones. Look at what happens if noodles = 5, spices = 6, and knobsausage = 6. NONE of the if statements fire and countofitems is 0.

What you want is min( noodles, min( spices, knobsausage)); - except there is no "min" (or "max") function. I'll consider putting one in. :)

To simulate it, since you want the min, not the max, use "<=", rather than ">=" or ">".
 

Bishy

New member
i knew it was something simple, thanks for your help Veracity from what you've said then this shoudl do the job

Code:
if(noodles <= spices && noodles <= knobsausage) countofitems = noodles;
if(spices < noodles && spices < knobsausage) countofitems = spices;
if(knobsausage < noodles && knobsausage < spices) countofitems = knobsausage;

the <= for noodles and the < for the other items should ensure that some value is picked by default if all items have the same number shouldnt it?
 

Veracity

Developer
Staff member
No. Having both <= and < will ensure that there situations where no item gets picked. Consider what happens when you have

noodles = 5
spices = 4
knobsausage = 4

Just stick with <=.
 

Tirian

Member
Assuming you're doing this every day and don't mind a little excess inventory, this might be a cleaner approach:

Code:
void buy_up_to(int quantity, item it)
{
	int deficit = quantity - item_amount(it);
	if (deficit <= 0) return;
	buy (deficit, it);
}

boolean sausage_chow_apalooza()
{
	while (true)
	{
		cli_execute("create * knob sausage chow mein");
		if (item_amount($item[spices]) == 0) return true;
		if (item_amount($item[dry noodles]) == 0) return true;
		if (item_amount($item[knob sausage]) == 0) return true;
		buy_up_to(10, $item[herbs]);
		buy_up_to(10, $item[knoll mushroom]);
		buy_up_to(10, $item[MSG]);
	}
	return false;
}

I'd also mention (probably not to you, but to anyone else reading this) that this is only going to work well if you are auto-repairing your chef. Otherwise, you'll have to factor in a potential inventory of stir fries and secret blends that resulted from partial cooking runs of previous chefs.
 

holatuwol

Developer
Just a few notes:

If you buy herbs, KoLmafia automatically wears the hippy suit, buys the herbs, and switches back to your original outfit.  Also, the acquire CLI command greatly simplifies the second part of your script (in fact, in this case where you've got nothing in storage, nothing in your closet and want nothing from the hermit, it does exactly what tirian's buy_up_to function does).  If you're an ASH purist (do such things exist?), there is an equivalent in the ASH universe: retrieve_item(int,item).

Therefore, you can replace:

Code:
if ( item_amount( $item[herbs]) < countofitems )
{
    cli_execute("outfit filthy hippy disguise");
    buy((countofitems - item_amount( $item[herbs])), $item[herbs]);
}
if ( item_amount( $item[knoll mushroom]) < countofitems )
{
    buy((countofitems - item_amount( $item[knoll mushroom])), $item[knoll mushroom]);
}
if ( item_amount( $item[MSG]) < countofitems )
{
    buy((countofitems - item_amount( $item[MSG])), $item[MSG]);
}
create( countofitems, $item[Knob sausage chow mein] );

with the (potentially simpler)

Code:
retrieve_item( countofitems, $item[herbs] );
retrieve_item( countofitems, $item[knoll mushroom] );
retrieve_item( countofitems, $item[MSG] );
create( countofitems, $item[Knob sausage chow mein] );

If you're daring enough to have the auto-satisfy with mall purchases option enabled, you can simplify this whole process even further and reduce the second half of your script to one line:

Code:
create( countofitems, $item[Knob sausage chow mein] );

KoLmafia will automatically attempt to buy any sub-ingredients needed in order to complete the creation of the specified number of items.
 

Bishy

New member
thanks for all your help guys, my script does everything i need now - it

gets my free buffs from test and N.O,
creates my chow meins,
eats some of them,
buys and drinks pink ponys and a martini,[
casts leash (thanks to itamar)
gets knob goblin buffs,
puts on my item drop outfit and my baby gravy fairy,
adventures in the kitchen,
puts on my rollover outfit,
drinks 1 last drink.

and thats exactly what i want it to do, so thanks again, and here is the full code if anyone wants to look at it and point out ways to improve it :)

Code:
void main ()
{
cli_execute("send 3 meat to testudinata");
cli_execute("send 4 meat to testudinata");
cli_execute("send 5 meat to testudinata");
cli_execute("send 6 meat to testudinata");
cli_execute("send 7 meat to testudinata");
cli_execute("send 8 meat to testudinata");
cli_execute("send 9 meat to testudinata");


cli_execute("send 2 meat to noblesse oblige");
cli_execute("send 3 meat to noblesse oblige");
cli_execute("send 15 meat to noblesse oblige");

int noodles;
int spices;
int knobsausage;
int countofitems;

noodles = item_amount( $item[dry noodles]);
spices = item_amount( $item[spices]);
knobsausage = item_amount( $item[Knob sausage]);

if(noodles <= spices && noodles <= knobsausage) countofitems = noodles;
if(spices <= noodles && spices <= knobsausage) countofitems = spices;
if(knobsausage <= noodles && knobsausage <= spices) countofitems = knobsausage;


create( countofitems, $item[Knob sausage chow mein] );

cli_execute("send 1 meat to testudinata");


  if ( item_amount( $item[Knob sausage chow mein]) < 3)
  {
buy ((3-(item_amount( $item[Knob sausage chow mein]))), $item[Knob sausage chow mein]);
  }
eat(3, $item[Knob sausage chow mein]);

 if ( item_amount( $item[pink pony]) < 4)
  {
buy ((5-(item_amount( $item[pink pony]))), $item[pink pony]);
  }
drink(4, $item[pink pony]);

buy(1, $item[dry vodka martini]);
drink(1, $item[dry vodka martin]);


// taken from Itamars Comperhensive MultiUse Peak Farming tool script
		while(have_effect($effect[leash of linguini])<my_adventures())
		{
			use_skill(my_mp()/12,$skill[leash of linguini]);
			//modify "12" if you have an MP cost reducing item.
			cli_execute("call ManaRestore.ash");
			//I am pretty sure you might get stuck in an infinite loop here.But it is unlikely to happen,
			//unless your max mp is less than 12...
		}
	
cli_execute("outfit knob goblin elite guard uniform");

 if(have_effect($effect[heavy petting])<my_adventures())
  {
  buy(((my_adventures() - have_effect($effect[heavy petting])) / 10) + 1, $item[Knob Goblin pet-buffing spray]);
  use(((my_adventures() - have_effect($effect[heavy petting])) / 10) + 1, $item[Knob Goblin pet-buffing spray]);
}
if(have_effect($effect[Peeled Eyeballs])<my_adventures())
  {
  buy(((my_adventures() - have_effect($effect[Peeled Eyeballs])) / 10) + 1, $item[Knob Goblin eyedrops]);
  use(((my_adventures() - have_effect($effect[Peeled Eyeballs])) / 10) + 1, $item[Knob Goblin eyedrops]);
}

cli_execute("outfit itemdrop");
equip_familiar($familiar[Baby Gravy Fairy]);

adventure(( my_adventures()), $location[Knob Goblin Kitchens]);

cli_execute("send 1 meat to testudinata");
cli_execute("outfit rollover");
drink(1, $item[pink pony]);

}
 

Nightmist

Member
Well personally I would stick the send meat commands at the end of the day because mafia can usually start adventuring before the buffs arrive (Unless you want to create a wait for buffs command but that is a waste of online time when you can request at the end of the day and then just log off)
 
a little heads up for the next version:
Code:
// taken from Itamars Comperhensive MultiUse Peak Farming tool script
		while(have_effect($effect[leash of linguini])<my_adventures())
		{
			use_skill(my_mp()/12,$skill[leash of linguini]);
			//modify "12" if you have an MP cost reducing item.
			cli_execute("call ManaRestore.ash");
			//I am pretty sure you might get stuck in an infinite loop here.But it is unlikely to happen,
			//unless your max mp is less than 12...
		}
should be able to be reduced to simply:
Code:
use_skill(my_adventures,$skill[leash of linguini]);
in which case kolmafia will handle the loop of restoring mp, and casting the buff till you have the correct number of adventures of the buff. This is indicated in the "access to internal data" thread located here: http://kolmafia.us/index.php/topic,250.msg1250.html#msg1250
 

Veracity

Developer
Staff member
[quote author=efilnikufecin link=topic=246.msg1280#msg1280 date=1151762411]
Code:
use_skill(my_adventures,$skill[leash of linguini]);
in which case kolmafia will handle the loop of restoring mp, and casting the buff till you have the correct number of adventures of the buff. This is indicated in the "access to internal data" thread located here: http://kolmafia.us/index.php/topic,250.msg1250.html#msg1250
[/quote]

Wait.

When did use_skill's first argument change from "number of times to cast" to "desired number of turns of effect"?

I was not aware that KoLmafia knew how many turns of effect you get per casting; it can be 5, 10, or 15.

Perhaps you mean:

Code:
use_skill(my_adventures()/10,$skill[leash of linguini]);

or even

Code:
use_skill((my_adventures() + 9)/10,$skill[leash of linguini]);

...since you always get 10 turns of effect for Leash of Linguini per casting.
 

holatuwol

Developer
Veracity said:
I was not aware that KoLmafia knew how many turns of effect you get per casting; it can be 5, 10, or 15.

Or 20 with the new wizard hat, and 40 for the Smile of Mr. A (maybe 45 if the wizard hat affects it). As indicated in the internal data thread, KoLmafia has no idea how many turns of effect you get per cast, and therefore you need to specify number of casts, not number of turns.
 
yes, I said
Code:
use_skill(my_adventures,$skill[leash of linguini]);
but actually meant
Code:
use_skill(my_adventures() / 10,$skill[leash of linguini]);
slip up in 2 ways. first
Code:
my_adventures
returns an error without () on the end. and second forgot the /10.
also if the script is run every day, it should take into account how many adventures of the effect you already have.

[quote author=Veracity link=topic=246.msg1284#msg1284 date=1151783660]
Wait.

When did use_skill's first argument change from "number of times to cast" to "desired number of turns of effect"?
[/quote]

erm it didn't. I screwed up.

[quote author=holatuwol link=topic=246.msg1286#msg1286 date=1151793602]
Or 20 with the new wizard hat, and 40 for the Smile of Mr. A (maybe 45 if the wizard hat affects it). As indicated in the internal data thread, KoLmafia has no idea how many turns of effect you get per cast, and therefore you need to specify number of casts, not number of turns.
[/quote]
uggh more math to do, and equipping of gear if the character has it. Fun!

By the way you no longer recieve the smiles of Mr. Accessory from having smiles cast on you. You always get boxes of sunshine. The effect The smile of Mr. Accessory is only obtainable from the use of a box of sunshine.
 
[quote author=efilnikufecin link=topic=246.msg1291#msg1291 date=1151864856]
By the way you no longer recieve the smiles of Mr. Accessory from having smiles cast on you. You always get boxes of sunshine. The effect The smile of Mr. Accessory is only obtainable from the use of a box of sunshine.
[/quote]

Just to split hairs....

I believe the defining factor is ascension. If I remember correctly, you receive the smile if you have never ascended. Once you ascend, you always receive a box.

Or has that changed?
 

Nightmist

Member
[quote author=Presto Ragu link=topic=246.msg1292#msg1292 date=1151874899]
I believe the defining factor is ascension. If I remember correctly, you receive the smile if you have never ascended. Once you ascend, you always receive a box.
[/quote]

I also think it is post ascension (Although I also have to comment that I always took KoLMafia as a post ascension tool rather then a "Its my first ascension and I want to bot everything and miss out on all the funny content")

Oh and what other item increases buff turns? (Apart from the hat and having a legend?)
 
It's been so long since I messed with a non-ascended character that I am not really sure about it. you may still get the smiles of Mr. A before you have ascended. Even so, it doesn't make sense to say this person who has ascended gets less from a gma smile than another who hasn't.
 
I agree that mafia should not be intended for the first time player.

But at the same time it is viable that an experienced player would be starting a brand new character, and should be able to use mafia functionally to advance through their first - if any - ascension.

Let's take nvx as an example. She has a level 99 character. That is pretty experienced in my opinion. Should she be expected to not use mafia for a multi?

That digression aside.

The characters who have not ascended getting a whole 10-ish% increase in the number of turns of a smile isn't that big a deal. I mean, the unascended are the most likely to need the help...

Damn... Have we threadjacked yet? :p
 

macman104

Member
It is indeed based on whether you have ascended. Non-ascended players will receive smiles, ascended players will always receive boxes.
 
Top