SRL Archive - OSR Help

Monster finding method


Shatterhand

2012-04-24 14:41:45

I have this function to find Moss giants in my script. Im kinda newbie at TPAs. I think this method is a little slow.
Any help to improve this would be appreciated. (like faster algorithms) :)
function FindMoss(LookForRedHpBar : Boolean) : Boolean;
var
TPA1, TPA2, TPA3, TPA4, TPA5, TPA6, TPA7, TPA8, TPA : TPointArray;
ATPA : Array of TPointArray;
RedHpBarDTM : Integer;
i, DetectTime, UptextTime, RedHpBarDTMTime : Integer;
ExcludeNearRedHpBAr : Boolean;
begin
MarkTime(DetectTime);
ExcludeNearRedHpBAr := False;

if LookForRedHPBar then //finding the red hpbar from the last fight then we exclude points around it to avoid to attack a dying monster
begin
RedHpBarDTM:= DTMFromString('mWAAAAHicY2FgYOBjZGDgAmJOKH0IKHYAiA8D8TEg3sfBwmDNzgTHrEAxZMyIhkEAABsyBO0=');
if FindDTM(RedHpBarDTM,X,Y,MSX1,MSY1,MSX2,MSY2) then
ExcludeNearRedHpBAr := True;
FreeDTM(RedHpBarDTM);
end;
RedHpBarDTMTime := TimeFromMark(DetectTime);


FindColorsTolerance(TPA1,3823447,MSX1,MSY1,MSX2,MSY2,12); //colors for Mossies
FindColorsTolerance(TPA2,5665130,MSX1,MSY1,MSX2,MSY2,12);
FindColorsTolerance(TPA3,2375742,MSX1,MSY1,MSX2,MSY2,9);
FindColorsTolerance(TPA4,2179404,MSX1,MSY1,MSX2,MSY2,8);

FindColorsTolerance(TPA5,2371894,MSX1,MSY1,MSX2,MSY2,11);
FindColorsTolerance(TPA6,1844005,MSX1,MSY1,MSX2,MSY2,8);
FindColorsTolerance(TPA7,4611177,MSX1,MSY1,MSX2,MSY2,8);
FindColorsTolerance(TPA8,1581349,MSX1,MSY1,MSX2,MSY2,10);


AppendTPA(TPA,TPA1);
AppendTPA(TPA,TPA2);
AppendTPA(TPA,TPA3);
AppendTPA(TPA,TPA4);
AppendTPA(TPA,TPA5);
AppendTPA(TPA,TPA6);
AppendTPA(TPA,TPA7);
AppendTPA(TPA,TPA8);


if (High(TPA)> 0) then
begin

if ExcludeNearRedHpBAr then
begin
SortTPAFrom(TPA,Point(X,Y));
InvertTPA(TPA);
for i:=0 to High(TPA) do
if (Abs(TPA[i].x - (X+30)) < 75) and (Abs(TPA[i].y - Y) < 75) then
Break;
SetArrayLength(TPA,i);
end;

//excluding points near middle
SortTPAFrom(TPA,Point(MSCX,MSCY));
InvertTPA(TPA);
for i:=0 to High(TPA) do
if (Abs(TPA[i].x - MSCX) < 30) and (Abs(TPA[i].y - MSCY) < 30) then
Break;
SetArrayLength(TPA,i);


ATPA := SplitTPA(TPA,10); //splitting TPAs
SortATPASize(ATPA,True);


for i:=0 to High(ATPA) do //excluding TPAs with less than 300 points
begin
if High(ATPA[i]) < 400 then
Break;
end;
SetArrayLength(ATPA,i);

if High(ATPA) < 1 then
Exit;

SortATPAFromFirstPoint(ATPA,Point(MSCX,MSCY)); //making the closest TPA the first in the array

if DebugTPAs then //DebugTPAs
DebugPoints(TPA,ATPA);

if DebugLines and (High(ATPA) > 0) then //DebugLines
begin
Writeln('[Mosses] (400)');
for i:=0 to High(ATPA) do
Writeln('-'+IntToStr(High(ATPA[i])));
end;

if MiddleTPAEx(ATPA[0],X,Y) then //getting the middle point of the TPA, moving mouse there then looking for uptext
begin
MMouse(X,Y,0,0);
MarkTime(UptextTime);
if WaitUpText('ttack',400) then
begin
if DebugLines then //DebugLines
Writeln('Found Moss in ' + IntToStr(TimeFromMark(DetectTime)) + ' ms. Uptext was ' + IntToStr(TimeFromMark(UptextTime)) + ' ms. RedTime was ' + IntToStr(RedHpBarDTMTime) + ' ms.');
Result := True;
Exit;
end;
end;
end;
Result := False;
end;

x[Warrior]x3500

2012-04-24 15:08:12

woah! just a quick tip, get rid of all those findcolortolerance()'s and just craete an autocolor.

Shatterhand

2012-04-24 15:31:57

From: x[Warrior]x3500
woah! just a quick tip, get rid of all those findcolortolerance()'s and just craete an autocolor.

What is that? Just checked autocolor.simba but found only road color/ladder color…, pre set color related things.

x[Warrior]x3500

2012-04-24 15:38:59

well the EASIEST possible way to create an autocolor function is to use ACAv2 (autocolor aide v2) - this is recommended


or if you enjoy trying to figure it out on your own you can use this tut:http://villavu.com/forum/showthread.php?t=32882&highlight=autocolor (i used this when i first came to srl)
or http://villavu.com/forum/showthread.php?t=32882&highlight=autocolor

masterBB

2012-04-24 15:43:53

Autocolor is an overused to tool to get good colors and test them with different cts methods before using it.

I think a better way to short the code would be:

var
j:Integer;
NewTPA,TPA:TPointArray;
colorsToSearch, colorsTol:TIntegerArray;


colorsToSearch := [3823447,5665130,2375742,2179404,2371894,1844005,4611177,1581349];
colorsTol := [12,12,9,8,11,8,8,10];
for j := 0 to High(colorsToSearch) do
begin
FindColorsTolerance(NewTPA,colorsToSearch[j],MSX1,MSY1,MSX2,MSY2,colorsTol[j]);
AppendTPA(TPA,NewTPA);
end;