Hobopolis chatbot script

Grotfang

Developer
Hobopolis chatbot script - New Problem (29th July)

Building on Alhifar's cagebot script, I tried to see if it was possible to create a chatbot for hobopolis. This was done mainly because my clan is looking to get into hobopolis runs soon and being in the UK I find it hard to be online when required.

Anyways, I managed to get the script to the point when on command it will go through the sewers and then use sufficient phials of the correct type to kill a pre-determined number of hobos. However, its behaviour with the tent is causing problems. Long story short, expected behaviour is for it to CLEESH to the tent on command ("tent") and then I want it to sit there (call the url but not actually do anything). On command ("play") it should enter the tent in the back and then sit there, and on command ("leave") it should leave the tent and then sit there, ready to go back to the tent on command.

What is actually happening is that first time through it got to the tent and then kept on calling the url until it got the play command, when it played correctly and then kept calling the url until getting the leave command, when it left. On subsequent "tent" commands it would CLEESH to the tent, and then would play and leave immediately. I'm not sure why it is doing this - maybe because looking so long at the code is stopping me from seeing obvious (or not so obvious) errors, but help would be much appreciated!

Verifying it in the gCLI produced no errors.

Code:
string run_choice( string page_text )
{
	matcher m_choice = create_matcher( "whichchoice value=(\\d+)" , page_text );
	while( contains_text( page_text , "choice.php" ) )
	{
		m_choice.reset( page_text );
		m_choice.find();
		string choice_adv_num = m_choice.group( 1 );
		
		string choice_adv_prop = "choiceAdventure" + choice_adv_num;
		string choice_num = get_property( choice_adv_prop );
		
		if( choice_num == "" ) abort( "Unsupported Choice Adventure!" );
		
		string url = "choice.php?pwd&whichchoice=" + choice_adv_num + "&option=" + choice_num;
		page_text = visit_url( url );
	}
	if( contains_text( page_text , "Combat" )) run_combat();
	return page_text;
}

void main( string sender , string message )
{
	buffer reply;
	if( contains_text( visit_url( "clan_detailedroster.php" ) , sender ) )
	{
		buffer quote;
		if( contains_text( message.to_lower_case() , "sewer" ) )
		{
			#Stuff I know works in the sewer and in hobopolis.
		}
					
		if( contains_text( message.to_lower_case() , "tent" ) )
		{			
			cli_execute ( "ccs sewer" );
			
			outfit( "tent" );
			
			string page_text = visit_url( "adventure.php?snarfblat=167" );
			
			int at_the_tent = 0;
			
			while( !contains_text( page_text , "Attention -- A Tent!" ) && at_the_tent < 1 )
			{
				if( contains_text( page_text , "Combat" ) )
				{
					run_combat();
				}
				else if( contains_text( page_text , "Marketplace Entrance" ) )
				{
					page_text = run_choice( page_text );
				}
				#Things to heal me if needed and boost non-combats
				if (at_the_tent < 1) {page_text = visit_url( "adventure.php?snarfblat=167" );}
			}
			if( contains_text( page_text , "Attention -- A Tent!" ) )
			{
				chat_reply( "at the tent");
				at_the_tent = 1;
			}
		}
	}
	
	if( contains_text( message.to_lower_case() , "play" ) )
	{
		set_property( "choiceAdventure225" , "1" );
		string page_text = visit_url( "adventure.php?snarfblat=167" );
		if( contains_text( page_text , "Attention -- A Tent!" ) )
		{
			page_text = run_choice( page_text );
			chat_reply( "playing" );
		}
		else
		{
			chat_reply( "not able to play" );
		}
	}
	
	if( contains_text( message.to_lower_case() , "leave" ) )
	{
		set_property( "choiceAdventure226" , "2" );
		string page_text = visit_url( "adventure.php?snarfblat=167" );
		if( contains_text( page_text , "Here You Are, Up On Stage" ) )
		{
			page_text = run_choice( page_text );
			chat_reply( "left" );
		}
		else
		{
			chat_reply( "can't leave!" );
		}
	}
	
}
 
Last edited:

mredge73

Member
it is playing and leaving automatically after the first visit because you need to reset your properties back to default (0) after executing the command.

Now as for the loop is concerned, be careful how you test it. Do not test your chatbot with your chatbot. In other words do not have the chatbot /msg itself unless you have extra coding in there to catch the chat_replys and void them out.
For example if I would:
/msg myself tent

the chatbot will recieve
tent
tent
at the tent
at the tent
at the tent
at the tent
ect...

everytime it sees the word tent it will execute the loop again.
 
Last edited:

Grotfang

Developer
Hey guys. One final problem I'm struggling with. When I use my play command, it correctly chooses the right choice from the Attention -- A Tent! choice adventure to get on stage, but then perpetually bombards the CLI with the adventure Here You Are, Up On Stage.

Now, I have tried debugging it and I think the problem is in Alhifar's run_choice method. The play command is:

