SRL Archive - OSR Help

TPAs / Interacting with a fire


TehNeonFishy

2012-06-22 12:05:42

I'm trying to get my player to interact with a player made fire, I'm guessing TPA's are the best way to go? I have no idea how to use TPAs, I looked at the only tutorial I could find on them and understood a bit, but coming into practice I still know how what the hell I was doing.

Any help guys? ^^

Abu

2012-06-22 12:10:38

Not sure if this still works but I used this in my GE Cooker

function ClickFire: Boolean;
var
x, y, CTS, I: Integer;
TPA: TPointArray;
ATPA: Array of TPointArray;
begin
Writeln('Clicking Fire...');
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 4697322, 216, 134, 348, 198, 20);
ColorToleranceSpeed(CTS);
ATPA := TPAToATPAEx(TPA, 5, 5);

for I := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y);
Mouse(x, y, 2, 2, True);
Wait(500 + Random(100));
Break;
end;
Result := DidRedClick;
end;

J J

2012-06-22 12:26:06

TPA = TPointArray
TPoint is a Point on the screen with a coord X,Y: Point(X, Y).
Basicly a TPointArray is an Array of Points that all have different Coords.

So you can have one with three points,
Point(30, 50), Point(100, 150), Point(50, 10)

Now you have the function GetColorsSpiralTolerance() that searches the area you input and stores all the points that match with the color/tolerance you input in a TPA. So you will basicly have a huge array all with coords of the points where the color has been found.

There are multiple functions you can use to "modify" this array to your likings. You could get the middle point or even split the TPA into small boxes with TPoints that are near to eachother.

This is the guide I used to learn how to "modify" TPA's: http://villavu.com/forum/showthread.php?t=49067

Runaway

2012-06-22 12:45:41

This could be a little over-the-top, but I'm bored so… :p I use this function when I'm dealing with fires:


function FindFire(Color, Min: TIntegerArray; UseItem: Integer; Strict: Boolean): Boolean;
var
Found, Tol, t, i: Integer;
P: TPoint;
Temp1, Temp2: TPointArray;
TPA, ATPA: T2DPointArray;
begin
Result := False;
for Tol := 10 to 20 do
begin
Found := 0;
for i := 0 to High(Color) do
begin
Writeln('Searching for fire: Tolerance is '+ ToStr(Tol) +'...');
FindColorsTolerance(Temp1, Color[i], MSX1, MSY1, MSX2, MSY2, Tol);
if (Length(Temp1) >= Min[i]) then
begin
SetLength(TPA, Found + 1);
TPA[Found] := Temp1;
Inc(Found);
end;
end;
if Strict then
begin
if (Found >= Length(Color)) then
Temp2 := MergeATPA(TPA)
else
Break;
end else
begin
if (Found >= 1) then
Temp2 := MergeATPA(TPA)
else
Break;
end;
ATPA := TPAToATPAEx(Temp2, 40, 40);
SortATPASize(ATPA, True);
for t := 0 to High(ATPA) do
begin
P := MiddleTPA(ATPA[t]);
if (UseItem <> 0) then
begin
if not ItemActivated(UseWith) then
MouseItem(UseWith, mouse_left);
Wait(200+Random(100));
end;
Mouse(P.x, P.y, 3, 3, mouse_right);
Result := WaitOption('ire', 1000);
if Result then
begin
Wait(500+Random(250));
while IsMoving do
Wait(200);
Exit;
end;
if (t >= 2) then
Break;
end;
end;
end;

It allows for multiple colors. If you wanted to use it to find a fire made from oak logs, you could use it like this:


if FindFire([5210365, 7257851, 8036535], [8, 4, 4], RandomRange(2, 8), True) then
begin
// ...

Abu

2012-06-22 12:50:37

If you're still learning then this should help…

Here is an example you can use to differentiate TPoints and TPointArrays

A TPoint (x and y) would return:


A TPA (TPointArray) would return:


TehNeonFishy

2012-06-23 14:20:46

Thanks guys, got it working. Only needs some finishing touches, but I've been put on 12 hour shifts for the next week so I'm guessing I'll be waiting until next week to finish it off. >.<