Script to mallsell/autocut hardcore-unuseable items?

Hello, I am new to scripting, and was wondering how one would go about creating a script that would mallsell and undercut the lowest mall prices for every food/alcohol item in inventory. I am doing an oxygenarian run right now, and figured that this would be an easy way to keep my inventory clean, as well as keeping up a steady flow of meat for my next softcore ascension. Thanks in advance for the help!
 

Bale

Minion
Actually, me and zarqon were just discussing a similar topic here. If you could read that you'd learn a lot about the subject.

The only remaining issue is how to only get rid of all food/booze. I think you'd have to make a list of all food/booze items in a map and then...

Code:
foreach key in sellmap
   if(item_amount(key) >0)
      cli_execute("mallsell * "+key);
Check the topic to see what the rest of your script would look like and I'd be glad to help you with it if you still have problems. I wish I knew some alternative to explicitly listing each and every food and booze in a map.
 
Last edited:
The only remaining issue is how to only get rid of all food/booze. I think you'd have to make a list of all food/booze items in a map and then...

Really? I figured that KOLMafia had some sort of means for identifying food and booze built in since it is able to honor path restrictions during hardcore runs. Is there a comprehensive list of all possible graphical CLI commands that I might be able to consult... or would it be a better idea (for me as a Java programmer) to just browse the source code looking for useful snippets? Thanks in advance for the help!
 

DerDrongo

Member
CLI command "ashref" lists all the ash functions (much better for scripting than using CLI and also needed for access to maps, just name your script with the .ash extension)
food items are stored in "fullness.txt", booze in "inebriety.txt"
EatDrink.ash uses some similar files, reading that script might help more then kolmafia's source [ http://kolmafia.us/showthread.php?t=1519 ]
 

zarqon

Well-known member
There is now an ASH function which I don't remember being there before called item_type(), which returns a string i.e. "booze" and "food". Instead of making an external map, you could just filter get_inventory() based on item_type().
 

Bale

Minion
Sweet! That's nice.

Incidentally, despite your belief my testing has revealed that mafia won't automatically split up a autosell or mallsell command that is over 11 items long. So...


Code:
string tosell ="";
int queue = 0;
int total = 0;
int price;
for i from 1 to 4000 {
	item it = to_item(i);
	if (is_tradeable(it) && item_amount(it) > 0 && (item_type(it) == "food" or item_type(it) == "booze")) {
		if (tosell.length() != 0)
			tosell= tosell + ", ";
		price = mall_price(it);
		total = price * item_amount(it) + total;
		tosell= tosell + "* "+to_string(it)+ " @ "+to_string(price);
		queue = queue + 1;
		if(queue == 11) {
			print("mallsell "+tosell, "blue");
			cli_execute("mallsell "+tosell);
			tosell ="";
			queue = 0;
		}
	}
}
if (tosell.length() != 0) {
	print("mallsell "+tosell, "blue");
	cli_execute("mallsell "+tosell);
}
print("Total Sale Price: "+total, "blue");

Granted my script will do a lot more mall lookup and take a lot longer than using undercut, but I have had some bad experiences with undercut and this is working out well for me.
 
Trying to run the above gives the following error...
Code:
> call scripts\hc_mallsell.ash

Expected ), found or (hc_mallsell.ash, line 7)

Maybe I am doing something wrong...
 

Bale

Minion
No, you did nothing wrong. I did something incredibly stupid. This will fix the problem.

Code:
string tosell ="";
int queue = 0;
int total = 0;
int price;
for i from 1 to 4000 {
	item it = to_item(i);
	if (is_tradeable(it) && item_amount(it) > 0 && (item_type(it) == "food" || item_type(it) == "booze")) {
		if (tosell.length() != 0)
			tosell= tosell + ", ";
		price = mall_price(it);
		total = price * item_amount(it) + total;
		tosell= tosell + "* "+to_string(it)+ " @ "+to_string(price);
		queue = queue + 1;
		if(queue == 11) {
			print("mallsell "+tosell, "blue");
			cli_execute("mallsell "+tosell);
			tosell ="";
			queue = 0;
		}
	}
}
if (tosell.length() != 0) {
	print("mallsell "+tosell, "blue");
	cli_execute("mallsell "+tosell);
}
print("Total Sale Price: "+total, "blue");
 

zarqon

Well-known member
To call the script you can leave off the scripts\ part. Even the .ash part. Sometimes even the call part!

Just call hc_mallsell or just hc_mallsell will work (the latter only if there is not anything else using that namespace).
 
Wow... I'm amazed I didn't catch that at first. I guess that working with SQL (the only language I know of where 'or' and 'and' are valid comparators) has ruined me. Thanks!

:::EDIT:::

Ok, so I'm still getting an error. It looks like KOLMafia is not recognizing the mall_price command. Is it possible that this function needs imported into the script/KOLMafia in some way?

Code:
Undefined reference to function 'mall_price' (hc_mallsell.ash, line 10)
 
Last edited:

zarqon

Well-known member
You might be using a version of mafia from before that command was added to ASH (it was rather recently). You can type "version" in the CLI to see which version you are running. Regardless, I recommend always using the latest daily build.
 

Bale

Minion
Since you were on the mafia forum, I was assuming you're using a recent build. As zarqon says, that command is not supported in v11.9

Since so much is always changing in this game, getting recent builds is always recommended. Simply head over to the Unofficial Builds forum and download it from the current sticky thread at the top. You can generally run .jar files on your system since you have installed java. If it gives you any trouble, just associate java with .jar files.

At the very least you'd want a recent build since the mall was broken by CDMoyer since 11.9 was released.
 
Top