Code:
if( contains_text( message.to_lower_case() , "play" ) && sender == desired_operator )
	
	{
		print( "Given the command play by " + sender , "blue" );
		set_property( "choiceAdventure225" , "1" );
		
		string page_text = visit_url( "adventure.php?snarfblat=167" );
		if( contains_text( page_text , "Attention -- A Tent!" ) )
		{	
			page_text = run_choice( page_text );
			chat_reply( "playing" );
			print( "Playing on stage" , "blue" );
			set_property( "choiceAdventure225" , "0" );
		}
		else
		{
			chat_reply( "not able to" );
			print( "Not able to play" , "red" );
			set_property( "choiceAdventure225" , "0" );
		}
	}

The run_choice part is:

Code:
string run_choice( string page_text )
{
	matcher m_choice = create_matcher( "whichchoice value=(\\d+)" , page_text );

	while( contains_text( page_text , "choice.php" ) )
	{
		m_choice.reset( page_text );
		m_choice.find();
		string choice_adv_num = m_choice.group( 1 );
		
		string choice_adv_prop = "choiceAdventure" + choice_adv_num;
		string choice_num = get_property( choice_adv_prop );
		
		if( choice_num == "" ) abort( "Unsupported Choice Adventure!" );
		
		string url = "choice.php?pwd&whichchoice=" + choice_adv_num + "&option=" + choice_num;

		page_text = visit_url( url );
	}
	
	if( contains_text( page_text , "Combat" )) run_combat();
	return page_text;
}

The part I think is failing is the final

Code:
page_text = visit_url( url );

The reason I think this is because when I set debug to true and print successive numbers throughout, the line it should print after that is not printed. In fact, it gets printed on the beginning of the first spammed line (a line that shouldn't be appearing).

This is really frustrating me, as I have no idea why it isn't getting this. Using get choiceAdventure225 and 226 returns the figures it should, so it isn't because the adventure is unsupported.

Does anyone have any idea?
 

mredge73

Member
it is because you are hitting two choice adventures in a row

run_choice is designed to only do one, you will have to build a new run_choice subroutine that does not include the while() loop


This can be substituted (not tested) or you can build your own.
run_choice(page_text, true); --use this if you are have more than one choice in a row, like the gallery or the one you are experiencing

run_choice(page_text,false); --runs like normal, checks to see if the choice was completed before moving on

Code:
string run_choice( string page_text, boolean RunOnlyOnce )
{
    matcher m_choice = create_matcher( "whichchoice value=(\\d+)" , page_text );
boolean stop=false;
    while( contains_text( page_text , "choice.php" ) && !stop)
    {
        m_choice.reset( page_text );
        m_choice.find();
        string choice_adv_num = m_choice.group( 1 );
        
        string choice_adv_prop = "choiceAdventure" + choice_adv_num;
        string choice_num = get_property( choice_adv_prop );
        
        if( choice_num == "" ) abort( "Unsupported Choice Adventure!" );
        
        string url = "choice.php?pwd&whichchoice=" + choice_adv_num + "&option=" + choice_num;
page_text = visit_url( url );
if (RunOnlyOnce)
stop=true;

    }
    
    if( contains_text( page_text , "Combat" )) run_combat();
    return page_text;
}
 
Last edited:

Alhifar

Member
Actually, that definitely accounts for multi-stage choice adventures. That's why it includes "while( contains_text( page_text , "choice.php" )"

Make sure you have your choice adventures set to valid, useful options.

EDIT: Actually, that's not the latest version. It doesn't take into account the possibility of an adventure that is to be shown in the mini-browser. While that may or may not be your problem, the version I'm currently using is as follows:
Code:
string run_choice( string page_text )
{
	matcher m_choice = create_matcher( "whichchoice value=(\\d+)" , page_text );

	while( contains_text( page_text , "choice.php" ) )
	{
		m_choice.reset( page_text );
		m_choice.find();
		string choice_adv_num = m_choice.group( 1 );
		
		string choice_adv_prop = "choiceAdventure" + choice_adv_num;
		string choice_num = get_property( choice_adv_prop );
		
		if( choice_num == "" ) abort( "Unsupported Choice Adventure!" );
		if( choice_num == "0" ) abort( "Manual control requested for choice #" + choice_adv_num );
		
		string url = "choice.php?pwd&whichchoice=" + choice_adv_num + "&option=" + choice_num;

		page_text = visit_url( url );
	}
	
	if( contains_text( page_text , "Combat" ) ) run_combat();
	return page_text;
}
 
Last edited:

mredge73

Member
Make sure you have your choice adventures set to valid, useful options.

This is what is not set properly, I think.
If you want to take the first choice and then just sit and wait for the next command without it repeating forever you will need to get rid of the while loop. If you want to do both of them back to back then the original one is fine.

Question for Alhifar
On your new run_choice, when the script aborts will it abort the chatbot or will the chatbot remain ready for new commands and just abort the while loop. If it just aborts the while then the new one that you posted should be fine.
 
Last edited:

Grotfang

Developer
I know the choices are set correctly, as in my debugging I got it to print those settings continuously. Therefore it isn't that it is unsupported. It might well be that the choice adventure 226 (Here You Are, Up On Stage) would be set to 0 at that stage. I will give your addition a try, Alhifar, thanks!

As for abort(), in chatbots it should stop the current actions, but not abort the chatbot itself. In my experience, a chatbot aborted will still act on subsequent commands.
 
Top