number of zaps

ki77bot

Member
I was wondering, if there is a function, which lets you check, if you have already used a wand to zap something?

Cheers,
ki77bot.
 

Bale

Minion
There is no such function, but zarqon once wrote an amazing bit of code which I have adapted to my own purposes. Here you go:

Code:
boolean zappp(item whatsit) {
   if (item_amount(whatsit) == 0) return false;
   cli_execute("zap 1 "+whatsit);
   return true;
}

void daily_zap() {
	print("Looking to zap...");
	int whichwand = 0;
	for i from 1268 to 1272
		if(item_amount(to_item(i)) > 0) whichwand = i;
	switch {
	case whichwand == 0:
		print("You don't have a wand.", "olive");
		break;
	case contains_text(visit_url("wand.php?whichwand="+whichwand),"feels warm"):
		print("Already zapped today. Afraid of Kabloo-ey!", "red");
		break;
	case zappp($item[green-frosted astral cupcake]):
	case zappp($item[orange-frosted astral cupcake]):
	case zappp($item[purple-frosted astral cupcake]):
	case zappp($item[33398 scroll]):
	case zappp($item[ring of aggravate]):
		break;
	default:
		print("You have nothing more to zap.", "olive");
	}
}
Since the cases stop executing once one of them is true, it will only zap one item.
 
Last edited:

mredge73

