Visit VIP Pool Table

My first (admittedly simple) contribution to the scripting community. Any thoughts would be greatly appreciated!

Update: old crappy code removed. Here's what it looks like now:

Code:
boolean play_pool(int stance) 
{
	// VIP Pool Script by Greenrider
	//
	// Arguments: int stance
	//	1 = Billiard Belligerence (+50% weapon damange, +5 familiar weight)
	//	2 = Mental A-Cue-Ity (+50% spell damage, +10MP recovery per adventure)
	//  3 = Hustlin' (+50% initiative, +10% item drops)
	// Actions: attempts to play pool using given stance
	// Returns: TRUE if pool visit appears to have worked, FALSE otherwise
	//
	if(stance < 1 || stance > 3)
		return false;
	return contains_text(visit_url("clan_viplounge.php?action=pooltable&preaction=poolgame&stance=" + stance),"You acquire an effect");
}

boolean table_exists()
{
	// Arguments: none
	// Actions: none
	// Returns: TRUE if character has VIP pool table, FALSE otherwise

	return contains_text(visit_url("clan_viplounge.php?action=pooltable"),"pool table");
}

void main (int stance)
{
	play_pool(stance);
	return;
}
 

Attachments

  • VIPPool.ash
    884 bytes · Views: 90
Last edited:

matt.chugg

Moderator
you already have stance, why not craft the url including it? then no need for the if statement!

Code:
void play_pool(int stance) {
	visit_url("clan_viplounge.php?action=pooltable&preaction=poolgame&stance=" + stance);
}

refactored FTW!

also you could make it return something useful!

Code:
boolean play_pool(int stance) {
	return contains_text(visit_url("clan_viplounge.php?action=pooltable&preaction=poolgame&stance=" + stance),"positive response string")
}

where positive response string should be replaced with something in the text to indicated it was successful. possibbly "you aquire an effect"
 
Last edited:
Thanks! That's incredibly helpful. Having that IF block in there was just stupidity on my part, and everything else you mentioned makes a lot of sense.

I parsed the HTML returned by the pool attempt, and "You acquire an effect" does seem like a good string to search for to determine success or failure. Here's the new version, basically identical to what you suggested:

Code:
boolean play_pool(int stance) 
{
	// VIP Pool Script by Greenrider
	//
	// Arguments: int stance
	//	1 = Billiard Belligerence (+50% weapon damange, +5 familiar weight)
	//	2 = Mental A-Cue-Ity (+50% spell damage, +10MP recovery per adventure)
	//      3 = Hustlin' (+50% initiative, +10% item drops)
	// Actions: attempts to play pool using given stance
	// Returns: TRUE if pool visit appears to have worked, FALSE otherwise
	//
	return contains_text(visit_url("clan_viplounge.php?action=pooltable&preaction=poolgame&stance=" + stance),"You acquire an effect");
}
 

Rinn

Developer
You might want to make sure the int that is passed in is between 1 and 3 as well since that was removed when you stopped using the switch.
 
Last edited:
Updated the script to allow for direct calls from the CLI (a la "vippool 1", for example) as well as people importing it to be able to call play_pool() from their farming scripts.

table_exists() is a utility function that lets you check whether or not a character has access to a table.
 
Last edited:
My version tells you the results of the match.

Code:
void pool(int stance) {
    string result, clannie;
    int clan1, clan2;
    result = visit_url("clan_viplounge.php?preaction=poolgame&stance="+stance);
    if(contains_text(result, "You skillfully defeat")) {
        clan1=index_of(result, "defeat")+7;
        clan2=index_of(result, " and take");
        clannie = substring(result, clan1, clan2);
        print("You beat "+clannie+" at pool!");
        }
    else if(contains_text(result, "unable to defeat")) {
        clan1=index_of(result, "defeat")+7;
        clan2=index_of(result, "Ah well")-3;
        clannie = substring(result, clan1, clan2);
        print(clannie+" beat you at pool!");
        }
    else if(contains_text(result, "against yourself")) print("You played a game of pool with yourself!");
    else if(contains_text(result, "play again tomorrow") || contains_text(result, "hands in your pockets")) print("You've played enough pool for one day.", "red");
    else print("WTF!?","red");
// that should never happen
}
 

Bale

Minion
Nice. However, since I don't like having to remember what acceptable arguments are for my scripts I built in a little more ability to understand what I mean.

Code:
// VIP Pool Script by Greenrider & shademaster00 (with Bale)

// Arguments: string stance
//	1 = Billiard Belligerence (+50% weapon damage, +5 familiar weight)
//	2 = Mental A-Cue-Ity (+50% spell damage, +10MP recovery per adventure)
//	3 = Hustlin' (+50% initiative, +10% item drops)

boolean table_exists() {
	return contains_text(visit_url("clan_viplounge.php?action=pooltable"), "pool table");
}

// Returns true if pool is played. This might mater if it was called by another script.
boolean play_pool(int stance) {
	string result, clannie;
	result = visit_url("clan_viplounge.php?preaction=poolgame&stance="+stance);
	if(contains_text(result, "You skillfully defeat")) {
		clannie = substring(result, index_of(result, "defeat")+7, index_of(result, " and take"));
		print("You beat "+clannie+" at pool!", "green");
	} else if(contains_text(result, "unable to defeat")) {
		clannie = substring(result, index_of(result, "defeat")+7, index_of(result, "Ah well")-3);
		print(clannie+" beat you at pool!", "#002080");
	}
	else if(contains_text(result, "against yourself"))
		print("You played a game of pool with yourself!", "#002080");
	return true;
	if(contains_text(result, "play again tomorrow") || contains_text(result, "hands in your pockets"))
		print("You've played enough pool for one day.", "red");
	else print("WTF!?","red"); 		// that should never happen
	return false;
}

void main(string choice) {
	if(table_exists()) {
		int stance;
		choice = choice.to_lower_case();
		
		switch{
		case choice.contains_text("1"):
		case choice.contains_text("bil"):
		case choice.contains_text("bel"):
		case choice.contains_text("fam"):
		case choice.contains_text("weap"):
			stance = 1;
			break;
		case choice.contains_text("2"):
		case choice.contains_text("mental"):
		case choice.contains_text("cue"):
		case choice.contains_text("mp"):
		case choice.contains_text("spell"):
			stance = 2;
			break;
		case choice.contains_text("3"):
		case choice.contains_text("hustl"):
		case choice.contains_text("item"):
		case choice.contains_text("init"):
			stance = 3;
			break;
		default:
			abort("Bad argument. Pool stance is unknown!");
		}
		
		play_pool(stance);
	} else print("No pool table. Try a clan that knows how to treat its VIPs.", "red");
}

I saved that as pool.ash and I'll be able to play pool from that command line now. :D
 
Last edited:

Bale

Minion
Edited a few little touch-ups into my previous post. Nothing important.

Collaborative script writings are pretty fun.
 
Top