Scripting Question?

dterphraud

New member
A few years ago I wrote my first and only cli script and recently I wrote my first Ash script (or should I say took some snipets mostly from Bale - thanks). I had to break out this part of the script and run it separately because it usually "times out" leaving adventures left to play. Not a big problem, I just restart the script, but, I would like it to be more reliable and play all the available adventures. Then, I can reconnect it with my login and logout scripts.

Here is the code:

adventure(my_adventures(), $location[Giant's Castle]);
batch_open(); // This tells mafia that there will be a lot of autoselling, malling or other batch activity, //so it should save them up.
int saleprice = 0;
foreach it in $items[heavy D, Original G, disturbing fanfic, furry fur, wolf mask, awful poetry journal, thin black candle, chaos butterfly, plot hole, probability potion, procrastination potion, angry farmer candy, giant needle, Mick's IcyVapoHotness Rub, rave whistle]
{
autosell(item_amount(it), it);
saleprice = item_amount(it) * autosell_price(it) + saleprice;
}
batch_close(); // Now it executes all recorded batch ativitites in groups of 11 at a time.
print("autosold trash for "+ saleprice +" meat.", "blue");

use(item_amount($item[Warm Subject gift certificate]), $item[Warm Subject gift certificate]);


I would enjoy your comments and suggestions.
 

lostcalpolydude

Developer
Staff member
That actually works? I would expect item_amount(it) to to be 0 after you autosell all of the item.

The equipment in that list (wolf mask, giant needle, rave whistle) is better off smashed than autosold. Even if you then proceed to autosell the nuggets.
 

dterphraud

New member
It works but, like I said, I usually need to restart the script at least once. Thanks for the suggestion, I intend to add the Pulverize comment when I get it to run flawlessly.
 

StDoodle

Minion
First, the time-out issue is probably inescapable during the Crimbo holiday, I'd guess. Second, his pricing works because it's in a batch; it would probably be safer to move those two lines around, though, just in case.
 

slyz

Developer
Check what happens when Mafia stops before using all your adventures: you probably have an auto-abort du to low health, a counter, or some other condition that makes it stop (you could try adding cli_execute( "conditions clear" ) before the first line).

If lag is stopping the auto-adventuring, you could try replacing
PHP:
adventure(my_adventures(), $location[Giant's Castle]);
by
PHP:
while( my_adventures() > 0 ) if ( adventure( 1, $location[Giant's Castle]) ) {};
 

Theraze

Active member
I'd prefer this code, just because it's shorter (and does the same thing):
PHP:
while (my_adventures() > 0) (!adventure(1, $location[Giant's Castle]));
 

dterphraud

New member
Thanks all! This worked perfectly:

while (my_adventures() > 0) (!adventure(1, $location[Giant's Castle]));

I looked through my logs and saw 2 instances of "nothing more to do" but it kept adventuring until all adventures where spent. This also helped me with a couple other questions.
 
Top