Help with a script

Pazleysox

Member
Here's what I was able to come up with. If there's an easier way to do it, I would be happy to change it. Criticism, good or bad, is always welcome. :)

this is how my MP-Burning portion is called.
PHP:
		set_property("autoManaRestore", "false");		// this saves your meat
		mp_burner();
		set_property("autoManaRestore", "true");

PHP:
void mp_burner()
{
int burn = my_mp() * .85;
string body;
body = visit_url ("campground.php");

	cli_execute("burn " + burn + " mana");
	if(get_property("nunsVisits") < 3 && my_maxmp() * .85 > my_mp()  ) // I figured having 15%, or less of your max MP was a good place to restore MP
		{
		visit_url("postwarisland.php?place=nunnery");
		visit_url("postwarisland.php?action=nuns&pwd&place=nunnery");
		cli_execute("burn " + burn + " mana");
		}
	if(get_property("expressCardUsed") == "false" && $item[Platinum Yendorian Express Card].available_amount() > 0 && my_maxmp() * .85 > my_mp() ) // I figured having 15%, or less of your max MP was a good place to restore MP
		{
		use(1, $item[Platinum Yendorian Express Card]);
		cli_execute("burn " + burn + " mana");
		}
int mpburn = my_mp() * .50; // I figured having 50% of your MP left was a good place for rollover
	if ($item[heart of dark chocolate].available_amount() > 0 && get_property("_darkChocolateHeart") == "false" && my_maxmp() - my_mp() > 50)
		{
		use (1, $item[heart of dark chocolate]);
		cli_execute("burn " + mpburn + " mana");
		}
	if(get_property("_eternalCarBatteryUsed") == "false" && $item[eternal Car Battery].available_amount() > 0 && my_maxmp() - my_mp() > 50)
		{
		use(1, $item[eternal Car Battery]);
		cli_execute("burn " + mpburn + " mana");
		}
	if(get_property("oscusSodaUsed") == "false" && $item[Oscus's neverending soda].available_amount() > 0 && my_maxmp() - my_mp() > 200 )
		{
		use(1, $item[Oscus's neverending soda]);
		cli_execute("burn " + mpburn + " mana");
		}
	if(contains_text(body,"_free.gif") && my_maxmp() - my_mp() > 150)
		{
		cli_execute("rest");
		cli_execute("burn " + mpburn + " mana");
		}
		else // when there's nothing left, this will fire off
			{
			cli_execute("burn " + mpburn + " mana");
			return;
			}
mp_burner(); //this loops it back around to grab all free restorers until there are none left.
}
I tried to figure out how to get the user set preference for MP, but I couldn't make it work, so I figured 50% of your MAX is pretty good.

The full script is pretty user friendly, or as user friendly as I can make it. It includes a few new script related preferences, which will allow, or disallow options to be done. The MP-Burn is an option users can shut off.

EDIT: I forgot about License to Chill, and April Shower (HOT) I'll have to script that in too

EDITEDIT:
Stealing these lines from Zarqon:
if (numeric_modifier("Base Resting MP") < 40 && item_amount($item[Frobozz Real-Estate Company Instant House (TM)]) > 0 && use(1,$item[Frobozz Real-Estate Company Instant House (TM)])) {}
if (numeric_modifier("Base Resting MP") < 10 && retrieve_item(1,$item[Newbiesport™ tent]) && use(1,$item[Newbiesport™ tent])) {}
and making nun-restoring faster. :)
 
Last edited:

Pazleysox

Member
I found this nice little snippet on Bale's login script forum.

I believe Bale is the one who wrote it

PHP:
	{
	int tomeLeft = 3- get_property("tomeSummons").to_int();
	if (tomeLeft > 1)
	print("returned true");
		{
		item [int] clip;
		for i from 5224 to 5283
		clip[count(clip)] = i.to_item();
		sort clip by -mall_price(value);
		for i from 0 to tomeLeft - 1 
			{
			create(tomeleft, clip[i]);
			print("Sell "+clip[i]+" for "+mall_price(clip[i]), "blue");
			put_shop(mall_price(clip[i]), 0,  clip[i]);
			}
		}
	}
Here's the final result, after searching for all clip art
Sell Temps Tempranillo for 8000
Sell none for 0
Sell none for 0
Sell none for 0
Sell none for 0
Sell none for 0
Sell none for 0
Sell none for 0
Sell none for 0
Sell none for 0
Sell none for 0

If never creates the Temps Tempranillo though...
 

icon315

Member
Well you somehow seemed to have cut out part of the code, based on your curly braces there was something after 'print("returned true");'
It was most likely a check to see if tomeleft is > 0. The reason it didn't create it is most likely because the input for create was 'create(0, Temps Tempranillo);' which it did. then it continued and put that 0 temps into the mall.

Try this, should work (can't test it as i don't have the tome), i'm assuming this is a function within a script:
PHP:
boolean clipArt()
{
	int tomeLeft = 3- get_property("tomeSummons").to_int();
	if (tomeLeft < 1){	print("returned true"); return false;}
	item [int] clip;
	for i from 5224 to 5283
		clip[count(clip)] = i.to_item();
	sort clip by -mall_price(value);
	if(!create(tomeleft, clip[0]) || tomeleft == 0)
	{
		print("Failed to summon "+tomeleft+" "+clip[0]	);
		return false;
		}
	else{
		print("Sell "+clip[0]+" for "+mall_price(clip[0]), "blue");
		put_shop(mall_price(clip[0]), 0,  clip[0]);
	}
	return true;
}

I didn't understand the reasoning behind 'for i from 0 to tomeLeft - 1 '
 
Last edited:

xKiv

Active member
...
code with heretical indenting
...

Code:
if (tomeLeft > 1)
    print("returned true");
        {

I bet that that print was not in the original code, because as it is, it is totally negating the point of the "if". You are printing "returned true" if tomeLeft > 1. And then, disirregardless of what tomeLeft >1 was, you continue with the inner block.

Also, the for cycle probably does not do what you think it does when tomeLeft is zero (I also didn't know it behaves like this until I tried it):
Code:
> ash for i from 0 to -1 { print(i); }

0
-1
Returned: void

And, unsurisingly, clip[-1] == $item[none], because you never initialized negative indexes.
 

xKiv

Active member
I didn't understand the reasoning behind 'for i from 0 to tomeLeft - 1 '

"If you have 3 tome summons left, don't create 3 of the most expensive thing, but 1 of the most expensive thing, 1 of the second most expensive thing, and 1 of the third most expensive thing". Spread you eggs across several baskets. Diversify your portfolio.
 

icon315

Member
"If you have 3 tome summons left, don't create 3 of the most expensive thing, but 1 of the most expensive thing, 1 of the second most expensive thing, and 1 of the third most expensive thing". Spread you eggs across several baskets. Diversify your portfolio.
Well he'd use all his summons on the first loop:
PHP:
create(tomeleft, clip[i]);
then on every loop from then on it would try to create 3 and fail. instead it should just be create(1,...)
surprisingly this behaves differently than what i expected:
Code:
> ash for i from 1 to 3 { i--; print(i); }

0
1
2
Returned: void
also i just looked up tomeSummons, not really sure what it checks (I'm assuming it checks all tomes and returns how many you've summoned all together) it returns 3 for me every time, even though i don't have clipart. I would use _clipartSummons instead. I guess you could check to see if you have clip art, but that seems unnecessary.
So he can do:
PHP:
    int tomeLeft = 3- get_property("_clipartSummons").to_int();
    if (tomeLeft > 1)
        {
        item [int] clip;
        for i from 5224 to 5283
        clip[count(clip)] = i.to_item();
        sort clip by -mall_price(value);
        for i from 1 to tomeLeft 
            {
            i--;
            create(1, clip[i]);
            print("Sell "+clip[i]+" for "+mall_price(clip[i]), "blue");
            put_shop(mall_price(clip[i]), 0,  clip[i]);
            }
        }
 

Pazleysox

Member
PHP:
    int tomeLeft = 3- get_property("_clipartSummons").to_int();
    if (tomeLeft > 1)
        {
        item [int] clip;
        for i from 5224 to 5283
        clip[count(clip)] = i.to_item();
        sort clip by -mall_price(value);
        for i from 1 to tomeLeft 
            {
            i--;
            create(1, clip[i]);
            print("Sell "+clip[i]+" for "+mall_price(clip[i]), "blue");
            put_shop(mall_price(clip[i]), 0,  clip[i]);
            }
        }
Without manually looking at mall prices, I think this code worked perfect.

Here's part of the final output:

Sell Temps Tempranillo for 7992
Adding Temps Tempranillo to store...
4 Temps Tempranillo added to your store.
Creating 1 thyme jelly donut...
Casting Summon Clip Art 1 times...
You acquire an item: thyme jelly donut
Summon Clip Art was successfully cast.
Successfully created thyme jelly donut (1)
Sell thyme jelly donut for 7990
Adding thyme jelly donut to store...
1 thyme jelly donut added to your store.
Creating 1 potion of the field gar...
Casting Summon Clip Art 1 times...
You acquire an item: potion of the field gar
Summon Clip Art was successfully cast.
Successfully created potion of the field gar (1)
Sell potion of the field gar for 7990
Adding potion of the field gar to store...
 

Pazleysox

Member
I didn't write this code. Either Bumcheekcity, or Hippoking wrote it, many years ago. Th3y modified it at some point.

PHP:
        string body = visit_url("/skills.php");
	int start = index_of(body,"select a skill");

	body = substring(body,start,index_of(body,"</select>",start));
	string [int] skills = split_string(body, "><");

	foreach X in skills 
		{
		if (contains_text(skills[X],"MP")) 
			{
			string skillName = substring(skills[X],index_of(skills[X],">")+1,index_of(skills[X]," ("));
			string skillCost = substring(skills[X],index_of(skills[X]," (")+2,index_of(skills[X],")"));
			if (!contains_text(skills[X],"disabled") && (
				contains_text(skillName, "Snowcone")			||
				contains_text(skillName, "Stickers")			        ||
					{
					print_html("You can still cast <font color=FF0000>"+skillName+"</font> today.");
					}
		else if(!in_bad_moon( ) && skillcost < my_maxmp() && (
			contains_text(skillName,"Party Favor")	||
			contains_text(skillName,"Candy Heart")	||
				{
				print_html("You can cast <font color=FF0000>"+skillName+"</font> for <font color=FF0000>"+skillCost+"</font>");
				}
			}
		}

I've taken out some irrelevant code (like more skills...) This part of this code works just fine on my main, which has all these skills. However, I tested it on a multi, which has NONE of these skills, and I get this error:
Begin index 19 greater than end index -1 (Rollover Management.ash, line 730)

I don't understand how this whole thing works, or what this error means... Any input is greatly appreciated!
 

icon315

Member
Code:
Begin index 19 greater than end index -1 (Rollover Management.ash, line 730)
This means that it can't find the index_of. All this code is unnecessary though. Most of these skills have a function
In mafia that can do this. See http://wiki.kolmafia.us/index.php?title=Have_skill

This also help http://wiki.kolmafia.us/index.php?title=Daily_Variables


EDIT: I guess I can try to explain the code a bit
PHP:
//visits the skills page and saves the html into a var.
     string body = visit_url("/skills.php");
//finds the index (location) of "select a skill", which will return -1 if it can't find it.
    int start = index_of(body,"select a skill");
//resets the body car to exclude the substring from the index of start to the index of "</select>"
    body = substring(body,start,index_of(body,"</select>",start));
//creates a map of each of the substring between each "><"
    string [int] skills = split_string(body, "><");
//I can't really tell what this part does without looking at the html of the page. But it basically finds all the skills you have and how much MP they cost to cast
    foreach X in skills 
        {
        if (contains_text(skills[X],"MP")) 
            {
            string skillName = substring(skills[X],index_of(skills[X],">")+1,index_of(skills[X]," ("));
            string skillCost = substring(skills[X],index_of(skills[X]," (")+2,index_of(skills[X],")"));
            if (!contains_text(skills[X],"disabled") && (
                contains_text(skillName, "Snowcone")            ||
                contains_text(skillName, "Stickers")                    ||
                    {
                    print_html("You can still cast <font color=FF0000>"+skillName+"</font> today.");
                    }
        else if(!in_bad_moon( ) && skillcost < my_maxmp() && (
            contains_text(skillName,"Party Favor")    ||
            contains_text(skillName,"Candy Heart")    ||
                {
                print_html("You can cast <font color=FF0000>"+skillName+"</font> for <font color=FF0000>"+skillCost+"</font>");
                }
            }
        }
 
Last edited:

Pazleysox

Member
Code:
Begin index 19 greater than end index -1 (Rollover Management.ash, line 730)
This means that it can't find the index_of. All this code is unnecessary though. Most of these skills have a function
In mafia that can do this. See http://wiki.kolmafia.us/index.php?title=Have_skill

This also help http://wiki.kolmafia.us/index.php?title=Daily_Variables

I figured out why I was getting this error. It's partly the code, partly KOL configuration.

My guess is that this script was written before the skills page was changed. This portion of this script requires /skills.php to be set to "Big and Chunky", with 'Drop down menus"... Any other variation from that, and the script won't work properly.

Now I have to find a new way to write this portion of code so that it works the same way. I'm not worried so much about the tomes, it's the Grimoires MP...

I will look into it though. I'm sure there's a better way.
 

lostcalpolydude

Developer
Staff member
Now I have to find a new way to write this portion of code so that it works the same way. I'm not worried so much about the tomes, it's the Grimoires MP...

Do you mean librams? That's what mp_cost() is for. If the code starts with visit_url() then there's a good chance it's missing something.
 

icon315

Member
You can do something like
PHP:
skill skillstocheck = [Summon Snowcones , Summon Stickers]

foreach i in skillstocheck
if(i.haveskill())
    print_html("You can cast <font color=FF0000>"+i+"</font> for <font color=FF0000>"+i.mpcost+"</font>");
Note that there's probably some syntax/spelling errors in this code, so it will give errors. But when fixed it should work.
 

Pazleysox

Member
You can do something like
PHP:
skill skillstocheck = [Summon Snowcones , Summon Stickers]

foreach i in skillstocheck
if(i.haveskill())
    print_html("You can cast <font color=FF0000>"+i+"</font> for <font color=FF0000>"+i.mpcost+"</font>");
Note that there's probably some syntax/spelling errors in this code, so it will give errors. But when fixed it should work.

I can see how that work, but how do I check if the skill has been cast already? (see below)


I've been fooling around with this most of the day, and now I'm stuck. I could use a (gentle nudge) hard push in the right direction...

This works...
PHP:
	foreach f in $familiars[Adventurous Spelunker, Ancient Yuletide Troll, Angry Jung Man, Astral Badger, Baby Bugged Bugbear, Baby Sandworm] (etc)
		if (have_familiar(f) && f.drops_today < f.drops_limit)
	{
		print_html("Your familiar <font color=FF0000>" + f + "</font> still has free drops available today");
	}

but this doesn't...
PHP:
foreach it in $skills [Advanced Saucecrafting, Advanced Cocktailcrafting, Pastamastery, Summon Crimbo Candy, Lunch Break, Summon Holiday Fun!, Summon Carrot] (etc)
		if (have_skill(it) && it.summon_today < it.summon_limit)
	{	print ("You can still cast " + it );	}}
I went through the preferences, and it looks like each familiar with a drop looks like this example: _spaceJellyfishDrops
and each skill that relates to a summon, looks like this example: _stickerSummons

I'm completely stuck on this one now... I really don't want to write a check for each and every skill, when I'm sure there's an easier way around it.
 

Pazleysox

Member
You need to write a check for each skill.

:(


PHP:
int f;
    foreach f in $familiars[Adventurous Spelunker, Ancient Yuletide Troll, Angry Jung Man, Astral Badger, Baby Bugged Bugbear, Baby Sandworm] (etc)
        if (have_familiar(f) && f.drops_today < f.drops_limit)
    {
        print_html("Your familiar <font color=FF0000>" + f + "</font> still has free drops available today");
    }
This was working the other day, now it's not...

but this script that Vlad is using works:
PHP:
familiar next_familiar() {
	foreach f in $familiars[fist turkey, adventurous spelunker, machine elf, astral badger, baby sandworm, rogue program, green pixie, li'l xenomorph, llama lama, blavious kloop, bloovian groose]
		if (have_familiar(f) && f.drops_today < f.drops_limit)
			return f;
	if (have_familiar($familiar[robortender])) return $familiar[robortender];
	return my_familiar();

I'm getting very discouraged with my scripting skills...
 
Last edited:

Pazleysox

Member
You're declaring a variable twice here

I only put that in, because Mafia kept telling me, it couldn't figure out what 'F' was...

I figured out what the issue was, aside from the "int f;"

I had this in too:
if (my_inebriety() < inebriety_limit() && my_adventures() > 0)

while my drunkeness was 14, it was effectively NOT < inebriety_limit()...
 
Top