Avatar changing items

mapledyne

Member
It's a pretty simplistic script, but one I find amusing (and what's KoL except amusement?).

The script can be loaded here:
Code:
svn checkout https://github.com/mapledyne/avatarpotion/trunk

And "installed" by adding to your mood (if you want it constantly checking):
Code:
Always, call avatar potion.ash
(or just run the script directly if you want to just do the check one-time)

What it does is this:
  • Put all avatar changing items in the closet.
  • If you aren't under the effect of an avatar changing item, take a random one out and use it.

If put into your mood, it'll make sure you're constantly "avatared" with a random avatar at all times.
 

Bale

Minion
I've got the following similar function in my logoutScript. It uses a random avatar potion, selected from amongst those that are cheapest in the mall. Steal whatever you like, if you like anything there.


PHP:
void avatar_potion() {
	# if(get_property("kingLiberated") == "false") return;
	
	// I like to see my West of Loathing avatars
	if(my_path() == "Avatar of West of Loathing") return;
	
	// Check if there is an Avatar potion currently in affect
	if(have_effect($effect[Juiced and Jacked]) > 0) {
		print("Won't imbibe an Avatar Potion because you already have the head of a pumpkin.", "blue");
		return;
	}
	foreach ef in my_effects()
		if(string_modifier(ef, "Avatar") != "") {
			print("Won't imbibe an Avatar Potion because you already look like a "+string_modifier(ef, "Avatar").to_monster()+".", "blue");
			return;
		}

	// Some avatars are too lame to use
	boolean lame(item it) {
		return $items[blob of acid, flayed mind, kobold kibble, Fitspiration™ poster, giant tube of black lipstick, punk patch, artisanal hand-squeezed wheatgrass juice, steampunk potion, 
		Gearhead Goo, Enchanted Plunger, Enchanted Flyswatter, Missing Eye Simulation Device, Gnollish Crossdress, gamer slurry]
			contains it;
	}

	int avatar_price(item it) {
		if(historical_price(it) > 900)
			return historical_price(it);
		return historical_age(it) > .8? mall_price(it): historical_price(it);
	}
	
	item random_avatar() {
		item [int] avatars;
		int cheapest_price() {
			sort avatars by avatar_price(value);
			foreach x,av in avatars
				if(avatar_price(av) > 0) return avatar_price(av);
			return 0;
		}
		
		foreach it in $items[]
			if(item_type(it) == "avatar potion" && (can_interact() || available_amount(it) > 0) && !lame(it))
				avatars[ count(avatars) ] = it;
		if(count(avatars) == 0)
			return $item[none];
		int min_price = cheapest_price() * 1.3; // Let's include everything up to 30% above minimum price... which will be 130 meat if can_interact() although slightly higher in hardcore.
		item [int] short_list;
		foreach x,av in avatars
			if(avatar_price(av) <= min_price)
				short_list[ count(short_list) ] = av;
		if(count(short_list) == 1)
			return short_list[0];
		return short_list[ random(count(short_list)) ];
	}

	item choice = random_avatar();
	if(choice != $item[none] && retrieve_item(1, choice))
		use(1, choice);
}
 
Last edited:

VladYvhuce

Member
Very useful for separating out the Avatar Potions from other usable stuff. I really don't care what my avatar looks like, so that's not a problem. The storage of these potions also allows for one to sell them rather efficiently. Which leads to a question: Could it be altered to autosell the APs?
 

Bale

Minion
You said you are interested in learning how to modify scripts for yourself. This script look like a good one to learn from. Execution of the program begins with the function called main().

main() has two main parts. First it sorts out the potions and uses put_closet() to put them in the closet. You'll want to find the spot where they are being put in the closet. Then change that to a command that autosells using autosell().

The second half of main() then decides which potion to use. You could delete all of that because you don't want to do that.

If you have any other questions, please ask! We're eager to help you learn.
 

VladYvhuce

Member
Cool. I'll give that a try tonight.

I'm assuming for this sort of modification, it would work better to save it as a separate file, and call that, instead? That way, I could use the original if I start feeling more whimsical, and not have to download anther copy if I happen to mess up the modifications.
 

Bale

Minion
You could certainly do that. If you do, then save your new file in the /scripts directory. The edits in the /svn directory can only be synced if they are a versioned file and a new file of your creation would not be.
 

VladYvhuce

Member
Well... I can't figure out how to get rid of that second part of the script without breaking it. Specifically, it keeps telling me that it expects to have a "}" and found a ";" instead as the end. And if I replace the ; with a }, it says it wants it back the way it was before. I think I'm beginning to understand why coders go insane... So, I just went ahead and modified the "use" function into a second "autosell" and it stopped having hissy fits and worked.

Also, thanks for the info regarding the directories. It clears up some confusion I had.
 

Bale

Minion
For every { you need a matching }.

I'm not sure how much of it you were trying to delete, but I was referring to ALL of this:

Code:
  // if we already have an avatar potion active, bail.
  if (has_avatar_active())
  {
    return;
  }

  item[int] potions;
  int count = 0;
  foreach it in $items[]
  {
    if (is_avatar_potion(it))
    {
      if (closet_amount(it) > 0)
      {
        potions[count] = it;
        count += 1;
      }
    }
  }
  if (count( potions ) == 0)
  {
    print("Sorry, no avatar changing potions found.");
    return;
  }

  sort potions by random(100000);
  item avatar_potion = potions[0];
  take_closet(1, avatar_potion);
  use(1, avatar_potion);
 

VladYvhuce

Member
That chunk is precisely what I tried deleting. The script wasn't happy about it, so I put it all back in. I was able to delete the print function with no problem, though. It seems to be running smoothly with "use(1, avatar_potion);" turned into "autosell(1, avatar_potion);".
 

theo1001

Member
My guess is that you deleted one more line than shown above, either line 27 or 57, thus creating unmatched brackets.

This may help in the future. A list of ASH errors and what usually causes them.
 

VladYvhuce

Member
Ah-ha! Now that I've got some sleep, I see what happened. Since I'm using Notepad, it doesn't show up properly as lines, so what should be "use(1, avatar_potion);" and then a "}" on the next line shows up as "use(1, avatar_potion);}". It works when I don't delete that last bracket. :D Maybe I should be using a different program for editing scripts. If so, which one?
Also, thanks for the errors list. It's better knowing how I broke something, rather than just that I broke something.
 

Crowther

Active member
Ah-ha! Now that I've got some sleep, I see what happened. Since I'm using Notepad, it doesn't show up properly as lines, so what should be "use(1, avatar_potion);" and then a "}" on the next line shows up as "use(1, avatar_potion);}". It works when I don't delete that last bracket. :D Maybe I should be using a different program for editing scripts. If so, which one?
Also, thanks for the errors list. It's better knowing how I broke something, rather than just that I broke something.
I leave it to others to suggest what editor you should download for Windows, but I want to point out that wordpad handles UNIX style newlines and is standard with Windows just like notepad.
 

Ethelred

Member
I've heard people recommend notepad++ for Windows. I run on a Mac and use TextWrangler, with which I'm very happy.

Edit: Ninja'd by Darzil
 
Last edited:

VladYvhuce

Member
Worpad crashes when set as Mafia's script editor, saying it can't find the specified file (meaning the script I tried to edit). But I set it to be the new default program for opening them in Windows, instead of Notepad, so I can at least open them the old fashion way. At least, this way, I can see them as they're supposed to be instead of all one big paragraph.
 
Top