Difference between revisions of "Custom Combat Script"

From Kolmafia
Jump to navigation Jump to search
imported>Bale
(updated. Should have done this after macro implementation an age ago. Still needs reference to macrofying.)
imported>Bale
(How to use macros in a CCS! Also, stuff on disco combos in regular CCS)
Line 1: Line 1:
 
{{TOCright}}
 
{{TOCright}}
= Basic CCS =
+
== Basic CCS ==
 
A Custom Combat Script (CCS) is a way of instructing mafia how to handle combat, round by round. For example, a simple CCS would be to tell mafia to pickpocket on round 1, then cast entangling noodles on round 2 and finally on rounds 3+ to use shieldbutt. If it is unable to carry out one of those steps, then that step will be skipped. For instance, if the character failed to get initiative, then pickpocket will be skipped and the character will go straight to entangling noodles. That CCS would look like this:
 
A Custom Combat Script (CCS) is a way of instructing mafia how to handle combat, round by round. For example, a simple CCS would be to tell mafia to pickpocket on round 1, then cast entangling noodles on round 2 and finally on rounds 3+ to use shieldbutt. If it is unable to carry out one of those steps, then that step will be skipped. For instance, if the character failed to get initiative, then pickpocket will be skipped and the character will go straight to entangling noodles. That CCS would look like this:
  
Line 15: Line 15:
  
 
<div style="border: solid 1px black; padding: 1em; margin:0px 20px;">
 
<div style="border: solid 1px black; padding: 1em; margin:0px 20px;">
[ default ]<br />
+
[ Black Knight ]<br />
 
try to steal an item<br />
 
try to steal an item<br />
 +
skill transcendent olfaction<br />
 
skill entangling noodles<br />
 
skill entangling noodles<br />
 
skill shieldbutt<br />
 
skill shieldbutt<br />
  
 
+
[ default ]<br />
[ Black Knight ]<br />
 
 
try to steal an item<br />
 
try to steal an item<br />
skill transcendent olfaction<br />
 
 
skill entangling noodles<br />
 
skill entangling noodles<br />
 
skill shieldbutt<br />
 
skill shieldbutt<br />
 
</div>
 
</div>
  
 +
Note that when you use a CCS, your CLI will report "character executes a macro!" because the CCS is converted into a macro to save on page loads
  
==== Legal commands are ====
+
=== Legal commands are ===
 
* attack
 
* attack
 
* skill
 
* skill
Line 36: Line 36:
 
* summon pastamancer ghost
 
* summon pastamancer ghost
 
* jiggle chefstaff
 
* jiggle chefstaff
 +
* combo {followed by one of the following}
 +
** Disco Concentration, Disco Nirvana, Disco Inferno, Disco Bleeding, Disco Blindness
 +
** Rave Knockout, Rave Bleeding, Rave Concentration, Rave Steal, Rave Nirvana, Rave Stats
 +
* abort
 +
 +
== Macros in CCS ==
 +
Macros may be used in a Custom Combat Script in addition to the basic commands. Any line in quotes  and any macro command used in a CCS will be made into part of the macro which KoLmafia is passing to KoL. You can find an primer on all KoL's macros at {{kolwiki|Combat Macros}}.
 +
 +
Note that a macro's abort command needs to be encased in quotes because abort is also a legal CCS command. See the following example of a demonstration of how to do that. Also, if a comment is the last line in a CCS, that will be used as your finishing attack even though it does nothing. Never conclude a CCS with a macro comment.
 +
 +
Also there is a section in the CCS called "global prefix" which will be part of every combat macro KoLmafia generates, regardless of the monster encountered.
 +
 +
Here's an example of a CCS that generates a macro which will cause KoL to wait for a hobo monkey to steal meat from your enemy before launching attacks.
 +
<div style="border: solid 1px black; padding: 1em; margin:0px 20px;">
 +
[ default ]<br />
 +
call monkey_stasis<br />
 +
attack<br />
 +
 +
[ global prefix ]<br />
 +
scrollwhendone<br />
 +
"abort hppercentbelow 10 #if HP ever falls below 10%, abort before you die"<br />
 +
"abort missed 5"<br />
 +
"abort pastround 25"<br />
 +
sub stasis_item<br />
 +
:while !pastround 20 && !hppercentbelow 20 && mppercentbelow 99
 +
::if hascombatitem facsimile dictionary
 +
:::item facsimile dictionary
 +
:::goto _endstasisitem
 +
::endif
 +
::if hascombatitem turtle totem
 +
:::item turtle totem
 +
