Combat Script - Cast Spell if you have enough MP

SeiferTim

New member
It took some time to figure out the "consult" command, but I came up with a very neat script that runs when I'm adventuring.
It checks if I have enough MP to cast a specific skill (thrust-smack, for my Seal clubber), and if I do casts it, otherwise, if I have at least one Mountain Stream soda, I drink one, if I'm out of soda, I attack.

Code:
void main(int iRound, monster eek, string sText){
	if ( my_mp() >= mp_cost( $skill[thrust-smack] ) ) {
		print("MP sufficient... casting skill.");
		use_skill( $skill[thrust-smack] );
	} else {
		print("MP insufficient... trying to recover MP...");
		if (item_amount( $item[Mountain Stream soda] ) > 0 ) {
			print("Drinking a soda...");
			throw_item( $item[Mountain Stream soda] );
		} else {
			print("No soda, attacking");
			attack();
		}
	}
	return;
}

In order for this to work, save the script in your "Scripts" folder as something.ash, then edit your custom combat script to say:
Code:
[ default ]
1: consult something.ash
Where "something" is whatever you want it to be.

There may be more advanced, and neater ways to do this, comments/suggestions welcome.
 

SeiferTim

New member
Updated my during combat script to heal me:
This is what I use for my Hardcore Pastamancer
Code:
void main(int iRound, monster eek, string sText){
	if ( my_hp() < my_hp() * 0.30 ) {
		print("Ouch!");
		if ( my_mp() >= mp_cost( $skill[Lasagna Bandages] ) ) {
			print("Bandaging...");
			use_skill( $skill[Lasagna Bandages] );
		} else {
			print("MP insufficient... trying to recover MP...");
			if (item_amount( $item[magical mystery juice] ) > 0 ) {
				print("Drinking a juice...");
				throw_item( $item[magical mystery juice] );
			} else {
				print("No juice, attacking");
				attack();
			}
		}
	} else {
		if ( my_mp() >= mp_cost( $skill[minor ray of something] ) ) {
			print("MP sufficient... casting skill.");
			use_skill( $skill[minor ray of something] );
		} else {
			print("MP insufficient... trying to recover MP...");
			if (item_amount( $item[magical mystery juice] ) > 0 ) {
				print("Drinking a juice...");
				throw_item( $item[magical mystery juice] );
			} else {
				print("No juice, attacking");
				attack();
			}
		}
	}
	return;
}

It helps to have an in-between combat script that purchases juice when your out.
 

Darkness

New member
Thanks for posting that, its good to have a simple script to see how to make consult scripts.

Is there anyway to determine if you have fired bottle-rockets in the current combat? I tried have_skill() but it seems that mafia still thinks you have the skill even once the game takes the drop-down option away. I guess I could use set/get_property to record data between combat rounds, but I just wondered if there was a more efficient way.
 

izchak

Member
For my combat script to be able to handle 'once per combat' things like bottle rockets, I wound up having the script loop until the entire combat is over, instead of having the script be called anew every round of combat. This makes the script a little trickier, as you have to remember to increment the round counter, and reload the html data, but that isn't really difficult. It would go something like this:
Code:
void main(int ROUND, monster MOB, string PAGEDATA) {
	# entangling noodles
	boolean noodled = false;
	# bottle rockets fired so far
	int rocketCount = 0;
	repeat {
		if(!noodled && have_skill($skill[entangling noodles])) {
			PAGEDATA = use_skill($skill[entangling noodles]);
			noodled = true;
		} else if((rocketCount == 0) && have_equipped($item[bottle-rocket crossbow])) {
			PAGEDATA = use_skill($skill[orange rocket]);
			rocketCount = rocketCount + 1;
		} else {
			PAGEDATA = attack();
		}
		ROUND = ROUND + 1;
	} until(
		# general win/loss messages
		contains_text(pageString, "You win the fight!") ||
		contains_text(pageString, "You lose the fight!") ||
		contains_text(pageString, "You run away, like a sissy little coward") || 
		#contains_text(pageString, "") ||
		# TODO: find the text for beating the man
		# this is specific to the wisniewski fight
		contains_text(pageString, "You stare open-mouthed at the carnage that used to be the hippy camp")
		#contains_text(pageString, "") 
}

A real combat script could do a lot more besides (firing multiple rockets, checking for enough MP, perhaps some more 'end of combat' strings, and stuff), but thats sufficient to demonstrate handling the looping inside your script, instead of having the script get called afresh every round of combat. I recall fightOptimizer.ash also did the looping.
 

Darkness

New member
Ah that's a much better way of handling once per combat things.

I have thought of a way to handle use of padl phones (or communications wind chimes) also. The problem with these is they can only be used every 6 combats or so, the spading still needed for exact numbers.
So an adventuring script could decide if use of a padl phone is safe and change the active combat script set from one that doesn't use the PADL phones to one that does.
Assuming there is a command (like mood) to change the current ccs

This would help to avoid using get/set_property which I imagine are fairly inefficient.
 

Guzkal

New member
Code:
void main(){
	if ( my_mp() > mp_cost( $skill[moxious maneuver] )+30 ) {
		print("MP is sufficient... Moxious Maneuver time!!");
		use_skill( $skill[moxious maneuver] );
	} else 
		{
			print("Don't have enough reserve MP. Time for plan B!!");
			attack();
			
		}
	return;
}

Thank you SeiferTim for your base for my custom combat script (I use it on my level 13 Accordion Thief)

I use it in coherts with the 'mood' settings in KoL mafia to allow me to have enough MP to cast my buffs (30) and also burn off any other MP with MOXIOUS MANEUVERS!

PS: I removed the gibberish after void main*. but now that I think about it does it have any importance or was that just you forgetting to remove it from someone elses example :p
 
Top