Vlad's Familiar Changing Frankenscript

VladYvhuce

Member
I've finally figured it out! When set as a between battle script, this script will run through the listed familiars, farming their items in the priority of the listed familiars (5 turkey boozes, then 1 tales of spelunking, and so on), and then switch to the Intergnat, if you have enough adventures left over. If you run out of adventures before the list is through, you'll just have the familiar you were farming with equipped. Also: For whatever reason, once you stop adventuring, if your familiar was changed while adventuring, you will receive a minor error message "Your" [current familiar] "can't wear a" [the equipment the familiar you had when you started adventuring had]. I'm sure that there are ways to make the script more elegant. You can customize it to work with any set of familiars with droppable item limits, and replace "intergnat" with whatever familiar you want to use after farming. And I'm sure someone may be able to figure out how to get it to only farm a specific number of droppable items, if they want it to do that.
Code:
void main ()
    if (my_familiar() != $familiar[fist turkey] && $familiar[fist turkey].drops_today < $familiar[fist turkey].drops_limit) 
		use_familiar($familiar[fist turkey]);
	if (my_familiar() == $familiar[fist turkey] && $familiar[fist turkey].drops_today == $familiar[fist turkey].drops_limit) 
		use_familiar($familiar[adventurous spelunker]);
	if (my_familiar() == $familiar[adventurous spelunker] && $familiar[adventurous spelunker].drops_today == $familiar[adventurous spelunker].drops_limit) 
		use_familiar($familiar[machine elf]);
	if (my_familiar() == $familiar[machine elf] && $familiar[machine elf].drops_today == $familiar[machine elf].drops_limit) 
		use_familiar($familiar[astral badger]);
	if (my_familiar() == $familiar[astral badger] && $familiar[astral badger].drops_today == $familiar[astral badger].drops_limit) 
		use_familiar($familiar[unconscious collective]);
	if (my_familiar() == $familiar[unconscious collective] && $familiar[unconscious collective].drops_today == $familiar[unconscious collective].drops_limit) 
		use_familiar($familiar[baby sandworm]);
	if (my_familiar() == $familiar[baby sandworm] && $familiar[baby sandworm].drops_today == $familiar[baby sandworm].drops_limit) 
		use_familiar($familiar[golden monkey]);
	if (my_familiar() == $familiar[golden monkey] && $familiar[golden monkey].drops_today == $familiar[golden monkey].drops_limit) 
		use_familiar($familiar[rogue program]);
	if (my_familiar() == $familiar[rogue program] && $familiar[rogue program].drops_today == $familiar[rogue program].drops_limit) 
		use_familiar($familiar[green pixie]);
	if (my_familiar() == $familiar[green pixie] && $familiar[green pixie].drops_today == $familiar[green pixie].drops_limit) 
		use_familiar($familiar[li'l xenomorph]);
	if (my_familiar() == $familiar[li'l xenomorph] && $familiar[li'l xenomorph].drops_today == $familiar[li'l xenomorph].drops_limit) 
		use_familiar($familiar[intergnat]);
 

Theraze

Active member
Alternatively:
Code:
familiar next_familiar() {
	foreach f in $familiars[fist turkey, adventurous spelunker, machine elf, astral badger, unconscious collective, baby sandworm, golden monkey, rogue program, green pixie, li'l xenomorph]
		if (have_familiar(f) && f.drops_today < f.drops_limit)
			return f;
	if (have_familiar($familiar[intergnat])) return $familiar[intergnat];
	return my_familiar();
}

void main() {
	next = next_familiar();
	if (next != my_familiar()) use_familiar(next);
}
 
Last edited:

VladYvhuce

Member
Well, that certainly looks more elegant. And it's got some more complex stuff than my previous attempts at simplifying it, which may have been why I kept running into weird glitches in those attempts. I'll give it a shot tonight.
 

Theraze

Active member
Well, the main problem (not a problem if it's on purpose) with your script is that it only changes if you never change your familiar manually. If your familiar is not exactly the prior familiar before the familiar drop changes, it won't swap. The only full-entry point in the script is when your fist turkey doesn't have drops done yet. After that's done, if you change familiars out of the chain, the script won't trigger anymore.

If you wanted that feature though, to allow setting a non-drop, non-intergnat familiar (If you actually possess the intergnat. If you don't have an intergnat, it will leave you on whatever your current familiar is.), you'd need to write up a few changes to the script I made. Not difficult, just something to be aware of.

It's good to practice though. It's something like 8 years of ASH scripting at this point and it's not as elegant as some of the more experienced writers would do. I'm just good at kludge. Sometimes elegant kludge, but utilitarian nonetheless.
 

VladYvhuce

Member
Yeah... I kept running into problems when trying to get my previous versions to switch familiars, without doing a "let's just shuffle through the list until we satisfy the conditions" or a "let's just skip over everyone except the xenomorph" scenario... I dare say it's not a bad effort for someone with more like 8 days worth of ASH scripting knowledge, huh? The script will evolve as I learn new tricks and stuff.
 

Theraze

Active member
Yep! The easiest way to do what you want without too much scripting fanciness is simply to move the familiar selector into a different function, as I did. Then return the familiar type that you want, and as soon as that happens, it won't keep trying anymore, because the function will have returned your familiar.

The single biggest problem with your original post, besides that it requires you to either switch to the fist turkey or not have farmed it up already, is that it does the server hit for changing familiars every time it runs through the list, even if the next familiar has already been farmed up fully. That means that if you don't remember if you accidentally switched away at some point and you manually swap it back to the fist turkey, it's 9 wasted hits to get back to the intergnat and figure out that you did really have all of your farming done already.
 

VladYvhuce

Member
Speaking of which... the "next" variable from "next = next_familiar();" came up as undefined. I added "familiar" in front of it, so it now reads "familiar next = next_familiar();" and now it works smoothly. Was that the right thing to put in front of "next"? Or is that something that may foul things up again?
 

Ethelred

Member
Yes, that will fix the problem. I'm an old school programmer who learned to always declare variables before they were used. That used to be required in older programming languages. Modern programming languages have relaxed this requirement in many cases and allow variables to be declared at first use. I cling to my old-fashioned ways and always declare my variables in a block at the beginning of a program or function, before any of the executable statements. I'm not sure what modern best practices would say about that, but it's served me well and makes it easier to see where and how things are defined, rather than having to poke around in the code to find them.
 
Last edited:

VladYvhuce

Member
Cool.
Nothing wrong with old-school style, so long as it works, in whatever one does. I grew up on a farm and learned that while new and flashy stuff may be prettier to look at, it may not stand up to abuse, and may be more of a pain in the butt to fix when it breaks down. I'm sure that to some extent, that applies to coding as well.
 

Theraze

Active member
Yep. I should have done it, but as I warned, never put the code through validation so that was all free-code. :)

Defining variables is (almost) always a good idea.
 

VladYvhuce

Member
I'll trim the list down tonight for a quick run-trough, to make sure the intergnat part works. Still not sure what to do about the ending error message, though... Try as he may, my intergnat just can't wear brass turkey knuckles. :rolleyes: I tried a version that was supposed to equip their corresponding equipments, but it just returns the same error message after automation is stopped (either manually, or by running out of adventures). I'm beginning to just wonder if that's a result of switching familiars during automation...
 

Theraze

Active member
Checkpoint clear MIGHT fix it. Mafia makes implicit outfit checkpoints on adventuring and when something changes your familiar or its gear during that - such as purchasing using the travoltan trousers or something similar - it switches your gear back. Unfortunately that causes issues when switching familiars. Fortunately it doesn't make things not work - just gives a little informative "Hey, I'm still working! Just wanted you to know!" message that you can safely ignore.

Alternatively, you could throw up a "clear" or "cls" to wipe the message off the screen if it really bugs you. :)
 

VladYvhuce

Member
Personally, I'll just be happy if the script works without breaking something important. That's the goal of the experiment. And quite honestly, Mafia turning red and tossing up an error message make me take notice more than it turning green at the end of adventuring, so I don't get too lazy about checking up on it.

I just figured that if the error message could be prevented, then that would make anyone else wanting to use it happier. I ran out of adventures last night, so I can't test the new modifications until tonight. I'll let you know what works and what doesn't.

If I can get rid of the error message, then I can figure out how to make a fake error show up that says their current familiar can't wear its own equipment, come next April... :D

EDIT: Put this at the front of the code. Fixed the error.
Code:
cli_execute("checkpoint clear");
 
Last edited:

Theraze

Active member
Yeah, as I said, clearing the implicit checkpoint should take care of it. Does mean that if any other non-familiar gear got changed, it might get abandoned wrong. But... eh, it's your script, for you, and you know if/when you want your gear changed up. Hopefully. :)
 

VladYvhuce

Member
I can't say that I'll run into a problem with automated gear changing any time in the foreseeable future. I use the gear changer to switch between outfits, or modify one outfit into a new one. And that's usually done before daily deeds and food/spleen consumption. And sometimes the maximizer for in-ronin rollover equipment. This is more of a script for me to run when I'm sick or tired or have to go help someone with something in the middle of the night, or just want Mafia to auto-farm for me while I watch a movie or something, than one to persistently keep as a BBB script forever. Case in point: Now that I've got it fixed, I actually disabled it so I could stick with an attacking familiar to get through the sewers. And I may want to stick with certain familiars while gathering hobo nickles... But for general item farming, it's a wonderful addition, in my book.
 

VladYvhuce

Member
Hey, y'all! I've decided to try and make a companion script for this one, if I can. My intention is to get it to switch familiars (both active and bjornified) when they hit max weight. My only real problem is that I don't know what to check for, there, or how to make one become bjornified through scripting. Any and all help would be appreciated.
 

Theraze

Active member
> ashref weight

int familiar_weight( familiar )
int weight_adjustment( )

> ashref throne

boolean enthrone_familiar( familiar )
familiar my_enthroned_familiar( )
Looks like you can use enthrone_familiar to do that. You can check your familiars weights, as well as the weight adjustment, to figure out when to shift them, so...
 

VladYvhuce

Member
I'm going to need more instruction on how to use that stuff. What my script doesn't say is invalid (which is most of what you posted), is somehow incompatible with my variables. So, now, I have a completely broken script that makes Mafia yell at me whenever I try to fix it... Thank goodness for backup copies.
 

Smelltastic

New member
I'm going to need more instruction on how to use that stuff. What my script doesn't say is invalid (which is most of what you posted), is somehow incompatible with my variables. So, now, I have a completely broken script that makes Mafia yell at me whenever I try to fix it... Thank goodness for backup copies.

What Theraze posted isn't code, it's the output of the CLI "ashref" command showing you what functions you're probably looking for. You can frequently take a guess or three at what words might be in the function you need and find it this way.

I don't know exactly what your logic is in choosing your familiars, but this should get you started.

Code:
if( familiar_weight( my_familiar() ) >= 20 ) {
  // Familiar choosing logic goes here
  use_familiar( chosenfamiliar );
}
if( familiar_weight( my_enthroned_familiar() ) >= 20 ) {
  // Familiar throne choosing logic goes here
  enthrone_familiar( chosenfamiliar );
}
 

VladYvhuce

Member
Ah. Shows what I know... I'll try it with the actual code, tonight.

For choosing familiars, I simply have a list of ones that I'd like to use. I'm also working up a secondary list for the bjornified familiars I like to use.

Now that I have a better idea of what I'm doing, it looks a lot less jumbled and confused in the code. So, hopefully, that'll translate into functionality.
 
Top