Check for and aquire trophies...

matt.chugg

Moderator
If anyone would like to test this, i'd appreciate it!

It should check, and (if aquiretrophies is true) aquire any and all trophies available, I only had one available to collect but if anyone ever has more than one i'd appreciate them testing this!

I think the regex pattern is "good" but regex is most definatly not my strong point!

Its part of a soon to be released pre-ascension script!

Code:
boolean aquiretrophies = true;

void checkandaquiretrophies() {
	print("Checking for trophies...","olive");
	string trophypage = visit_url("trophy.php");
	matcher trophymatcher = create_matcher("name\=whichtrophy.*?value\=(.*?)\>",trophypage);
	while (find(trophymatcher)){
		print("You are entitled to trophy " + group(trophymatcher,1),"red");
		if (aquiretrophies==true) {
			print("Purchasing trophy " + group(trophymatcher,1),"blue");
			if (my_meat() >= 10000) {
				string buytrophy=visit_url("trophy.php?action=buytrophy&whichtrophy="+group(trophymatcher,1),true);
			} else {
				print("Not enough meat","red");
			}
		}
	}
	if (aquiretrophies==true) {
		trophypage = visit_url("trophy.php");
		if (contains_text(trophypage,"entitled to the") == true) {
			print("Something may have gone wrong, there are still trophies to collect!");
		}
	}
}
 

Winterbay

Active member
My multi has several (have not bothered about them there) so I set out to test this. I saved the text above as trophy_get.ash and just to be safe did:
Code:
> verify trophy_get

void checkandaquiretrophies( )

Script verification complete.

Which seems good.

Edit: I am stupid. You need a main for it to do anything :)

Code:
> call trophy_get.ash

Checking for trophies...
You are entitled to trophy 4
You are entitled to trophy 39
You are entitled to trophy 45
You are entitled to trophy 47
You are entitled to trophy 63
You are entitled to trophy 74
You are entitled to trophy 75

Edit again:

Setting the variable to true instead (and putting my meat to 20k just for testing purposes):

Code:
> get_meat 20000

Removing meat from closet...
Returned: true

> trophy_get

Checking for trophies...
You are entitled to trophy 39
Purchasing trophy 39
Buying trophy #39 at the Trophy Hut
You are entitled to trophy 45
Purchasing trophy 45
Not enough meat
You are entitled to trophy 47
Purchasing trophy 47
Not enough meat
You are entitled to trophy 63
Purchasing trophy 63
Not enough meat
You are entitled to trophy 74
Purchasing trophy 74
Not enough meat
You are entitled to trophy 75
Purchasing trophy 75
Not enough meat
Something may have gone wrong, there are still trophies to collect!

It buys 1 trophy but Mafia somehow deducts 20k from my total (going to the relay browser confirms that three is indeed 10k left).

Trying again with 40k meat instead leads to Mafia buying 3 trophies before somehow losing track of the last 10k, but the purchasing of the trophies the script claims to have successfully bought is indeed performed.
 
Last edited:

matt.chugg

Moderator
Thanks Winterbay, thats perfect, i'm not sure quite whats happening with the meat though!

It is "acquire", not "aquire", FYI...

damn! I guess spelling isn't my strong point either!! updated in my file, and SEVERAL other instances in my scripts!

To anyone who edits the wiki, the above code may be a good example on the regex pages, as there arn't any and its flagged as needs code samples.
 
Top