Using target's HP as a condition in combat?

Aoi

New member
I'm trying to build something that can perform different actions based on the current HP of whatever you're fighting.

I've found a potentially workable, though incredibly hardcoded and inelegant, solution via a consult script using monster_HP() and a gigantic series of nested if statements. I'm pretty confident there's a better way to go about this though.

...Of course, while typing this, inspiration struck-- at a glance, is this vein of thought about as good as it gets?

string run(int round, string opp, string text) {
for i from 1 to 30 {
if (monster_HP() < Target){
return get_ccs_action(31);
}
else {
return get_ccs_action(round);
}

where each turn's commands are in the CSS and a 31st turn gives the conditional behavior.
 

roippi

Developer
Head over to the smartstasis thread, where Zarqon just posted an alpha version of BatBrain. It's hardly drag-and-drop (it's "just" a library of functions) but it is eventually going to be a very elegant solution to this very problem.
 

StDoodle

Minion
I just don't understand using both "return" and a for loop... but perhaps I just don't understand consult scripting. (Always has been mysterious to me, despite some efforts.)
 

Bale

Minion
I just don't understand using both "return" and a for loop... but perhaps I just don't understand consult scripting. (Always has been mysterious to me, despite some efforts.)

Nope, that code was pretty much nonsense. I think he wanted to do this:

Code:
string run(int round, string opp, string text) {
      if (monster_HP() < Target){
         return get_ccs_action(31);
      }
     else {
         return get_ccs_action(round);
     }
}

First of all, this is a combat filter for use with the three parameter version of adventure(), not a consult script.

This will run the combat with the commands from 1-30, but when the monsters HP gets less than Target (which hopefully will be defined somewhere in the script), it will finish off the monster with the round 31 action.
 
Last edited:

StDoodle

Minion
Ah, knowing it's a combat filter clears things up. Why is it every time there's a question regarding combat, all scripts are referred to as consult scripts? ;)
 

Veracity

Developer
Staff member
Code:
string run(int round, string opp, string text) {
      if (monster_HP() < Target){
         return get_ccs_action(31);
      }
     else {
         return get_ccs_action(round);
     }
}
of course, now you can do this:
Code:
 string run( int round, string opp, string text )
{
    return get_ccs_action( monster_HP() < Target ? 31 : round );
}

:)
 

Aoi

New member
I was calling it a consult since I was running it via 'consult scriptname.ash'. Seemed like a reasonable thing call it, in that case.

So pretty much, a filter script was the exact thing I was looking for. One of my previous attempts was actually leading towards writing my own with an unpleasant set of loops.

Indeed; I'm not a particularly skilled coder [or even decent, at that...]. Since most of my final objectives are pretty niche though, hammering at it until you end up with a mess of spaghetti that somehow works usually isn't a problem. Horrible for learning though.

Thank you everybody for your assistance! Your link to the combat filters, something I haven't encountered before, was particularly useful, Bale.
 

StDoodle

Minion
I was calling it a consult since I was running it via 'consult scriptname.ash'. Seemed like a reasonable thing call it, in that case.

Is this something that works on non-windows OS's or something? The command "consult" returns "Unable to invoke consult" for me.

I was trying to attack you personally, it's just that this happens fairly often. Perhaps there's a mac or linux specific command I'm unaware of, and that's why... *shrug*
 

Theraze

Active member
I believe that Aoi means that was the line used in the CCS (consult), not that it was called in gCLI...
 

StDoodle

Minion
Ah yeah. Long day, I shoulda been able to see that. I think V's statement through me off; technically, it was part of a consult, just not the main() function (which wasn't shown). Argh, long day.
 

Aoi

New member
Oh, I didn't take it as an attack; I well aware that my knowledge of Mafia scripting is lacking so I spent some time looking up what else it could be. Didn't find anything, but looking through the Mafia info is educational nonetheless.
 
Top