Here are a few more functions I've made and found useful when scripting. Hope someone else can get some use out of them.
Simba Code:
//gets random point in a tpa.
//by HKbotz
function TPointArray.getRandomPoint(): TPoint;
begin
if (length(self) < 1) then
result := point(-1, -1)
else
result := self[random(length(self))];
end;
//mouses a random point in a tpa
//by HKbotz
procedure mouseTPA(tpa: TPointArray; button: integer = MOUSE_MOVE; mmType: integer = MOUSE_HUMAN);
begin
mouse(tpa.getRandomPoint(), button, mmType);
end;
//sorts TBoxArray from point p
//by HKbotz
procedure TBoxArray.sortFromPoint(const p: TPoint);
var
tpa: TPointArray;
tmpBoxArr: TBoxArray;
i, j: integer;
begin
if (length(self) < 1) then
exit();
setLength(tpa, length(self));
setLength(tmpBoxArr, length(self));
for (i := 0) to (high(self)) do
tpa[i] := self[i].getMiddle();
tpa.sortFromPoint(p);
j := 0;
for (i := 0) to (high(tpa)) do
for (j := 0) to (high(self)) do
begin
if (tpa[i].equals(self[j].getMiddle())) then
begin
tmpBoxArr[i] := self[j];
break;
end;
end;
self := tmpBoxArr;
end;
examples:
Simba Code:
var
TPA: TPointArray;
p: TPoint;
begin
//get the tpa using findColorsTolerance or something like that
p := TPA.getRandomPoint();
end.
Simba Code:
var
TPA: TPointArray;
begin
//get the tpa using findColorsTolerance or something like that
mouseTPA(TPA, MOUSE_LEFT);
end.
Simba Code:
var
tba: TBoxArray;
begin
//get the tba somehow
tba.sortFromPoint(mainscreen.playerPoint);
end.