help a new guy get started

stadsalv

New member
Hi!

I'm really new to the world of scripting for KoLmafia but I've done some basic programing in C++ and Java and wanted to try this out as well.

Is there a beginner's guide anywhere?

The main reason I want to learn how to script is that I'm going away sailing for 4 weeks this summer and don't want to miss 28 lucre. Therefore I want to write a script that uses 1 MoM, eats Hi Meins, does a BHH hunt, burns the rest of the turns in the castle, casts Ode, drinks until it falls over and goes to sleep. After that Mafia closes. If this can be done in just one script, please let me know.

I'm running WinVista and I know how to make it run Mafia once a day. Is there any way to get Mafia to load the script automatically or do I have to find someone to do it for me?

I hope this isn't to much of a request and gets deleted...

Thanks in advance!
/Alv
 
You would do better to find someone to monitor it. Though Kolmafia is a really great program there is always the element of Jick making changes server side which break Kolmafia.

Kolmafia was never intended to completely run a characters life, though I have in the past used it to do so. Even the best laid out scripts still require a level of supervision.

A 28 day sailing trip is the kind of trip which I would unplug the fridge, and leave it's door standing open for. Are you sure you would want to leave your computer running that entire time with no-one around? Heck, I would unplug everything because I would like to see an electric bill under $20 for that month.
 

stadsalv

New member
I have access to a computer that runs 24/7, that won't be the problem, but I see what you're saying. I'll ask my brother if he can monitor it for me.

What about the script? Is it possible and where do I start? My brother doesn't play KoL and I think he would be happier if all he needed to do was to start Mafia and load one script. Then I'll write a list so that he knows what to do if it fails.
 
OK, start by creating a new folder for kolmafia to reside in. This will minimize the "junk". Put kolmafia in the folder.

write the script, look into turn burning scripts for a place to start doing what you are wanting. also visit the wiki to learn about functions in kolmafia ash scripting.

The final command in the script will need to be
Code:
cli_execute("exit");

startup kolmafia
Login with save password, and autologin selected.

go to the breakfast tab in kolmafia preferences and assign the script you want to run daily.

of course since you have done programming before, you know there will be debugging to do, so start several days ahead of time.

Once you have begun return to this thread with other questions.
 

stadsalv

New member
Thanks! I'll get started after my exam on Monday. Got a multi at lvl 15 to test with and about a month before I sail away. The monitoring is fixed since my brother agreed to run Mafia once a day for me.

EDIT

couldn't resist :)
Here's my very first script. It still needs a lot of work in the middle but I have an idea about how the language works now.

Code:
outfit("work");

use (1, $item[milk of magnesium]);
eat (3, $item[spooky hi mein]);

#Pick hilvl BHH-q and do it

#Buy buffs from buffbots

while ( my_adventures() > 20 )
    adventure( 1, $location[ castle in the clouds in the sky ] );

use (1, $item[salty dog]);
use (5, $item[roll in the hay]);

outfit("sleep");

cli_execute("exit");
 

tebee

Member
Here's a script which does roughly what you want, although it's untested in it's current form, it's a collection of bits from various scripts I use which do work. It needs the bounty hunter library from the link in the last post and you'll need to change the outfit and mood names to whatever you use and there are several other things you may want to change to your personal preference.

It needs the cli_execute("exit"); outlined above adding to run it unattended every day but I've left this off so you can test it.

Tom

Updated version of script added 27/05/08
 

Attachments

  • day.ash
    25.8 KB · Views: 121

stadsalv

New member
Thanks for the script! I tried to run it but all I get is "Unknown variable 'import' (day.ash, line 512)"

If I'm not misstaken, the script does almost exactly what I had in mind and a little more. If I buy a pile of food and booze it wont buy anything from the mall, right? Assuming I bought the right kind.

