Nebula
2012-10-29 22:07:41
I made this function just earlier for use in a script of mine. I think some people will find it useful (eg. determining if your player has teleported or entered a new area).
{*******************************************************************************
function WaitMMChange(Tol, Percent, TimeOut: Integer): boolean;
Description: Compares your minimap to your starting minimap repeatedly with a
tolerance of Tol. Waits for a max of TimeOut or until the difference
is greater than percent.
*******************************************************************************}
function WaitMMChange(Tol, Percent, TimeOut: Integer): boolean;
var
boxCoords, tmpCoords: array of TPoint;
boxCols, tmpCols: array of Integer;
bools: array of Boolean;
j, TimePlace, maxT, falseBools: Integer;
begin
boxCoords := TPAFromBox(IntToBox(MMX1, MMY1, MMx2, MMY2));
RemoveDistTPointArrayWrap(MMCX, MMCY, 75, boxCoords, true, boxCoords);
RAaSTPA(boxCoords, 3);
boxCols := GetColors(boxCoords);
maxT := TimeOut;
MarkTime(TimePlace);
while (TimeFromMark(TimePlace) < maxT) and (not result) do
begin
falseBools := 0;
tmpCoords := CopyTPA(boxCoords);
tmpCols := GetColors(boxCoords);
SetLength(bools, Length(boxCoords));
for j:= 0 to high(bools) do
bools[j] := SimilarColors(boxCols[j], tmpCols[j], Tol);
for j:= 0 to high(bools) do
if not bools[j] then
inc(falseBools);
result := Round(falseBools * 100.0 / Length(bools)) >= Percent;
end;
end;