SRL Archive - SRL Snippets

tpa.getRandomPoint(), mouseTPA()


HKbotz

2015-01-30 23:07:16

Here are a few more functions I've made and found useful when scripting. Hope someone else can get some use out of them. :)

//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:
var 
TPA: TPointArray;
p: TPoint;
begin
//get the tpa using findColorsTolerance or something like that
p := TPA.getRandomPoint();
end.
var
TPA: TPointArray;
begin
//get the tpa using findColorsTolerance or something like that
mouseTPA(TPA, MOUSE_LEFT);
end.

var
tba: TBoxArray;
begin
//get the tba somehow
tba.sortFromPoint(mainscreen.playerPoint);
end.

The Mayor

2015-01-31 00:52:37

Nice little snippets ;)

apple98

2015-02-01 16:13:09

mmm cant wait :D