The Neo-Cow Farming Script

slyz

Developer
1) You could avoid a LOT of server hits by hitting bhh.php only once in NCF Bountyhunting.ash. Simply add
PHP:
string bhh = visit_url("bhh.php");
at the beginning of the script, and replace all the visit_url() that are only used to gather info by "bhh".

2) If you know which items you need, and how many you need, you can just subtract item_amount() from the total number.
 

Theraze

Active member
2) If you know which items you need, and how many you need, you can just subtract item_amount() from the total number.

Also, using CLI_EXECUTE("condition set 40 coal button") instead of CLI_EXECUTE("condition add 40 coal button") or add_item_condition(40, $item[coal button]) means that it will only add as many as you need, counting current inventory. Easier than doing add_item_condition(40-item_amount($item[coal button]), $item[coal button]).
 

Banana Lord

Member
I'll look at number 1 and Theraze's suggestion after I've released 1.5.3, which I'll after I get this putty logic improvement sorted. My problem is number 2. How do I work out how many bounty items I need?
 

Banana Lord

Member
So this would work?
PHP:
import <NCF Bountyhunting.ash>
if(item_amount(currentBounty.bountyTarget) - item_amount(currentBounty) == 1)
	blah don't use putty blah;
 

icon315

Member
So this would work?
PHP:
import <NCF Bountyhunting.ash>
if(item_amount(currentBounty.bountyTarget) - item_amount(currentBounty) == 1)
	blah don't use putty blah;
Would it have to equal 2? If you kill the monster you get 1 then the monster from the putty will get you another
 

Theraze

Active member
I'd set it to < 2 instead, in case mafia has a KoL update hiccup and you somehow end up with having them all but starting another combat, and inventory doesn't update until after it's too late... Don't want it to putty with 0 bounty items remaining.
 

Banana Lord

Member
Would it have to equal 2? If you kill the monster you get 1 then the monster from the putty will get you another
The point is that the consult script won't use putty in a combat with only one bounty item remaining to find because that final item will drop at the end of the current combat.

Thanks for the tip Theraze!
 

slyz

Developer
Gah, I lost my connection while answering and lost my post. New, shorter reply:
So this would work?
PHP:
import <NCF Bountyhunting.ash>
if(item_amount(currentBounty.bountyTarget) - item_amount(currentBounty) == 1)
	blah don't use putty blah;
Nope, this won't work. First, currentBounty isn't defined (simply importing NCF Bountyhunting.ash isn't enough). Also, currentBounty.bountyTarget is an int, there's no reason to apply item_amount() to it.
PHP:
import <NCF Bountyhunting.ash>
BountyInfo currentBounty = find_BHH_object( get_property( "currentBountyItem" ).to_item() );
if( currentBounty.bountyTarget - item_amount( currentBounty.bountyItem ) < 2 )
	blah don't use putty blah;

If you do this, you might want to remove the visit_url( "bhh.php" ) you planned on adding from the top level of NCF Bountyhunting.ash. You could instead make it happen in bountyhunt() and pass the resulting string to the other functions.
 
Last edited:

Banana Lord

Member
This is where NCF Combat - Bountyhunt is at now. I've added a couple of minor bits and pieces, but I can't test it until after rollover. Can you see anything obviously wrong?
PHP:
import <Zlib.ash>
import <NCF Bountyhunting.ash> 
boolean USE_PUTTY = to_boolean(vars["neocowfarm_puttybounty"]);
BountyInfo currentBounty = find_BHH_object( get_property( "currentBountyItem" ).to_item() ); 

void main( int round, string opponent, string text ) 
	{    
    buffer mac;  // macro in progress   

    string macro(string mac) // ASH function for submitting a macro   
    	{  
		// Uncomment these when bug testing
#		print( mac ); 
#		print( "" ); 
#		print( url_encode(mac) );
         
        return visit_url("fight.php?action=macro&macrotext="+url_encode(mac), true, true);   
    	}

	// We want to pickpocket regardless of what we're fighting
	mac.append( 'pickpocket; ');
	
	// Use spooky putty if advisable
	if(USE_PUTTY)
		{
		if(get_property("spookyPuttyCopiesMade") != "5") // Check for available putties
			{ 
			if(item_amount($item[spooky putty monster]) == 1)
				abort("You have a spooky putty monster, use it!");
			if(item_amount($item[spooky putty sheet]) == 0) // Make sure you have a putty sheet
				abort("No putty!"); // don't even hit the server for your abort situation
			if( item_drops(opponent.to_monster()) contains get_property("currentBountyItem").to_item() && currentBounty.bountyTarget - item_amount(currentBounty.bountyItem) > 1 ) 
 ) // Only use putty if the monster drops your current bounty item
				mac.append( 'use spooky putty sheet; ' );
				else
				print("That monster doesn't drop your bounty item so putty was not used", "blue");
			}
			else
			print("You're out of putties for today so spooky putty was not used", "blue");
		}
		else
		print("You have opted not to use putty to speed up bounty hunting", "blue");
	
	// Olfact the monster if you can, and if it drops your bounty item
	if(item_drops(opponent.to_monster()) contains get_property("currentBountyItem").to_item() ) // Only olfact if the monster drops your current bounty item
		{
		if(have_skill($skill[transcendent olfaction]))
			mac.append( 'skill transcendent olfaction; ' );
		}
		else
		print("That monster doesn't drop your bounty item so it was not olfacted", "blue");

	// Finish the fight
	mac.append( 'while !pastround 25; attack; endwhile;' );

    // Finally, submit the macro   
    macro(mac); 
	}
 

