Using items in combat, ash script

Hello, I recently came across Illarion's Stasis script on the hardcore oxygenation boards, and I've started to tinker with it a bit for my own use. I'm running a new HC character, and don't have all the skills required to fully use that one (ie no noodles, no big damage finisher). This will explain why I want to do what i want to do!

I'm starting to learn how to write ash scripts - they look a bit similar to the C programming i learned a year ago. But one thing i haven't been able to figure out, is how to use an item in a combat round using ash. For example, I'd like to use a seal tooth for my "do nothing" round in stasis. Should I just add in the following function to do so?

Code:
string UseSealTooth()
{
  print("Using Seal Tooth");
  return visit_url( "fight.php?action=item&whichitem=2");
}

This isn't working, so how can I correct this line?
 
I haven't done anything with this, but I did create a wiki page that might be helpful to you. http://wiki.kolmafia.us/?page_id=51

My guess would be you want:
Code:
string UseSealTooth()
{
   print("Using Seal Tooth");
   return throw_item($item[Seal Tooth]);
}

Again I will state that this is not my area, and I only created that wiki page because I am trying to bring the wiki up to date as a function reference.
 

degrassi

New member
This may be an easier way for most uses:
http://kolmafia.sourceforge.net/combat.html

It allows you to map out the rounds based on areas and/or monster. Even without going into the consult part of (allowing all sorts of customization, as the previous reply's link hints to) it allows quite a bit of straightforward customization. It doesn't have the precision of the consult script, but if you want something like "use a seal tooth for X rounds" it works pretty well.
 
I tried looking up that page in the wiki first, but I have no idea how to use the functions defined. When I tried using the bit of code you wrote, i get an error "too many arguments supplied"....so that doesn't seem to work. Also, I don't want to just use the custom combat even though it is a great way to use X item Y times, since i want to nest this inside a previously written script that heals MP.

No script I've found on this site has this ability to use items in combat. Use skills, attack, those are all covered. But I'm stumped when it comes to finding out how to use items properly.
 

macman104

Member
There's a function I believe called consult(), I'm not exactly sure though unfortunately. I think that is used in order to direct mafia to use a previously written script, where those functions can be used. If no one answers, I'll see if I can scrounge up some more info for you about it.
 
I analyzed kolmafia's source for new functions. No consult().

Now my theory is...edit: from here on....ah hell, I just googled the stasis script the OP mentioned, and managed to track it down.
I quote Illarion here
To use:
- save the script with a .ash extension in your Mafia scripts directory. I call it ASHStasis.ash
[size=14pt]- edit your custom combat to have this entry:
Code:
[ default ]
1: consult ASHStasis.ash[/size]


(this will try and stasis vs *everything*, simply turn off custom combat or revert back once you get beyond your stasis zone).

- ensure your combat option is set to "custom combat script"
- adventure away. I'd make sure you have sufficient mp for at least a couple of noodles

OK so to simplify:
The entry point into your script is
void main(int iRound, monster eek, string sText)
where "eek" is the monster you are fighting, "iRound" is the current round number in the battle, and "sText" is the current html response. I assume you can name the variables anything, but probably must have the same type and order. Study what Illarion did. Come to understand what he/she did. Learn from what he/she did. Tear apart what He/She did. Follow the file as if you were kolmafia executing the actions. Write your battle handling script from there. Then add the consult line as indicated above, or on an individual monster basis.
 
Thanks for the rundown of that script - I understood basically the same when I read through it. I have my custom combat set properly to consult that script, and have it running as written properly. I know this isn't the hardcore oxygenation forums, so I won't be asking too much about that particular script - I more brought it up to explain why I'd want to add a "use item" in combat to an ash script instead of using the very simple custom combat in mafia. Illarion's script makes a lot of sense, and I'll enjoy tearing through it to learn how to make something like it myself.

What I don't know, is how to use the in-combat functions that aren't explained at all in the wiki. So I'm asking for help here, seems like the natural place to start. A basic script such as
Code:
int main(){
   throw_item( $item[spices] );
return 0;
}

doesn't do anything, even once i have it running by adding
Code:
[ default ]
1: consult myscript.ash
to my custom combat settings. My real question is how to get such a narrow function to work in an ash script - once it does, i'll be able to incorporate it into a more detailed script - such as Illarion's.

EDIT: thanks for the mod edit, in adding that funky code formatting.
 

macman104

Member
Well, if you could elaborate on "doesn't do anything" that would help. open up the gCLI and see what it's printing, and such, check your sessions log, see what that says. Anyway, I've got no experience with Consult, but I messed around a little with it.
Code:
void main(int iRound, monster eek, string sText)
{
String grab;
print("Round " + iRound);
item razor = $item[seal tooth];
grab = throw_item(razor);
return;
}
Before I added the parameters to main, I kept getting a too many parameters error each round. Now, in my sessions log it says every round, "Soandso throws a SEAL TOOTH" or whatever, each round, however, it doesn't actually seem to be doing that. It's possible we either a) still don't know how to use this function properly, or b) the function does not function properly, or c) something else here.

