Small script for automating PVP fights

ElCarrot

New member
I was trying to automate my PVP fighting and I couldn't find any existing scripts for the new PVP fighting, and the old CLI commands didn't seem to work, so here's some basic code which will automate your PVP fighting for you.

Notes:
-The excise function comes from zlib so you will need to include that.
-The Announce function is just a simple function that makes the text pretty - you can replace it with "print"
-This code will do a random fight using moxie and will try to steal a flower. It should be fairly trivial to modify the URL as needed to suit your character.
-I hard-coded my character name for determining winning or losing because I was lazy.

Code:
// Find out how many PVP fights we have left
string pvpPage1 = visit_url("peevpee.php?place=fight");
matcher pvpMatcher = create_matcher("You have \\d+ fights remaining today.", pvpPage1);
// Are there PVP fights left
if (pvpMatcher.find()) {
	int numPVPFights = to_int(excise(pvpMatcher.group(0), "have ", " fight"));
	announce(2, "You have " + numPVPFights + " PVP Fights");
	for i from 1 to numPVPFights {
		string tmp6 = visit_url("peevpee.php?action=fight&place=fight&pwd=&ranked=1&stance=3&attacktype=flowers&winmessage=raaaaaaaaar&losemessage=meep");
		if (contains_text(tmp6, "<b>TheCarrot</b> won the fight")) {
			announce(2, "Won PVP Fight");
		} else {
			announce(2, "Lost PVP Fight");
		}
	}
} else {
	// No PVP fights left
	announce(2, "No PVP fights left");
}
announce(2, "Done PVP Fighting");

As I said before - this is quick and dirty - feel free to modify to suit.
 

slyz

Developer
If you (or a visitor from the future) is interested, there is a script, posted by Donavin here and expanded by the community (the community being mostly Bale in this case, I think).
 

Bale

Minion
My PvP script now looks like this:

PHP:
int MUSCLE_STANCE = 1;
int MYST_STANCE = 2;
int MOXIE_STANCE = 3;
int BALLYHOO_STANCE = 4;

int RANDOM_PERSON = 1;
int HARDER_PERSON = 2;

string HIT_FOR_FLOWERS = "flowers";
string HIT_FOR_FAME = "fame";
string HIT_FOR_LOOT = "lootwhatever";

void autoPvP(int fights) {
	int stance = BALLYHOO_STANCE;
	int ranked = RANDOM_PERSON;
	string attacktype = HIT_FOR_FLOWERS;
	
	string winMessage = "Have a Cheerio";
	string loseMessage = "OUch! I suck.";

	if(fights < 1) fights = 1;
	string color = "red";
	int startSwag = $coinmaster[The Swagger Shop].available_tokens;
	string result;
	try {
		for f from 1 to fights {
			print("Fight #"+f+ "......");
			string fight_res = visit_url("peevpee.php?action=fight&place=fight"
					  + "&attacktype=" + attacktype 
					  + "&ranked=" + ranked 
					  + "&stance=" + stance 
					  + "&who="
					  + "&losemessage=" + loseMessage
					  + "&winmessage=" + winMessage);
					  
			matcher names = create_matcher("<a href=\"showplayer\\.php\\?who=\\d+\"><b>([^<]+)</b></a> calls out <a href=\"showplayer\\.php\\?who=\\d+\"><b>([^<]+)</b></a> for battle!", fight_res);
			result = "";
			if(names.find())
				result = names.group(1) + " calls out " + names.group(2) + " for battle!";
			else print("no call-out found");
		
			matcher m = create_matcher("<b>([^<]+)</b> won the fight, <b>(\\d+)</b> to <b>(\\d+)</b>!", fight_res);
			if(m.find()) {
				result = result + " ... " + m.group(1) + " won the fight, " + m.group(2) + " to " + m.group(3);
				if(m.group(1) == my_name())
					color = "green";
				else color = "red";
			} else print("No result could be found");
			
			print(result, color);
		}
	} finally {
		int currentSwag = $coinmaster[The Swagger Shop].available_tokens;
		print("You just gained "+(currentSwag - startSwag)+" swagger. Total is now "+currentSwag+" swagger.", "blue");
	}
}

int count_fights() {
	string PeeVPee=visit_url("peevpee.php?place=fight");
	if(PeeVPee.contains_text("You must break your")) {
		print("You haven't chosen to PvP, I can't help you!", "blue");
	} else if(PeeVPee.contains_text("You're out of fights")) {
		print("You are out of fights, wait for rollover!", "red");
	} else {
		matcher PvPs = create_matcher("You have ([0-9,]+) fights remaining today", PeeVPee);
		if(find(PvPs)) {
			print("You have "+ PvPs.group(1) +" fights remaining today", "blue");
			return PvPs.group(1).to_int();
		}
	}
	return 0;
}