:::goto _endstasisitem
 +
::endif
 +
::if hascombatitem spices
 +
:::item spices
 +
:::goto _endstasisitem
 +
::endif
 +
::if hascombatitem seal tooth
 +
:::item seal tooth
 +
:::goto _endstasisitem
 +
::endif
 +
::if hascombatitem spectre scepter
 +
:::item spectre scepter
 +
:::goto _endstasisitem
 +
::endif
 +
::if hascombatitem dictionary
 +
:::item dictionary
 +
:::goto _endstasisitem
 +
::endif
 +
::if hascombatitem fat stacks of cash
 +
:::item fat stacks of cash
 +
:::goto _endstasisitem
 +
::endif
 +
::"abort "No infinite use items detected!" "
 +
::mark _endstasisitem
 +
:endwhile
 +
endsub<br />
 +
sub monkey_stasis<br />
 +
:while !match "climbs up and sits on your shoulder" && !pastround 20
 +
::call stasis_item
 +
:endwhile<br />
 +
endsub<br />
 +
</div>
  
= Consult Scripts =
+
== Consult Scripts ==
While this may seem reasonably flexible, sometimes you will want to do something too complicated to express in this format. For instance if you want your character to cast a Rave Combo if the character is a Disco Bandit, you'd have to change your CCS every ascension, but a consult script can automatically figure it out.
+
While this may seem reasonably flexible, sometimes you will want to do something too complicated to express in this format. For instance if you want your character to take different actions based on your characters current stats or current monster level, a consult script can automatically figure it out. There are few limits to what a consult script can enable. The downside to using a consult script is that KoLmafia will not be able to generate a combat macro to pass to KoL. As a result multi-round combat will take somewhat longer.
  
 
A consult script is called by using the "consult" command in your CCS, as follows:
 
A consult script is called by using the "consult" command in your CCS, as follows:
Line 54: Line 117:
 
These values will be supplied by mafia when the consult script is called.
 
These values will be supplied by mafia when the consult script is called.
  
== Example of a Consult Script ==
+
=== Example of a Consult Script ===
 
This example will attempt to maximize use of a Sauceror's spells as a Sauceror by making use of sauce splash effects when they can be used.
 
This example will attempt to maximize use of a Sauceror's spells as a Sauceror by making use of sauce splash effects when they can be used.
 
<div style="margin-bottom: 1em; border: dashed 1px green; padding: 1em; margin:0px 20px;"><syntaxhighlight>
 
<div style="margin-bottom: 1em; border: dashed 1px green; padding: 1em; margin:0px 20px;"><syntaxhighlight>
Line 99: Line 162:
 
</div>
 
</div>
  
== Parts of a Combat Consultation Script ==
+
=== Parts of a Combat Consultation Script ===
 
As you can see in the above example, a consultation script is called with three parameters.
 
As you can see in the above example, a consultation script is called with three parameters.
 
*The first parameter is the round of combat that the script is called. Sometimes it is important to keep track of the round. This is particularly important to keep from losing the fight by going over 30 rounds.
 
*The first parameter is the round of combat that the script is called. Sometimes it is important to keep track of the round. This is particularly important to keep from losing the fight by going over 30 rounds.
Line 107: Line 170:
 
All possible actions you can take in a round of combat are listed under [[In-combat Consulting]].
 
All possible actions you can take in a round of combat are listed under [[In-combat Consulting]].
  
== Resolution of a Combat Consultation Script ==
+
=== Resolution of a Combat Consultation Script ===
 
The consult script can automate as many, or as few rounds of combat as desired to achieve its goal. When it finishes executing, if the monster is not yet dead, then the CCS will continue combat from the current round. Note that the current round is not always the next line in a script. For instance, if the consult script is called at round 1 and executes three actions, then it will return to the CCS at round 4. This is why most CCSs containing consult script prefer to have only a line after the consult script, usually a simple method of killing a monster.
 
The consult script can automate as many, or as few rounds of combat as desired to achieve its goal. When it finishes executing, if the monster is not yet dead, then the CCS will continue combat from the current round. Note that the current round is not always the next line in a script. For instance, if the consult script is called at round 1 and executes three actions, then it will return to the CCS at round 4. This is why most CCSs containing consult script prefer to have only a line after the consult script, usually a simple method of killing a monster.
  
  
= Employ Scripts =
+
== Employ Scripts ==
 
<div style="padding: 1em; border: solid 1px red; color: red; font-weight: bold;">Please note! This section is speculative; Employ Scripts have not yet been implemented.</div>
 
