Checking for Scripts currently running.

HasteBro

Member
I was wondering, is there anyway to check if there's a script currently running? I need a way to do this, so that my buffbot's chatbotscript stops interrupting my farming script, which usually means that Mafia halts adventuring AND doesn't buff anyone if it happens to stop mid-battle.

So I need either a way to know if another script is running or a check to see if the buffbot is in-combat, making the chatbotscript wait until the battle ends before buffing.
 

Theraze

Active member
I think HasteBro is actually trying to find out if automation is currently running during another script firing. The only way this would happen, currently, is with a chatbot script firing during automation, or using the adventuring tab to start adventures and then beginning a script/adventuring from the gCLI.
However, even if the adventuring tab is fixed to just use normal queueing, the chatbot conflict remains a possibility...

The answer currently is, no, there isn't a way to tell if something is running. There isn't even really a good way of avoiding it, as I understand it, as either the chatbot waits until after all adventuring/automation is done, or it tries to fire immediately, but either way it ends up awkward somethow... the 'best' solution might be to queue a "run_combat()" into any chatbot calls that might not work right if currently in combat, since that should finish up the fight (if possible) before moving on, and just display the last round of combat if it's already over without actually harming anything.
 

Theraze

Active member
Welcome. The one issue with throwing that in there is that, if your combat fails, the chatbot script will probably abort... though you probably want that to happen if further actions are going to fail anyways.
 

HasteBro

Member
Yeah, but people who use the bot have an uncanny ability to always ask for buffs during a fight, so I guess it will be alright.
 

Catch-22

Active member
Yeah, but people who use the bot have an uncanny ability to always ask for buffs during a fight, so I guess it will be alright.

If this is your main issue: I don't know if KoLmafia tracks combat state internally. If it does, perhaps you could file a feature request for access to this state so you could only cast buffs when, say, in_combat() returns false.

PHP:
if (someoneRequestedBuff) {
    while (in_combat()) {
        qwait(2);
    }
    use_skill(amt, buff, player);
}

A more reliable method would be creating an action queue in a map which can be accessed by an afterAdventure script. If you're automating adventures then you could even set that state at the start of your adventuring scripts (make sure the adventure script sets the state back to false once execution is complete).

PHP:
if (someoneRequestedBuff) {
    if (isAdventuring) {
        //Currently the bot is automating adventures, so we'll queue actions instead of doing them immediately.
        queueAction("buff player");
    } else {
        //Not adventuring at the moment, so let's assume we're idle and cast the buff immediately.
        use_skill(amt, buff, player);
    }
}
 
Last edited:
The way I used to handle this (and still kinda do, just a bit differently) is to have the farming script set a property when it starts adventuring, and then have the chatbotscript either wait or abort when it sees that the property is set. If the farming is going to take a while, it could be awkward to wait (the user(s) will get his(their) buff(s) after X delay).

It might be a bit more tedious, but you could also have the farming script set/unset the property between each adventure, such that the chatbotscript has a chance to fire between adventures (and then, of course, the chatbot would be setting a property such that the farming script waits for it to finish as well).

Or, you could just tell everybody "hey, the bot farms at this time every day, so try to get your buffs before/after".
 
Top