However, seeing as it is Winter/Holiday break, or whatever you want to call it, both Veracity and Holatuwol I believe are involved with Winter/Holiday break type-stuff, so it may be a little while until this gets addressed (if it's option b, that is, or if no one comes around to explain it).
 
try this:
over-ride throw_item:

Code:
string throw_item(item tothrow)
{
return visit_url("fight.php?action=item&whichitem=" + item_to_int(tothrow));
}
test, does it work now? if so you've got a kolmafia malfunction. post details please.
If not, post details, and we can dig further.
btw
Code:
int main(){
   throw_item( $item[spices] );
return 0;
}
should throw an error

Code:
void main(int iRound, monster eek, string sText)
{
throw_item( $item[spices] );
}
should not
 
Thanks for the quick replies. When I use the code
Code:
int main(){
   throw_item( $item[spices] );
return 0;
}
i get an error " ')' Expected at line 2 in file scripts\item.ash " in the graphic CLI.

I tested out the bits of code that efilnikufecin showed. I first overrided the throw_item function as shown, on a multi of mine. When I use the int main() version of the code, I get "Too many arguments supplied Script aborted!" every round. When I use the void main(int iround....) the CLI gets filled with combat information. By that I mean, it prints out the text that would be displayed in the browser, as well as every combat item and skill I can use that round.

I tried that same test to all the code supplied here, without over-riding the throw_item function. I get the exact same result. Note in a few of the cases, my turn is skipped and the monster attacks again. Not what I was trying to accomplish, but that would be useful to certain stasis-type people.

Then I tried testing out macman's code. While the round does display properly, and the script is accepted by mafia, the items aren't used. I'm fighting bunnies with no +ML, to get consistency. And they survived 8 rounds of seal toothing. So no dice there. And this multi is stocked with plenty of seal teeth, spices, and turtle summoning scrolls.

Any other tips?
 

Nightmist

Member
Hey I decided to start work on my item usage section of my adventure-override script and incase you people didn't actually check the HTML of the fight page and got the URL's based on some other source. You people DO realise its "action=useitem" right? Not just "action=item".

Although this only applies if your using direct URL's instead of throw_item.

Edit: I just tested a direct URL to use spices in battle against a rabbit in the warren in 9.9. It worked.
 

macman104

Member
[quote author=quantumnightmare link=topic=666.msg3129#msg3129 date=1167367303]
Thanks for the quick replies. When I use the code
Code:
int main(){
   throw_item( $item[spices] );
return 0;
}
i get an error " ')' Expected at line 2 in file scripts\item.ash " in the graphic CLI.[/quote]Which you should
I tested out the bits of code that efilnikufecin showed. I first overrided the throw_item function as shown, on a multi of mine. When I use the int main() version of the code, I get "Too many arguments supplied Script aborted!"
Again, this should happen, stop using int main()
When I use the void main(int iround....) the CLI gets filled with combat information. By that I mean, it prints out the text that would be displayed in the browser, as well as every combat item and skill I can use that round.
Ok...even though it's reporting stuff, is it doing anything?
Then I tried testing out macman's code. While the round does display properly, and the script is accepted by mafia, the items aren't used. I'm fighting bunnies with no +ML, to get consistency. And they survived 8 rounds of seal toothing. So no dice there. And this multi is stocked with plenty of seal teeth, spices, and turtle summoning scrolls.
Yup, that's exactly what I reported happens. That code wasn't meant for you to try out, I know what happens, but to help in debugging the issue.

Anyway....

Efilnikufecin, I tried out overriding the code for throw_item, and it succeeded.
Code:
string throw_item(item tothrow)
{
print("Overridden");
return visit_url("fight.php?action=useitem&whichitem=" + item_to_int(tothrow));
}

void main(int iRound, monster eek, string sText)
{
String grab;
print("Round " + iRound);
item razor = $item[seal tooth];
grab = throw_item(razor);
return;
When in the dire warren, prints:
Visit to Mountain: The Dire Warren in progress...
Encounter: fluffy bunny
Round 1
Overridden
You gain 8 Meat
You gain 6 Strongness
Script succeeded!

So..I guess that means it's an issue with the throw_item function in mafia, right?
*Goes digging in mafia*, yup, in KoLmafiaASH.java, we have
Code:
		public ScriptValue throw_item( ScriptVariable item )
		{
			KoLRequest request = new KoLRequest( "fight.php?action=item&whichitem=" + item.intValue() );
			request.run();
			return new ScriptValue( request.responseText == null ? "" : request.responseText );
		}
Which according to nightmist, and my test makes sense that it doesn't do anything, because the action value is incorrect. *Goes off to report on dev forum*. Thanks for helping debug everyone.

Quantum, so until a new version of mafia is released, or until it's fixed and you download a daily build, add the throw_item function that I posted at the top of your script (you can take out the print("overridden") part. You should be able to normally use the throw_item function then. Note, that if you want to throw two items, you'll need to also have the throw_items function which is
Code:
string throw_items(item tothrow1, item tothrow2)
{
return visit_url("fight.php?action=useitem&whichitem=" + item_to_int(tothrow) +
                             "&whichitem2=" + item_to_int(tothrow2));
}
*I broke that up into two lines, just to not break the frames, it should be all together without all those spaces (if you copy-pasted it).
 
I was certain that the url being used was valid...so certain in fact that I have to wonder if it changed at some point explaining why so many people wound up making the exact same mistake?

answer: I highly doubt it now
sorceresslair.java contains:
// Parse response to see which item we need.
AdventureResult guardianItem = getGuardianItem( QUEST_HANDLER.responseText );

// With the guardian item retrieved, check to see if you have
// the item, and if so, use it and report success. Otherwise,
// run away and report failure.

QUEST_HANDLER.constructURLString( "fight.php" );

if ( inventory.contains( guardianItem ) )
{
QUEST_HANDLER.addFormField( "action", "useitem" );
QUEST_HANDLER.addFormField( "whichitem", String.valueOf( guardianItem.getItemId() ) );
QUEST_HANDLER.run();

return -1;
}
which proves that it was known to Holatuwol that fight.php requires "useitem" instead of "item". So when the functions for consult adventuring were written a simple mistake was made...but how the heck did we manage to duplicate the same mistake? BTW no I didn't check the url myself, I just used the one previously mentioned in this thread.
 

macman104

Member
[quote author=quantumnightmare link=topic=666.msg3139#msg3139 date=1167437918]Great! I used macman's override of the throw_item function, and it works just fine now.[/quote]Well, it was really efilnikufecin's override of the function, so the thanks goes to him. And now quantum, when you get a new release you'll be able to simply delete the over-riding function that's at the top, and you won't have to change your functions names or anything.
 
[quote author=macman104 link=topic=666.msg3140#msg3140 date=1167442893]
Well, it was really efilnikufecin's override of the function, so the thanks goes to him. And now quantum, when you get a new release you'll be able to simply delete the over-riding function that's at the top, and you won't have to change your functions names or anything.
[/quote]
Actually the thanks goes to Nightmist for noticing that we was using the wrong url my function was useless without that aspect. The thanks also goes to you macman104 for posting the fixed version.
 
Top