There must be a better way!

Banana Lord

Member
I know there must be a better way of doing this, but I'm not really sure what I'm doing.
Code:
if(my_primestat() == $stat[muscle])
	{
	if(item_amount($item[corpsedriver]) == 0)
		{
		if(my_inebriety() < 6)
			take_storage(2, $item[corpsedriver]);
		if(my_inebriety() > 5 && my_inebriety() < 15)
			take_storage(1, $item[corpsedriver]);
		}
	if(item_amount($item[corpsedriver]) == 1 && my_inebriety() < 6)
		take_storage(1, $item[corpsedriver]);
	}
		
if(my_primestat() == $stat[mysticality])
	{
	if(item_amount($item[corpse on the beach]) == 0)
		{
		if(my_inebriety() < 6)
			take_storage(2, $item[corpse on the beach]);
		if(my_inebriety() > 5 && my_inebriety() < 15)
			take_storage(1, $item[corpse on the beach]);
		}
	if(item_amount($item[corpse on the beach]) == 1 && my_inebriety() < 6)
		take_storage(1, $item[corpse on the beach]);
	}
		
if(my_primestat()== $stat[moxie])
	{
	if(item_amount($item[corpsetini]) == 0)
		{
		if(my_inebriety() < 6)
			take_storage(2, $item[corpsetini]);
		if(my_inebriety() > 5 && my_inebriety() < 15)
			take_storage(1, $item[corpsetini]);
		}
	if(item_amount($item[corpsetini]) == 1 && my_inebriety() < 6)
		take_storage(1, $item[corpsetini]);
	}
 
There are a few things you could do to improve this, yes.
First, instead of three identical code blocks, use one with an item variable.
Start with:
Code:
item corpseDrink;
switch (my_primestat()) {
 case $stat[muscle]:
  corpseDrink=$item[corpsedriver];
  break;
 case $stat[mysticality]:
  corpseDrink=$item[corpse on the beach];
  break;
 case $stat[moxie]:
  corpseDrink=$item[corpsetini];
  break;
}
As for the actual grab code, there are a few ways to simplify that. Here's one:
Code:
 int roomLeft=0;
 if (my_inebriety()<15) roomLeft+=1;
 if (my_inebriety()<6) roomLeft+=1;
 while (item_amount(corpseDrink)<roomLeft)
  take_storage(1, corpseDrink);

EDIT: careful with that while loop though. If there aren't any left in storage it will simply keep trying forever.
 
As for the actual grab code, there are a few ways to simplify that. Here's one:
Code:
 int roomLeft=0;
 if (my_inebriety()<15) roomLeft+=1;
 if (my_inebriety()<6) roomLeft+=1;
 while (item_amount(corpseDrink)<roomLeft)
  take_storage(1, corpseDrink);

I can simplify that with the power of MATH! And improve it in two other ways at the same time...

PHP:
take_storage(min((inebriety_limit() - my_inebriety()) /6, storage_amount()), corpseDrink);

Note that my version will check to see if you have liver of steel and won't try to get anything from storage that you lack. (I was assuming that your character wants enough corpse drinks to not get drunk.)
 
Last edited:
(I was assuming that your character wants enough corpse drinks to not get drunk.)

This makes way more sense.

My numbers were taken straight from his source. I wasn't thinking in terms of 20 drunkenness so I assumed it was enough to -overdrink- with. His numbers still don't quite make sense for this though (<15 would mean 14, and 14+6 would put you at 20, which is bad mmmkay; likewise <6 would mean 5, and 5+12 is 17... so I'm not really sure what he was going for)
 
Thanks!

My diet is actually drink one, keep one for nightcap, and make up the remainder with improved swill, pumpkin juice, and whatever else I can find. I don't bother with liver. I just like to get as many of my pulls out of the way as I can.
 
Back
Top