slyz

Developer
PHP:
if(item_amount($item[spooky putty monster]) == 1)
         abort("You have a spooky putty monster, use it!");
This bit might cause problem when you are fighting putty monsters. I think you can safely remove it.
PHP:
if(item_amount($item[spooky putty sheet]) == 0) // Make sure you have a putty sheet
         abort("No putty!"); // don't even hit the server for your abort situation
Why abort instead of simply carrying on? Add the check for a putty sheet/monster in the script that uses NCF Combat - Bountyhunt.ash to manage the fights instead.
 

Banana Lord

Member
This bit might cause problem when you are fighting putty monsters. I think you can safely remove it.
The abort is performed before the macro is executed or not at all so it should be fine shouldn't it?
EDIT: Oh you mean if the script is interrupted after puttying and then restarted during the same combat? Hmm. I'll think on it. I put it there in case the script failed to clear your putty before bountyhunting due to unforeseen error.

Why abort instead of simply carrying on?
Because to reach that condition the user must have specified that they wanted to use spooky putty while bountyhunting, have putties available for that day, and not have a monster in their putty. If after all of that the script finds that the user has no spooky putty sheet available for use in combat then something has gone wrong and the user's attention is required. That was my rationale anyway, is it flawed?
EDIT2: I see your point about adding it to the script that uses NCF Combat - Bountyhunt.ash , but to me it seemed safer and more intuitive to put it there.
EDIT3: Besides, if I move it to NCF Bountyhunting.ash then I have to put it in several places since the combat script is set multiple times (or define a function to handle doing both, but again that's extra complexity). Then again it would be better to not even go into the fight without putty. Argh.
 
Last edited:

slyz

Developer
I just thought the check could be made before adventuring. If the user wants to use a putty sheet, but doesn't have one (or another putty item, or a putty monster), carry on without bothering him =)

Re. the putty monster, I seem to remember that, when you use the putty monster in Mafia, you start the fight and Mafia still thinks you have a putty monster in your inventory. This would cause an abort. Maybe I am wrong or this has been corrected a long time ago.
 

Banana Lord

Member
You ninja'd my edits! :)

Surely the best of both worlds is to include it in both places? xD

Re. the putty monster
Well that's easy to check. I'll run the script after rollover and if it blows up in my face we'll know the bug's still there!
 

Banana Lord

Member
OK, thanks. It's always good to have more than one person test :)

PHP:
import <Zlib.ash>
import <NCF Bountyhunting.ash> 
boolean USE_PUTTY = to_boolean(vars["neocowfarm_puttybounty"]);
BountyInfo currentBounty = find_BHH_object( get_property( "currentBountyItem" ).to_item() ); 

void main( int round, string opponent, string text ) 
	{    
    buffer mac;  // macro in progress   

    string macro(string mac) // ASH function for submitting a macro   
    	{  
		// Uncomment these when bug testing
#		print( mac ); 
#		print( "" ); 
#		print( url_encode(mac) );
         
        return visit_url("fight.php?action=macro&macrotext="+url_encode(mac), true, true);   
    	}

	// We want to pickpocket regardless of what we're fighting
	mac.append( 'pickpocket; ');
	
	// Use spooky putty if advisable
	if(USE_PUTTY)
		{
		if(get_property("spookyPuttyCopiesMade") != "5") // Check for available putties
			{
			if(item_amount($item[spooky putty sheet]) == 0) // Make sure you have a putty sheet
				abort("No putty!"); // don't even hit the server for your abort situation
			if(item_drops(opponent.to_monster()) contains get_property("currentBountyItem").to_item() && currentBounty.bountyTarget - item_amount(currentBounty.bountyItem) > 1 )
				mac.append( 'use spooky putty sheet; ' );
				else
				print("That monster doesn't drop your bounty item so putty was not used", "blue");
			}
			else
			print("You're out of putties for today so spooky putty was not used", "blue");
		}
		else
		print("You have opted not to use putty to speed up bounty hunting", "blue");
	
	// Olfact the monster if you can, and if it drops your bounty item
	if(item_drops(opponent.to_monster()) contains get_property("currentBountyItem").to_item() ) // Only olfact if the monster drops your current bounty item
		{
		if(have_skill($skill[transcendent olfaction]))
			mac.append( 'skill transcendent olfaction; ' );
		}
		else
		print("That monster doesn't drop your bounty item so it was not olfacted", "blue");

	// Finish the fight
	mac.append( 'while !pastround 25; attack; endwhile;' );

    // Finally, submit the macro   
    macro(mac); 
	}
 
Top