Simba Code:
function clickClosestNPC(): boolean;
var
i, j, x, y: integer;
b: TBox;
p: TPoint;
tpa, tpa2: TPointArray;
atpa, temp: T2DPointArray;
begin
if findColors(tpa, hp_green, msx1, msy1, msx2, msy2) then
begin
if findColors(tpa2, hp_yellow, msx1, msy1, msx2, msy2) then tpa := combineTPA(tpa, tpa2);
if findColors(tpa2, hp_gray, msx1, msy1, msx2, msy2) then tpa := combineTPA(tpa, tpa2);
if findColors(tpa2, red_square, msx1, msy1, msx2, msy2) then tpa := combineTPA(tpa, tpa2);
//all of these 'findColors' are finding the various possible colors of the NPC HP bars and combining them
tpa.filterPointsBox([375, 240, 425, 250]); //exclude points in this box
atpa := clusterTPA(tpa, 1); //ideally we get a different cluster for each NPC
filterTPAsBetween(atpa, 222, 9000); //filter out TPAs that are too big
filterTPAsBetween(atpa, 0, 50); //filter out TPAs that are too small
for i := 0 to high(atpa) do
begin
b := getTPABounds(atpa[i]); //this just returns a TBox of the TPA's bounds
b.edit(+4, 0, -4, 0); //slightly edit the box
if (b.x1 >= b.x2) then continue(); //skip the box if the bounds are messed up for some reason
if (inRange((b.y2-b.y1), 2, 5)) then //check the the box is the right height
if ((countColor(text_white, b.x1, b.y1-12, b.x2, b.y2) > 88) or //check for white text of monster's name
(countColor(text_yellow, b.x1, b.y1-12, b.x2, b.y2) > 88)) then //check for yellow text of monster's name
temp := temp + atpa[i]; //assign all of the "good" monsters to a temporary variable
end;
if (length(temp) > 0) then //make sure we found at least one good monster
begin
sortATPAFromMidPoint(temp, player_point); //get the closest monster first
for i := 0 to high(temp) do //loop through each good monster in 'temp'
begin
p := middleTPA(temp[0]); //get the middle of the first point. this might be an error? should be 'temp[i]' maybe. idk
b := getTile(pointToTile(p)); //convert from point to tile box
for j := 0 to high(tile_colors) do //check each valid tile color
begin
if findColor(x, y, tile_colors[j], b.x1, b.y1, b.x2, b.y2) then //check if the color is found within the tile box
begin
p.y := min(p.y + random(10, 25), _h-7); //offset the Y coordinate, since the HP bar is above the NPC's head
p.x := p.x + random(-10, 10); //randomize the X a bit
mouse(p, mouse_left); wait(345);
exit(true);
end;
end;
end;
end;
end;
end;