Is it possible to turn of the casting of advanced cocktailcrafting and the likes? I will be in post-prism BM if things go as planned and wont have these skills. (Not optimal at all, but I'm not looking to meatfarm, just get my 1 lucre á day without going bankrupt or messing up a mini-BM loop)

I might just use your ideas for the BHH and the buffbots, since I know what class I will be and what I will have to eat.
 

tebee

Member
The import will fail if you you haven't downloaded and unzipped to your script folder the bounty hunter files from http://kolmafia.us/index.php/topic,1473.0.html - in fact the bhh bit of the script is lightly modded version of one of those files.

There's a line -

if (have_skill($skill[Superhuman Cocktailcrafting])&& (stills_available() > 1))

This means it will only try to make the drinks if you have the skill to make them and have access to and uses of the still available. If not it will use the best superhuman drink you have in your inventory - though it doesn't check for all possible ones. If nothing is found it will look for an unimproved drink - first from your inventory, then try and make it, and if all else fails buy it from the mall(this is what "acquire" does.) It is of course possible to chance this to whatever drinks you prefer.

If, as you suggest, you buy sufficient drinks from the mall beforehand it will simply use those. I can recommend the shop of my mall trading multi for a good supply of suitable drinks!

I tried to make my scripts as versatile as possible - it will even handle teetotal etc, though it might struggle with hardcore .


Tom
 

tebee

Member
Ah - I did not know that........

Guess we really ought to get on with that wiki.....

I've put an updated version of the script in the post above - maybe I ought to test it myself.......

Tom
 
I can see some ways that script could be simplified reducing that 933 line count down. Maybe this info will make your future script writing easier

Code:
# This returns the primary statistic for your character's class
stat my_stat()
{
	stat st;
	st = class_to_stat(my_class());
	return st;
}

stat my_primestat() does the exact same

Code:
// auto sells all but "leave" of an item

void auto_sell(string item_string, int leave)
{
    item item_item;
	int count;
	item_item = to_item(item_string);
	count = item_amount(item_item);
	if (count>leave)
	{
		int difference;
		difference = count-leave;
		print ("Now auto selling " + to_string(difference) +" of " + item_string, "red");
		autosell(difference, item_item);
	}
}

can be simplified:
PHP:
void auto_sell(string item_string, int leave)
{
cli_execute("autosell " + leave + " " + item_string);
}

Code:
// puts in clan stash all but "leave" of an item

void to_stash(string item_string, int leave)
{
    item item_item;
	int count;
	item_item = to_item(item_string);
	count = item_amount(item_item);
	if (count>leave)
	{
		int difference;
		difference = count-leave;
		put_stash(difference, item_item);
	}
}

can also be simplified:
PHP:
void to_stash(string item_string, int leave)
{
cli_execute("stash put " + leave + " " + item_string);
}

Both the auto-sell and stash put functions (along with many others) in the cli understand a negative number to mean "do this with all but this many of the item".
 

zarqon

Well-known member
efil, I think you meant this:

PHP:
cli_execute("autosell -" + leave + " " + item_string);

cli_execute("stash put -" + leave + " " + item_string);

Note the "-" before leave. You said it but didn't write it. :) You could pass a negative integer for the same effect (and greater flexibility), but for the functions to work like the originals, it needs the -.

Also writing separate functions for this is unnecessary.

@stadsalv: You can declare variables and initialize them with values in the same line. For example, instead of:

Code:
int difference;
difference = count-leave;

You can just use
PHP:
int difference = count-leave;

Just FYI.
 

tebee

Member
Ah, even more things I didn't know about Mafia and I've been scripting for about 15 months now.

I don't claim this script to a great feat of programing , it had it's origins in a number of scripts I've hacked together, mostly originating in ones downloaded from here over the months, though I've thoroughly changed most of them to suit my own needs.

I tend not to worry too much about the efficiency of the code in mafia scripts as long as it does not make unnecessary server requests, it's only my computer's CPU cycles I'm wasting and it's normally got plenty of those going spare., what do other people think?
 

zarqon

Well-known member
[quote author=tebee link=topic=1731.msg8206#msg8206 date=1211922120]I tend not to worry too much about the efficiency of the codein mafia scriptsas long as it does not make unnecessary server requests, it's only my computer's CPU cycles I'm wasting and it's normally got plenty of those going spare., what do other people think?[/quote]

Perfectly reasonable. At this level, most (non-server-hitting) efficiency issues are negligible. But scripters are all about the efficiency, so if you're sharing scripts that have inefficiencies or "wordiness", someone is bound to point it out. :)

But in the end, it boils down to what works best, which is of course somewhat subjective.
 

tebee

Member
I suppose it's something of a style thing, I like to have similar routines to do similar things , it means when you come back and try to remember what your code was doing you only have to work it out once. I personally value clarity of code over brevity.

I can write tight efficient code when it is needed - my early programing work was doing online IBM 370 assembler transactions - 800 users on a machine with 256 k main memory, eyh lad , I feel a four Yorkshiremen sketch coming up........

Most of the time I never get round to sorting all of the things I mean to do to tidy up my code, added to which I'm naturally lazy, you may note I deliberately coded these routines so I could call them by using auto_sell("original G", 1 ); rather than auto_sell(item[original G], 1 ); - a whole four characters less to type each time!

Tom
 
One of this site's reason for being here is for people to learn about scripting. I learn new stuff all the time, and I try to help others when I can.

Later Tebee, when you are typing up a new script the things I pointed out might just save you some typing. That's where it's at.

Thank you zarqon for correcting the negative thing for me. When I typed it, I read it multiple times and missed my omission. BTW the extra function wrapper for the auto-sell command makes encoding 50 of them statements easier, and more ash-like. The whole group of auto sell commands and stash commands could also be put into 1 cli_execute statement though.
 
Top