Im working on a fighter script too. The monster finding part is already ready and working. I search for all the hpbars on the screen and exclude those areas when finding colors for monster.
Finder function. Colors are set for ghouls. You will need two global variables.
Simba Code:
MarkTime(FailTime); //call this before the searching loop
SortPoint := IntToPoint(MSCX,MSCY); //call this before the searching loop
Simba Code:
function FindMonster: Boolean;
var
TPA, TempTPA, GreenTPA, RedTPA : TPointArray;
ATPA : Array of TPointArray;
X,Y, i,j, CTS, BoxWidth,BoxHeight, MinPoints : Integer;
Colors, Tolerances : Array of Integer;
HueMods, SatMods : Array of Extended;
a : TPoint;
TempBox : TBox;
ExcludeBoxes : Array of TBox;
begin
Result := False;
//EXCLUDING
FindColorsTolerance(GreenTPA,65280,MSX1,MSY1,MSX2,MSY2,0);
FindColorsTolerance(RedTPA,255,MSX1,MSY1,MSX2,MSY2,0);
TPA := CombineTPA(GreenTPA,RedTPA);
if (High(TPA) > 0) then
begin
SplitTPAWrap(TPA,1,ATPA);
SetLength(ExcludeBoxes,Length(ATPA));
for i:=0 to High(ATPA) do
begin
TempBox := GetTPABounds(ATPA[i]);
BoxWidth := TempBox.x2-TempBox.x1;
BoxHeight := TempBox.y2-TempBox.y1;
if (BoxWidth = 29) and (BoxHeight = 4) then
begin
TempBox.x1 := TempBox.x1-20; //the bigger the monster is, the bigger you make this box
TempBox.y1 := TempBox.y1-20;
TempBox.x2 := TempBox.x2+20;
TempBox.y2 := TempBox.y2+40;
ExcludeBoxes[j] := TempBox;
Inc(j);
end;
end;
SetArrayLength(ExcludeBoxes,j);
end;
//MONSTER
Colors := [8364964];
Tolerances := [24];
HueMods := [0.02];
SatMods := [0.23];
MinPoints := 50;
CTS := GetToleranceSpeed;
ColorToleranceSpeed(2);
for i:=0 to High(Colors) do
begin
SetToleranceSpeed2Modifiers(Huemods[i],SatMods[i]);
FindColorsTolerance(TempTPA,Colors[i],MSX1,MSY1,MSX2,MSY2,Tolerances[i]);
AppendTPA(TPA,TempTPA);
end;
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
//Excluding - boxes
for i:=0 to High(TPA) do
begin
for j:=0 to High(ExcludeBoxes) do
begin
if PointInBox(TPA[i],ExcludeBoxes[j]) then
begin
a := IntToPoint(MSCX,MSCY);
tSwap(TPA[i],a);
Break;
end;
end;
end;
//Excluding - middle
SortTPAFrom(TPA,Point(MSCX,MSCY));
InvertTPA(TPA);
for i:=0 to High(TPA) do
if (Abs(TPA[i].x - MSCX) < 20) and (Abs(TPA[i].y - MSCY) < 30) then
Break;
SetArrayLength(TPA,i);
if (High(TPA)> 0) then
begin
ATPA := SplitTPA(TPA,10);
SortATPASize(ATPA,True);
for i:=0 to High(ATPA) do
begin
if High(ATPA[i]) < MinPoints then
Break;
end;
if (i = 0) then Exit;
SetArrayLength(ATPA,i);
SortATPAFromFirstPoint(ATPA,IntToPoint(MSCX,MSCY));
DebugAll(TPA,ATPA,0,ExcludeBoxes);
{$IFDEF SMART}
//SMART_DebugAll(TPA,ATPA,0,ExcludeBoxes);
{$ENDIF}
MiddleTPAEx(ATPA[0],X,Y);
if (TimeFromMark(FailTime) < 5000) then
begin
Mouse(X,Y,0,0,mouse_move);
if IsUpText('Attack') then
begin
ClickMouse2(mouse_left);
if DidClick(True,2000) then
begin
Result := True;
Exit;
end;
end else
begin
SortPoint := IntToPoint(X,Y);
end;
end else
begin
Mouse(X,Y,0,0,mouse_right);
if ChooseOption('Attack') then
begin
Result := True;
Exit;
end else
begin
SortPoint := IntToPoint(X,Y);
end;
end;
end;
end;
Debug functions:
Simba Code:
procedure SetBoxToBounds(var Box : TBox; X1,Y1,X2,Y2 : Integer);
begin
if (Box.x1 < X1) then Box.x1 := X1;
if (Box.x2 > X2) then Box.x2 := X2;
if (Box.y1 < Y1) then Box.y1 := Y1;
if (Box.y2 > Y2) then Box.y2 := Y2;
end;
procedure DebugAll(TPA: TPointArray; ATPA: Array of TPointArray; First: Integer; Boxes: Array of TBox);
var
BMP, Col, x, y, i, width, height: Integer;
TPABox : TBox;
begin
//if not DebugWindow then Exit;
GetClientDimensions(width,height);
BMP := BitmapFromClient(0,0,width-1,height-1);
DrawTPABitmap(BMP,TPA,ClWhite);
for i:=0 to High(ATPA) do
begin
if i = First then
Col := ClRed
else
Col := ClYellow;
TPABox := GetTPABounds(ATPA[i]);
SetBoxToBounds(TPABox,0,0,width-1,height-1);
for x := TPABox.x1 to TPABox.x2 do
begin
FastSetPixel(BMP,x,TPABox.y1,Col)
FastSetPixel(BMP,x,TPABox.y2,Col)
end;
for y := TPABox.y1 to TPABox.y2 do
begin
FastSetPixel(BMP,TPABox.x1,y,Col)
FastSetPixel(BMP,TPABox.x2,y,Col)
end;
end;
for i:=Low(Boxes) to High(Boxes) do
begin
SetBoxToBounds(Boxes[i],MSX1,MSY1,MSX2,MSY2);
for x := Boxes[i].x1 to Boxes[i].x2 do
begin
FastSetPixel(BMP,x,Boxes[i].y1,ClBlack)
FastSetPixel(BMP,x,Boxes[i].y2,ClBlack)
end;
for y := Boxes[i].y1 to Boxes[i].y2 do
begin
FastSetPixel(BMP,Boxes[i].x1,y,ClBlack)
FastSetPixel(BMP,Boxes[i].x2,y,ClBlack)
end;
end;
DebugBitmap(BMP);
FreeBitmap(BMP);
end;