Starfish Switch

CptJesus

Member
Starfish Switch 1.1

So I've been using Mafia for a while now, and I decided to try my hand at scripting. One thing that I was wishing for was for Mafia to automatically pull out my starfish when I got low on mana (more important now that I'm actually playing hardcore). So I decided to write a nice little script that would do it for me. This is my first mafia script ever. I tried to document all my functions and stuff, and I think I maintained proper programming style through most of it. I'll take any criticism and stuff I can get.

This script acts as a betweenBattleScript. After each battle, it will check your mana percentage against a user set variable. If your mana is below a certain percentage, it will pull out the best starfish type familiar you have based on weight and calculations taken from KoLWiki. It will then switch back to your original familiar when your mana crosses a threshold that once again is user specified. It's pretty much automatic for the most part. Now a large portion of the code, I have been completely unable to test, because I don't have any of the familiars. However, the code works perfectly fine for the base Starfish familiar. I would love to get some feedback from people who actually have access to the different type of starfish familiars. If any of the veteran coders around here want to take a look at my code and give me some pointers, that would rock too. So to recap:

  • Starfish Switch will automatically handle your starfish switching needs.
  • The script will take into account adventuring under the sea.
  • The script supports all the pure starfish type familiars.

To use the script:
  • Download StarfishSwitch.ash to your scripts directory.
  • Get ZLib if you don't have it already
  • Open mafia and type set betweenBattleScript = StarfishSwitch.ash into the gCLI
  • Get out your preferred familiar and start adventuring

Variables that can and should be changed:
  • ss_enabled - Enables and disables the script completely.
  • ss_starfishmin - The mana percentage at which to pull out your starfish
  • ss_starfishmax - The mana percentage at which to put away your starfish
  • You must pick only one of the below three options!!! Do not more than one at the same time!
  • ss_useggg - Use gluttonous green ghost.
  • ss_usespirithobo - Use spirit hobo.
  • ss_useslimeling - Use slimeling.

Changelog:
  • 2/16/2010: 1.0 - First Release
  • 2/16/2010: 1.1 - The real first release because the first one was broken. Added some new features too! Now detects familiar changes better and takes them into account

PS: If this goes in another section, please feel free to move it. This was just the best one I could think of >.<
 

Attachments

  • StarfishSwitch.ash
    6.8 KB · Views: 91
Last edited:

slyz

Developer
Nice script!

Just one little thing:
Code:
//The current familiar we are using
setvar("ss_currentfamiliar",my_familiar());
familiar ss_currentfamiliar = to_familiar(vars["ss_currentfamiliar"]);

setvar only defines the default zlib setting for a variable (it returns without changing the variable if it already exists), so ss_currentfamiliar will always be set to the familiar the user was using when he ran StarfishSwitch for the first time.

You should just do
Code:
familiar ss_currentstarfish = my_familiar();
without using a zlib setting.
 

CptJesus

Member
Nice script!

Just one little thing:
Code:
//The current familiar we are using
setvar("ss_currentfamiliar",my_familiar());
familiar ss_currentfamiliar = to_familiar(vars["ss_currentfamiliar"]);

setvar only defines the default zlib setting for a variable (it returns without changing the variable if it already exists), so ss_currentfamiliar will always be set to the familiar the user was using when he ran StarfishSwitch for the first time.

You should just do
Code:
familiar ss_currentstarfish = my_familiar();
without using a zlib setting.


Actually, in the main loop, it redefines ss_currentfamiliar again.

Code:
if ((my_mp()*100 / my_maxmp() < ss_starfishmin)){
	print("Mana is below switch percentage. Switching to Starfish");
	ss_currentfamiliar=my_familiar();
	use_familiar(star);
	return true;
}

So every time your mana goes below the threshold, ss_currentfamiliar is redesignated to make sure that it keeps up with your current choices.

However, you're right, using a zlib setting is a bit overkill. I'll remove it in the next version.
 

slyz

Developer
Oh sorry, I missed that. Actually, you should leave it in and change that part to:
Code:
if ((my_mp()*100 / my_maxmp() < ss_starfishmin)){
	print("Mana is below switch percentage. Switching to Starfish");
	ss_currentfamiliar=my_familiar();
        cli_execute("zlib ss_currentfamiliar = "+ss_currentfamiliar);
	use_familiar(star);
	return true;
}
so that you switch back to the previous familiar when your MP is more than ss_starfishmax.
 

