From my Jr. Members+ Barrows script:
{PROCEDURE -- regenerate
Purpose: Regenerates health after a fight.
Comments: None.}
procedure regenerate;
var
regenerateLocation: TPoint;
begin
if not isLoggedIn or areWeFighting then
exit;
regenerateLocation := point(actionbar.x1 + 24 + random( - 3, 3), actionbar.y1 + 17 + random( - 3, 3));
ClarityDebug('Regeneration initiated.');
if (actionBar.getAdrenalinePercent() > 5) then
begin
mouse(regenerateLocation, MOUSE_MOVE, MOUSE_HUMAN);
fastClick(MOUSE_LEFT);
ClarityDebug('Regenerating health with leftover adrenaline. Did so blindly.');
scriptStatus('Regenerating health.');
wait(GaussRangeInt(300, 1000));
end;
end;
To check if you are in or out of combat, you could do a number of things. You could check for the presence of the health bar above your player, restricting the search to a box around your player so other players' health bars are not detected. A DTM would probably work well.
My check for fighting vs. not fighting is this, but it is specific to the script, you would want to search for a different DTM depending on your script.
{FUNCTION -- areWeFighting
Purpose: Checks if we are fighting a brother.
Comments: None.}
function areWeFighting: boolean;
var
x, y, tries: integer;
begin
if not isLoggedIn then
exit;
result := false;
isAkrisae := false;
ClarityDebug('Checking to see if we are in combat.');
while tries < 4 do
begin
if findDTM(earthWeakness, x, y, mainScreen.getBounds()) or
findDTM(airWeakness, x, y, mainScreen.getBounds()) or
findDTM(rangedWeakness, x, y, mainScreen.getBounds()) or
findDTM(rangedWeaknessAlt, x, y, mainScreen.getBounds()) or
findDTM(fireWeakness, x, y, mainScreen.getBounds()) or
findDTM(stabWeakness, x, y, mainScreen.getBounds()) or
findDTM(waterWeakness, x, y, mainScreen.getBounds()) or
findDTM(boltWeakness, x, y, mainScreen.getBounds()) then
begin
if findDTM(boltWeakness, x, y, mainScreen.getBounds()) then
begin
isAkrisae := true;
ClarityDebug('We are fighting Akrisae!');
end;
result := true;
ClarityDebug('Currently in combat with a Barrows brother.');
exit;
end
else
inc(tries);
end;
end;
Actionbar.isSlotActive might lead to misleading results since I don't believe you need to be in combat for a slot to be selected.