<div style="padding: 1em; border: solid 1px red; color: red; font-weight: bold;">Please note! This section is speculative; Employ Scripts have not yet been implemented.</div>
 
An employ script is a like a consultation script, with benefits. While a consultation script operates turn-by-turn, an employ script operates only at the beginning of the combat and generates a combat macro.
 
An employ script is a like a consultation script, with benefits. While a consultation script operates turn-by-turn, an employ script operates only at the beginning of the combat and generates a combat macro.

Revision as of 22:07, 12 October 2010

Basic CCS

A Custom Combat Script (CCS) is a way of instructing mafia how to handle combat, round by round. For example, a simple CCS would be to tell mafia to pickpocket on round 1, then cast entangling noodles on round 2 and finally on rounds 3+ to use shieldbutt. If it is unable to carry out one of those steps, then that step will be skipped. For instance, if the character failed to get initiative, then pickpocket will be skipped and the character will go straight to entangling noodles. That CCS would look like this:

[ default ]
try to steal an item
skill entangling noodles
skill shieldbutt


If you wanted to treat different monsters differently, that can be accommodated also. For instance, the following CCS will attempt to cast Transcendent Olfaction upon Black Knights while treating all other monsters differently. If the character currently has "On the Trail" then that line will be skipped.


[ Black Knight ]
try to steal an item
skill transcendent olfaction
skill entangling noodles
skill shieldbutt

[ default ]
try to steal an item
skill entangling noodles
skill shieldbutt

Note that when you use a CCS, your CLI will report "character executes a macro!" because the CCS is converted into a macro to save on page loads

Legal commands are

  • attack
  • skill
  • item, use
  • try to steal an item, pickpocket
  • summon pastamancer ghost
  • jiggle chefstaff
  • combo {followed by one of the following}
    • Disco Concentration, Disco Nirvana, Disco Inferno, Disco Bleeding, Disco Blindness
    • Rave Knockout, Rave Bleeding, Rave Concentration, Rave Steal, Rave Nirvana, Rave Stats
  • abort

Macros in CCS

Macros may be used in a Custom Combat Script in addition to the basic commands. Any line in quotes and any macro command used in a CCS will be made into part of the macro which KoLmafia is passing to KoL. You can find an primer on all KoL's macros at Combat Macros.

Note that a macro's abort command needs to be encased in quotes because abort is also a legal CCS command. See the following example of a demonstration of how to do that. Also, if a comment is the last line in a CCS, that will be used as your finishing attack even though it does nothing. Never conclude a CCS with a macro comment.

Also there is a section in the CCS called "global prefix" which will be part of every combat macro KoLmafia generates, regardless of the monster encountered.

Here's an example of a CCS that generates a macro which will cause KoL to wait for a hobo monkey to steal meat from your enemy before launching attacks.

[ default ]
call monkey_stasis
attack

[ global prefix ]
scrollwhendone
"abort hppercentbelow 10 #if HP ever falls below 10%, abort before you die"
"abort missed 5"
"abort pastround 25"
sub stasis_item

while !pastround 20 && !hppercentbelow 20 && mppercentbelow 99
if hascombatitem facsimile dictionary
item facsimile dictionary
goto _endstasisitem
endif
if hascombatitem turtle totem
item turtle totem
goto _endstasisitem
endif
if hascombatitem spices
item spices
goto _endstasisitem
endif
if hascombatitem seal tooth
item seal tooth
goto _endstasisitem
endif
if hascombatitem spectre scepter
item spectre scepter
goto _endstasisitem
endif
if hascombatitem dictionary
item dictionary
goto _endstasisitem
endif
if hascombatitem fat stacks of cash
item fat stacks of cash
goto _endstasisitem
endif
"abort "No infinite use items detected!" "
mark _endstasisitem
endwhile

endsub
sub monkey_stasis

while !match "climbs up and sits on your shoulder" && !pastround 20
call stasis_item
endwhile

endsub

Consult Scripts

While this may seem reasonably flexible, sometimes you will want to do something too complicated to express in this format. For instance if you want your character to take different actions based on your characters current stats or current monster level, a consult script can automatically figure it out. There are few limits to what a consult script can enable. The downside to using a consult script is that KoLmafia will not be able to generate a combat macro to pass to KoL. As a result multi-round combat will take somewhat longer.

A consult script is called by using the "consult" command in your CCS, as follows:

[ default ]
consult myscript.ash
attack

The main() function in the ASH script being consulted must accept three parameters:

void main(int round, monster mob, string page)

These values will be supplied by mafia when the consult script is called.

Example of a Consult Script

