What is wrong with visit_url?

wonko

New member
I'm attempting to write a barrels script to run in my daily scripted runs to do the boring daily stuff.

visit_url is giving me grief however.

This code:
Code:
  string barrelitem;
  barrelitem = visit_url("barrel.php?smash=1");
  print(barrelitem);

Gives me this output:
Code:
[5249] Barrel Full of Barrels
<html><head>
<script language=Javascript>
<!--
if (parent.frames.length == 0) location.href="main.html";
top.charpane.location.href="charpane.php";
//-->
</script>
<script language=Javascript src="[url]http://images.kingdomofloathing.com/scripts/window.js"></script>[/url]
<link rel="stylesheet" type="text/css" href="[url]http://images.kingdomofloathing.com/styles.css">[/url]
</head>

<body>

Oh, wait, I think I get it now. Didn't catch that dangling body tag there before. I'm exceeding the string size aren't I?

Well, that doesn't work well. Is there a way to get around that?

EDIT: the code block has eaten my output!! It shows up when I go to edit it, what gives? Do I need to tell it something other than code to not eat html?

EDIT2: Huh, now it shows up. Whatever.

EDIT3: Oh yeah, it doesn't actually "consume" the barrel either, which I think is a bit odd. So maybe it's something else?
 

macman104

Member
visit_url is working fine for me. What I would suggest is to open up the minibrowser and visit the barrel you want to smash, and make sure the url that the minibrowser displays it visited is the same as what you are using.

Also, if you want to see the url that the visit_url is retrieving, before you run the script, turn on debugging (type "debug on" into the gCLI), then run the script, then turn off debugging ("debug off"), then go look at the debug text, and it will show what visit_url visited and what the function returned.
 

wonko

New member
Ah ha! Thanks for the tip!

it turns out I needed a &pwd appended to that url.

It works great now, thanks!
 

wonko

New member
Crap, new problem. Since I'm using visit_url() when I get a mimic, it doesn't fight it. Now I need to figure out how to get it to fight if that's what I find.

Ideas?

-brian
 

dangerpin

Member
Maybe something like

Code:
if(contains_text(url, "Combat")) run_combat();

or

Code:
if(contains_text(url, "mimic")) run_combat();


You could also switch autoattack off and on which might help for that first combat.
 

hippymon

Member
All the results of visiting the url/barrel will be shown in the gCLI and under the session results in the adventure frame/tab..
 

wonko

New member
That's where I got the inspiration to get the returned items from combat. I'd rather not use his as mine is already written, I just need to figure out this last piece. This is a learning experience as much as it is a chance to write a useful tool. The more I know, the more useful my scripts will become. :)
 

izchak

Member
I was browsing through the mafia source the other day, as it is the best place to discover undocumented ASH features, and I stumbled across this in KoLmafiaASH.java .
Code:
		public ScriptValue item_drops()
		{
			Monster monster = FightRequest.getLastMonster();
			List data = monster == null ? new ArrayList() : monster.getItems();

			ScriptMap value = new ScriptMap( RESULT_TYPE );
			AdventureResult result;

			for ( int i = 0; i < data.size(); ++i )
			{
				result = (AdventureResult) data.get(i);
				value.aset( parseItemValue( result.getName() ), parseIntValue( String.valueOf( result.getCount() ) ) );
			}

			return value;
		}

		public ScriptValue item_drops( ScriptVariable arg )
		{
			Monster monster = (Monster) arg.rawValue();
			List data = monster == null ? new ArrayList() : monster.getItems();

			ScriptMap value = new ScriptMap( RESULT_TYPE );
			AdventureResult result;

			for ( int i = 0; i < data.size(); ++i )
			{
				result = (AdventureResult) data.get(i);
				value.aset( parseItemValue( result.getName() ), parseIntValue( String.valueOf( result.getCount() ) ) );
			}

			return value;
		}

Now, my Java knowledge is pretty poor, but this *seems* to be designed to return a list of items the monster could drop. If you dont specify a monster, it uses the last encountered monster, it seems.

However, I couldn't get it to return me a list of items, I could only get it to return a single integer, which was always zero (in the limited amount of tests I ran in the castle, anyway).
This is the scriptlet I used to test it, and its output:

Code:
#item [int] drops;
int drops;
monster mob = to_monster("Raver Giant");
print("item drops for " + to_string(mob));
drops = item_drops(mob);
#drops = item_drops();
print(drops);

#foreach i in drops {
#	print(i + " : " + drops[i]);
#}
and its output
> call test.ash

item drops for Raver Giant
0

Is this function broken, incomplete, or (quite possibly), am I using it in completely the wrong way?
 

hippymon

Member
Well, I typed in gCLI "ashref drops" and got this:
int item_drops( )
int item_drops( monster )
This tells me that this function only returns the amount of items dropped..... :p
 
Top