Member
In summary this is how I use it to check if the wand has been used yet:
Add these two functions to your script:
(I created them borrowing portions of Zarqon's script a while back)
Code:
//Find Wand
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
int FindWand()
{
	int wand=0;
	for i from 1268 to 1272
	{ 
		if (haveItem(to_item(i)))
			wand = i;
	}
	return wand;
}

//checks if the wand was used today
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
boolean WandUseable(int wand)
{
	if (wand==0)
		return false;
	if (contains_text(visit_url("wand.php?whichwand="+wand),"feels warm")) 
		return false;
	else
		return true;
}

To use:

boolean FreshWand = WandUseable(FindWand());
 

matt.chugg

Moderator
purly for extra variety, heres the one I wrote, not that I really use it much!

Code:
// -1   No wand found in inventory
//  0   wand hasn't been used at all
//  1   feels warm to the touch (level 1)
//  2   You should probably be careful. (level 2)
//  3   You should definitely be careful. (level 3)
//  4	You should seriously be careful.  (level4)
//  5   should never be seen in visit_url, because I think at this point the wand is gone

int wandstatus() {
	int whichwand=0;
	int retstatus;

  	for i from 1268 to 1272 {
		if (item_amount(to_item(i)) > 0) whichwand = i;
	}
      	
	if (whichwand == 0) {
		retstatus = -1;
	} else {
		// we have a wand so can't be -1 preset to 0 then if its still 0
		// after below checks then it really should be zero.
		// does ash have elseif ?

		retstatus = 0;
		string wanddescription = visit_url("wand.php?whichwand="+whichwand);
		
		if (contains_text(wanddescription, "feels warm")) {
			retstatus = 1;
		} 
		
		if (contains_text(wanddescription, "probably be careful")) {
			retstatus = 2;
		}
		
		if (contains_text(wanddescription, "definitely be careful")) {
			retstatus = 3;
		}

		if (contains_text(wanddescription, "seriously be careful")) {
			retstatus = 4;
		}
	}
	return retstatus;
}
 

ki77bot

Member
Thanks for all your replies...

I am using a breakfast script, that sometimes breaks , if the 'Ode to Booze' is not cast fast enough. Needless to mention, that the script also zaps. In case the script breaks, I do not want to risk losing the wand. With this variety of solutions, I should be able to do that.

Again, thanks a lot...

Cheers,
ki77bot.
 

Bale

Minion
If Ode to Booze is a problem, try this subroutine:

Code:
// shot = 1 for first shot of Ode, or shot = 2 for second shot as a nightcap.
boolean get_ode(int shot) {
	if(have_effect($effect[Ode To Booze]) < 1) {
		if(have_skill($skill[The Ode To Booze])) {
			if(my_mp()< mp_cost($skill[The Ode To Booze])) {
				restore_mp(mp_cost($skill[The Ode To Booze]));
				if(my_mp()< mp_cost($skill[The Ode To Booze]))
					abort("Can't cast Ode to Booze due to lack of MP!");
			}
			use_skill(1, $skill[The Ode To Booze]);
			if(have_effect($effect[Ode To Booze]) >= 1)
				return true;
			else 
				return false;
		} else {
			// lets try to get it from a buffbot
			print("purchasing Ode to Booze from a few buffbots...", "blue");
			if(shot == 1) {
				cli_execute("csend 1 meat to Testudinata");
				cli_execute("csend 23 meat to Iocainebot");
			} else {
				cli_execute("csend 11 meat to Testudinata");
				cli_execute("csend 80 meat to Iocainebot");
			}
			int iterations = 0;
			while( have_effect($effect[Ode to Booze]) < 1) {
				if (iterations > (30)) {
					print("failed to get Ode to Booze", "red");
					return false;
				}
				cli_execute("wait 30");
				cli_execute("effects refresh");
				iterations = iterations + 1;
			}
		}
	} 
	return true;
}
 
Last edited:

ki77bot

Member
Perfect, that was exactly what I was looking for.

I tried to solve it like this, but was not quite satisfied:

Code:
		if(have_effect($effect["ode to booze"]) > 0){
		print("Yes, your favorite song 'Ode to Booze' has been played for you.", "green");
	} else {
		print("Need to get 'Ode to Booze' (testudinata @ 1 meat)", "red");
		cli_execute("csend 1 meat to testudinata");
		wait(10);
		cli_execute("status refresh");
	}

	int i = 0;
	while( (have_effect($effect["ode to booze"]) <= 0) && i < 4 )
	{
	    i = i + 1;
		wait(30);
		cli_execute("status refresh");
		print("...waiting 30 seconds for buff...");
	}

	if(have_effect($effect["ode to booze"]) > 0){
		print("Yes, your favorite song 'Ode to Booze' has been played for you.", "green");
	} else {
		abort("Well, something didn't work there with your buffbot. Get 'Ode to Booze'!");
	}

Cheers,
ki77bot.
 

Bale

Minion
Ooh Bale, I am stealing that switch() mod to my zapping script. Nice.
Glad you liked it. When I looked at the HUGE if() command in your script I thought... that could be a lot prettier to look at. :D And of course I'm a huge fan of switch to the point that sometimes I over-use it. ;)

I've already thanked you for the basic work that I merely tinkered with.
 

matt.chugg

Moderator
And of course I'm a huge fan of switch to the point that sometimes I over-use it. ;)

Massive tangent, but I know what you mean, i'm actually a .net programmer as part of my job (the other part involves removing the shredded remains of a sheet of A4 after a printer jam), I often use the switch or the vb equivalent of select case for code with only 3 options, just because I prefer it a whole lot to elseif!, plus, it makes future expansion a whole lot easier!

seriously, thats the best ever thread hijack i've ever pulled off! :p
 
Last edited:

zarqon

Well-known member
I'm sure there are quite a few places in my scripts that could yet be optimized by switching to the switch() statement -- most of them were written before switch() existed and I haven't taken the time to fix what's not broken.

I'm very glad that the compiler now recognizes when the switch statement is guaranteed to return. For a while after the introduction of switch() you also needed a return statement outside the switch statement, even if you had a default: return. That often disinclined me to use switch(), but now that's fixed, I'll see about incorporating it more.

Also, the word "switch" starts to look really funny if you keep looking at it.
 

Bale

Minion
Also, the word "switch" starts to look really funny if you keep looking at it.
Speaking of which, have you thought about improving your scripts with the salad() function? I've noticed that virtually every function in my recovery script should be replaced with salad(). I tried that, but strangely I cannot get it to work quite right yet. Once I've managed it, v3.0 will be 100% salad().
 
Top