CCS/Macro in consult script

Banana Lord

Member
A while back I wrote a huge macro that handles 99% of all combats I could ever run into. For the remaining 1% I need a consult script to figure out what to do, but as I've already spent a huge amount of time bug testing my macro I'd like to preserve as much of it as possible. Is there a way of including CCS/macro code in a consult script (perhaps similar to the way in which cli commands can be executed by an ash script)?
 

Winterbay

Active member
You can submit a macro via the consult script. Spamattack does that and I've managed to modify that to be slightly more advanced than it was. It should be doable to actually have it generate the same macro that you otherwise used and have it do something else for the 1% of fights that are not handled by that macro.
 

Banana Lord

Member
As Winterbay says, I'm essentially trying to submit a combat macro/(standard) CCS-style action via a consult script. Ash lets me find out how many times I've used my putty in a day, whether I'm farming with my hobo monkey rather than completing the nuns, and other such things. As an example:
Code:
if(get_property("spookyPuttyCopiesMade") != "5" && monstername lobsterfrogman)
	call puttyfrogman

sub puttyfrogman
    if !hascombatitem spooky putty sheet
        "abort" "No Putty!"
    endif
    use spooky putty sheet
    while !pastround 25 && !hpbelow 30
        skill shieldbutt
    endwhile
    "abort" "Too many rounds!"
endsub

Except, as you can see, I have no idea how to integrate my macro into a consult script. Can I use monstername as a condition? If not what do I use instead? Can I call a sub in the way I've tried to above? Do I need to put anything other than abort in quotes? Is there another way of telling what round it currently is (assuming I can't use pastround)? Could I simply use an ash if expression to determine what needs to be done then submit the appropriate subroutine via the purely imaginary command submit_macro(string subname);?
 
Last edited:

StDoodle

Minion
You need something like this:
Code:
visit_url("fight.php?action=macro&macrotext=" + url_encode(macro_string) ,true,true);
With "macro_string" being your combat macro as a string (use either ";" or "\n" for new-lines). You can use other functions to build your macro using any ash functions, including having "sub" sections (which of course must also be part of the string).
 

Banana Lord

Member
Fantastic! I *think* I understand. I realise it's a bit of an imposition, but would you mind showing me what the example I posted above would look like when formatted correctly?
 

Winterbay

Active member
Code:
string macro = "if(get_property("spookyPuttyCopiesMade") != "5" && monstername lobsterfrogman);	call puttyfrogman;sub puttyfrogman;if hascombatitem spooky putty sheet;"abort" "No Putty!";endif;use spooky putty sheet;while !pastround 25 && !hpbelow 30;skill shieldbutt;endwhile;"abort" "Too many rounds!";endsub;";

visit_url("fight.php?action=macro&macrotext=" + url_encode(macro) ,true,true);

I think that should work...
 

slyz

Developer
It will, unless you do something like:
PHP:
string macro;
macro += "line1;";
macro += "line2;";
macro += "line3;";
 

Winterbay

Active member
Also, you may need to escape the "-characters in order for it to be one string and not a lot of them now that I think of it.
 

zarqon

Well-known member
Not sure what's going on with the quotes in macros these days but this would probably work:

PHP:
if (last_monster() == $monster[lobsterfrogman] && get_property("spookyPuttyCopiesMade") != "5") {
   if (item_amount($item[putty sheet]) == 0) abort("No putty!"); // don't even hit the server for your abort situation
   visit_url("fight.php?action=macro&macrotext="+url_encode("use item spooky putty sheet; while !pastround 25 && !hpbelow 30; skill shieldbutt; endwhile; \"abort\" \"Too many rounds!\""));
}
 

Banana Lord

Member
That answers some more questions I was going to ask :) Can you think of a more editing-friendly way of presenting the macro part of the script (aside from the suggestion Slyz made earlier)? Putting a small sub on one line is OK, but by the time I've reformatted my entire macro I won't be able to see the wood for the trees.
 

StDoodle

Minion
You could throw in some simple macro-building routines that allowed you to pass your current command into a function, but that's about the best you could do. Or you could do some complicated junk and read from a file to build your macros.
 

holatuwol

Developer
Anyone want to explain to me what kinds of things are valid in "if" statements for KoL combat macros? If all you want is access to KoLmafia properties, and KoL has some mechanism where I can actually substitute get_property("") strings with the property value at macro-build time (or something less vague like $propertyName, like how some other scripting languages do it), that wouldn't be all that hard.
 

holatuwol

Developer
Hm, would "pastround 0" and "pastround 1000" effectively work for true/false checks?

The idea is that, suppose that you were totally comfortable with the idea of macros (something that is submitted to the server all at once, you don't need round-by-round evaluation of your player's status with anything that KoL doesn't give you). Then we COULD add something to KoLmafia to let it know that you want it to evaluate stuff for you at macro compile time.

Code:
if { get_property("awesome") != "awesome" && get_property("awesomer") != "awesomer" }
    goto { import <blah.ash>; blah_function(); }
endif
Then KoLmafia could go, "Oh hey, I see a bunch of curly braces which are not normally legal characters in combat macro, so I'll just parse that when I'm compiling the macro to decide what to actually send to KoL as the macro, replacing those {} blocks with whatever those things actually evaluate to at macro compile time."

It wouldn't allow all of ASH, just whatever subset can be accomplished without {} (which is practically everything, given that imports don't require them, but you have to externalize everything instead of have it all be in your CCS).
 

slyz

Developer
This almost looks like Jason's Employ Script idea. They aren't implemented, but consult scripts can build and submit their own combat macros, so it's not really a problem.

I think CCSs should stay simple. Any more advanced decision making can be done via consult scripts.
 
Top