void autoPvP() {
	int fights = count_fights();
	if(fights > 0)
		autoPvP(fights);
}

void main(){
	autoPvP();
}

I prettied up the output a bit and added a readout of how much Swagger you gained while it was automating. I'll attach it here also, for the sake of those who like a simple download.
 

Attachments

  • PvP.ash
    2.6 KB · Views: 552
Last edited:

ElCarrot

New member
Apparently mine was outmoded before I even posted it. I don't know why Donavin69's script didn't show up in my searches (I searched "PVP" and several other variants - wierd.

Oh well - it was a fun exercise in coding.
 

lostcalpolydude

Developer
Staff member
The steal flowers|fame|ballyhoo [muscle|myst|moxie|ballyhoo] command currently works, as does flowers, for anyone that wants to burn fights and isn't concerned with pretty results.
 

Bale

Minion
I don't know why Donavin69's script didn't show up in my searches I searched "PVP" and several other variants.

Because the forum search function won't search terms with less than four letters. You can cheat it by searching for Pvp* which will find any word starting with the letters PvP or even the three letters by themselves.
 

Aramada

Member
Mafia newbie, not sure what the hell I'm doing question:

For Bale's PvP script, the default is currently set to attack Ballyhoo. I've got a couple of multis and while for a few ballyhoo works just fine, for one I'd like them to go with Muscle and another with Myst. Is there any way to set the preferences of what attack is used per character (that I can set and it will remember), or will i need to alter the script before I sign on each time?

~Aramada
 

lostcalpolydude

Developer
Staff member
Below "int stance = BALLYHOO_STANCE;" you could add
PHP:
if ( my_name() == "name1" ) stance = MUSCLE_STANCE;
and so on, for each character, filling in the appropriate name and stance.
 

Aramada

Member
Thank you Lost! That's perfect, and I'll do that.

One more question for you folks, and then I'll go back to reading: All of my characters have a custom outfit labeled PvP. Is there a way to put in the script to have Mafia equip the outfit before it starts the fights?

~Aramada
 

Ethelred

Member
Thank you Lost! That's perfect, and I'll do that.

One more question for you folks, and then I'll go back to reading: All of my characters have a custom outfit labeled PvP. Is there a way to put in the script to have Mafia equip the outfit before it starts the fights?

~Aramada

If you're using the version by Bale from post #3, you could add the following code around the autoPvP() call:


PHP:
void main(){ 
     cli_execute("outfit save Prev"); 
     cli_execute("outfit PvP");
     autoPvP(); 
     cli_execute("outfit Prev");
}

You can substitute any name you like for Prev. And all the usual warnings apply: I haven't actually executed that code and some typo or bug almost surely crept in while I was looking the other way, but that's a starting point you can use.
 
Last edited:

Theraze

Active member
There's actually also an outfit ash command... could just do outfit("PvP") instead of cli_execute("outfit PvP") if you wanted... but, eh. :)
 

Aramada

Member
Yet another "how to customize this" question about Bale's script.

For most of my accounts, I'm good with them going after flowers, which is what Bale's script defaults to. At least one, I'd like them to go for Phat Loot.

Keeping in mind what Lost told me about how to customize the stances, (adding "if ( my_name() == "name1" ) stance = MUSCLE_STANCE;" below "int stance = BallyHoo_Stance;" which works beautifully), I thought perhaps I could do something similar with what you are attacking for.

So, below "string attacktype = HIT_FOR_FLOWERS;" I tried putting "if ( my_name() == "name1" ) string attacktype = HIT_FOR_PHAT_LOOT;". Mafia politely asked me what the hell I had been smoking. I
tried "if ( my_name() == "name1" ) attacktype = HIT_FOR_PHAT_LOOT;". Mafia politely inquired if I shouldn't be leaving this to people who know what they are doing.

So, 1. what did I do wrong and 2. how can I get it to do what I'd like?

~Aramada
 

Theraze

Active member
Try shifting from Phat Loot to regular Loot. At least, Bale's script above doesn't mention phatness...
 

Aramada

Member
::rereads Bale's script::

::sees the line in it that says "string HIT_FOR_LOOT = "lootwhatever";"::

::facepalm::

Thank you, Theraze.

~Aramada
 
Bale, adding to your script, would this do what I think it would do?

Code:
void main(string num_fights){
        if ( num_fights == "all" ) {
                autoPvP();
        } else {
                autoPvP(num_fights.to_int());
        }
}
 

Bale

Minion
It would, but there's really no reason to bother with that script anymore. I certainly do not use it. There's now a CLI command to do the job:

pvp flowers ballyhoo — PvP for all available fights, to steal flowers using the ballyhoo stance.
pvp 15 loot muscle — PvP for 15 fights, attempting steal loot using the muscle stance.
 
Top