CptJesus

Member
Oh sorry, I missed that. Actually, you should leave it in and change that part to:
Code:
if ((my_mp()*100 / my_maxmp() < ss_starfishmin)){
	print("Mana is below switch percentage. Switching to Starfish");
	ss_currentfamiliar=my_familiar();
        cli_execute("zlib ss_currentfamiliar = "+ss_currentfamiliar);
	use_familiar(star);
	return true;
}
so that you switch back to the previous familiar when your MP is more than ss_starfishmax.

It already does go back to your previous familiar

Code:
if ((my_mp()*100 / my_maxmp() > ss_starfishmax) && switched == true){
	print("Mana is above switch percentage. Going back");
	use_familiar(ss_currentfamiliar);
	ss_switched = false;
	return true;
}

That's code from my updated version, but the original version has something similar anyways. I'm working on a few more refinements to make it a bit better. Eventually, I'm going to add support for Cocoabo type familiars as an option. They're not as effective for pure MP gain, but it's an alternative, and honestly, its pretty fun to code.

Also, why do you need to use the cli execute? The Zlib variable should update without a cli execute command in there, right?

Just a clarification on the algorithm that picks the starfish.

I calculate the buffed weight for each different familiar, and then I plug those weights into the equations provided on the KoL Wiki. Using that, I get the average between the min and max mana regen, and then multiplying the average by the frequency at which the familiar acts. This does take into account adventuring in the sea as well, so if you start adventuring there for whatever reason, it will switch to your best sea familiar on the fly (new version). My math might be off a bit though. I think it should be reasonably accurate. The problem obviously as I mentioned before is that I have absolutely no way to test the other starfish familiars, so I can't ascertain what the deal is with those.
 
Last edited:

slyz

Developer
It's a betweenBattle script, you need to save ss_currentfamiliar somewhere for the script to switch back next time it runs and your MP is full.

The lines I pointed out in post #2 never update the zlib variable, they only set the default (maybe it would be a good idea to have an empty string as default).

I proposed a cli_execute because it only takes only one line, otherwise you would have to do:
Code:
familiar ss_currentfamiliar=my_familiar();
vars["ss_currentfamiliar"] = ss_currentfamiliar.to_string();
updatevars();
which is just as good.
 

CptJesus

Member
It's a betweenBattle script, you need to save ss_currentfamiliar somewhere for the script to switch back next time it runs and your MP is full.

The lines I pointed out in post #2 never update the zlib variable, they only set the default (maybe it would be a good idea to have an empty string as default).

I proposed a cli_execute because it only takes only one line, otherwise you would have to do:
Code:
familiar ss_currentfamiliar=my_familiar();
vars["ss_currentfamiliar"] = ss_currentfamiliar.to_string();
updatevars();
which is just as good.

Ah...interesting. I was under the impression that

Code:
ss_currentfamiliar = my_familiar()

would also update the corresponding zlib variable.

I'll make changes accordingly
 

CptJesus

Member
Edit: Updated the first post. It should be all shiny and working now!

Thanks a lot for the help slyz!

Just a few details as to the changes:

I made all the variables properly update the way they're supposed too. I also added a check to see if the familiar was switched while in the mana restoring phase. If it is, it will change ss_currentfamiliar to that familiar. This will allow you to change your familiar choice sort of in between. Also, the script will now properly check to see if there is a better starfish familiar you should be using currently. It'll switch to the best starfish available if there is a better one. For example, if you are using a Star Starfish and have a Midget Clownfish available, and you start adventuring in the sea. Assuming both familiars are equal weight, the Clownfish will be switched in as it is superior in the Sea. Also cleaned up a bit of the code here and there.
 
Last edited:

Allucaneet

New member
Can this script "recognize" the Rogue Program? It seems that when I get low on MP, it switches to a Star Starfish, even if it has a 1-lb base wt, wherein I have a heavier Rogue Program.


P.S. Woah. The last post in this thread dates back to a time when RP does not yet exist.
This works great with a slimeling. :D It's a good script.
 

Theraze

Active member
If you want to use RP instead of SS, just replace those parts of the script... should probably work fine for that.
 
Top