This example will attempt to maximize use of a Sauceror's spells as a Sauceror by making use of sauce splash effects when they can be used.

// Save this as SauceSplash.ash
boolean sauceSplash() {
   if(!(have_effect($effect[Jabañero Saucesphere]) >0 
      || have_effect($effect[Jalapeño Saucesphere]) >0))
         return false;
   int normal = numeric_modifier("spell damage");
   if(normal >= 25)
      return true;
   int cold = numeric_modifier("cold spell damage");
   int hot = numeric_modifier("hot spell damage");
   if(have_skill($skill[Immaculate Seasoning])
      && cold != hot && max(cold, hot) + normal >= 25)
         return true;
   if(monster_element() == $element[cold] && cold + normal >= 25 
     && (have_skill($skill[Immaculate Seasoning])
     || have_equipped($item[Gazpacho's Glacial Grimoire])))
        return true;
   if(monster_element() == $element[hot] && hot + normal >= 25
     && (have_skill($skill[Immaculate Seasoning])
     || have_equipped($item[Codex of Capsaicin Conjuration]) 
     || have_equipped($item[Ol' Scratch's manacles])
     || (have_equipped($item[Ol' Scratch's ash can]) && my_class() == $class[Sauceror])))
        return true;
   return false;
}

void main(int initround, monster foe, string url) {
   if(have_effect($effect[Burning Soul]) || have_effect($effect[Soul Freeze]) || !sauceSplash())
      use_skill($skill[Saucegeyser]);
   else
      use_skill($skill[Wave of Sauce]);
}


This consult script can then be integrated into a CCS like this:

[ default ]
consult SauceSplash.ash
attack

Parts of a Combat Consultation Script

As you can see in the above example, a consultation script is called with three parameters.

  • The first parameter is the round of combat that the script is called. Sometimes it is important to keep track of the round. This is particularly important to keep from losing the fight by going over 30 rounds.
  • The second parameter is the monster that you are fighting. This is important because it enables you to take different actions for different monsters.
  • The third parameter is the text of the page. This is important because it enables you to examine every detail of the fight as it is taking place. It can be analyzed for potential actions, damage that you deal to a monster and all other events.

All possible actions you can take in a round of combat are listed under In-combat Consulting.

Resolution of a Combat Consultation Script

The consult script can automate as many, or as few rounds of combat as desired to achieve its goal. When it finishes executing, if the monster is not yet dead, then the CCS will continue combat from the current round. Note that the current round is not always the next line in a script. For instance, if the consult script is called at round 1 and executes three actions, then it will return to the CCS at round 4. This is why most CCSs containing consult script prefer to have only a line after the consult script, usually a simple method of killing a monster.


Employ Scripts

Please note! This section is speculative; Employ Scripts have not yet been implemented.

An employ script is a like a consultation script, with benefits. While a consultation script operates turn-by-turn, an employ script operates only at the beginning of the combat and generates a combat macro.

Employ scripts do not yet exist in KolMafia at this time, but they are a goal that jasonharper is working towards as he describes on the mafia forum.


It is currently proposed that they will have the following format:

string main( string opponent, string pageText, string macroSoFar, string parameter )
  • opponent is the name of the monster being fought, just as in a consult script or combat filter function.
  • pageText is the raw HTML of the initial combat page. This isn't necessarily going to be useful (since it's a one-time snapshot), however you may want to examine the Skills popup to see what conditionally-available skills are actually available.
  • macroSoFar is the current text of the macro being built - a mafia-generated header with some useful subroutines defined, followed by macro translations of all the prior lines in the CCS.
  • parameter contains any extra text from the CCS line; it could be used to customize the behavior of the script, more conveniently than using a "note" line with a consult script. It also serves the less obvious purpose of making the parameter count something other than 3, so that mistakenly attempting to employ a consult script, or consult an employ script, will fail before any code runs.
  • The return value entirely replaces the macro being built. It would probably be an error for this to be any shorter than the original value of macroSoFar.

The simplest thing an employ script could do is to append some commands to macroSoFar, and return that. Other possibilities include:

  • It could look back through the previously-generated macro commands to decide what to do. For example, it could refrain from adding a "pickpocket" action if that has already been done
  • If it wanted to set up a global abort condition, active throughout the combat, it could insert the command at the beginning of the macro.
  • There will be a subroutine called "mafiaround" defined in the header, and called before every combat action to handle things like automatic antidote use. The script could insert commands into that subroutine, for example to implement an eye color check for using He-Boulder major rays.
  • There will likely be other defined subroutines for the script to call or modify.