SRL Archive - OSR Help

Checking if colors are gone


Roflme

2012-11-14 16:53:22

wall of text, I apologize if I left out any information or if I made any spelling errors.

Working on a mining script, and for a fail safe I was going to use WairColorGone for a failsafe to see if someone else stole the ore. When I was just using WaitColorGone, though, the color that was found would be blocked out by mining animation and it would come back as true, trying to click on the same/another ore. I wanted to know if someone could make suggestions to this function I wrote; will it even work? What can I do to improve it? etc.

(I've posted the other functions that go along with it).

And the goal of the function is that I want to use the furthest color point away from my player. That isn't blocked, but when I was putting WaitColorGone right in my function the colors were just gone. So with the following function, I'm trying to use the coords in MineOre, and set then to cx and cy. Find the colors spiraled around it but only in a small area (to make sure it doesn't include other ores in the TPA). Then, sort them so it'll start with the furthest away.

function CheckIfOreGone(Color, tol: Integer):Boolean;
var
C: Integer;
cTPA: TPointArray;
cATPA: T2DPointArray;
begin
if not FindColorsSpiralTolerance(cx, cy, cTPA, Color, cx-6, cy-6, cx+6, cy+6, tol) then // Probably will have to play with the area it's looking in (the integer cx is +/- by).
Exit;

cATPA := TPAtoATPAEx(cTPA, 1, 1);

SortATPAFromSize(cATPA, {Size??}, False); //What should fill in the size? I put a 1 and it compiled fine?
For C := 0 to High(cATPA) do
ox := MiddleTPA(cATPA[c]).x; //Would I change this to cATPA[0]? Because I ONLY want the furthest away coords, so there's no need for the other cATPAs?
oy := MiddleTPA(cATPA[c]).y;

Result := WaitColorGone(Color, ox, oy, tol, 30000);
end;

function MineOre(Which: String; tol: Integer):Boolean;
var
PlusOne, Mining1, Mining2, Mining2Wait: Integer;
begin
if InvFull then
Exit;

MarkTime(Mining1);

case Lowercase(Which) of
'mith':
begin
Color := MithColor; //AutoColor Function
Hue := 0.09;
Sat := 0.61;
Text := ['ithril', 'ril or', 'mithril ore', 'Mine Mith', 'ine M'];
S := ['ine Mith', 'ril ore', 'Mine Mithril ore rocks'];
Mining2Wait := 25000;
end;
'addy':
begin
Color := AddyColor; //AutoColor Function
Hue := 0.11;
Sat := 0.72;
Text := ['amant', 'ine A', 'tite or'];
S := ['Mine Adamantite ore rocks', 'ine Ada', 'ite or', 'daman'];
Mining2Wait := 55000;
end;
end;
if not FindOre(Color, tol, Hue, Sat, Text) then
Exit;

begin
PlusOne := InvCount + 1;
ClickMouse2(false);
Result := WaitOptionMulti(S, 500);

if TimeFromMark(Mining1) > 10000 then
Exit;

if Result then
begin
MarkTime(Mining2);
Wait(RandomRange(300,400));
while IsMoving do
Wait(250);

cx := x;
cy := y;

// CheckIfOreGone would go here

repeat
Wait(RandomRange(100,120));
until WaitColorGone(Color, cx, cy, tol, 30000) or (InvCount = PlusOne) or (TimeFromMark(Mining2) > Mining2Wait);
end;
end;
end;

function FindOre(Color, tol: Integer; Hue, Sat: Extended; Text: TStringArray):Boolean;
var
tCTS, I: Integer;
TPA: TPointArray;
ATPA: T2DPointArray;
myPoint: TPoint;
begin
myPoint := Point(MSCX, MSCY);
tCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(Hue, Sat);
if not FindColorsSpiralTolerance(MSCX, MSCY, TPA, Color, MSX1, MSY1, MSX2, MSY2, tol) then
begin
ColorToleranceSpeed(tCTS);
Exit;
end;
ATPA := TPAtoATPAEx(TPA, 10, 10);
SortATPAFrom(ATPA, myPoint);
For I := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 2, 2);
if IsUpTextMultiCustom(Text) then
Result := True;
end;
ColorToleranceSpeed(tCTS);
end;

I believe those are all the functions…

I haven't tested it yet (Don't know what to put in for the Size), but in theory would that work? Are there any other functions that would do what I want (to find when the ore is gone) in some way?

Sorry for the long post :p

If you actually read that all I thank you very much :D!

weequ

2012-11-14 17:05:26

You are missing a begin after for c:=0 to high (…
Maybe try waiting untill the color has changed and remained constant for a period of time? That would mean that there is nothing animating over it.

Edit btw you are now sorting by the amount of matches (size) and not by distance like you intended to? Use sortatpafrom I stead. Also the for c..to loop is unnecessary if only want to deal with the closest rock. If you want the furthest point of the rock you should short the tpointaaray atpa [0] from the middle (use middletpa or gettpabounds) and use the last point of that array.

Sorry I'm typing on my phone so it's not very easily readable.

Roflme

2012-11-14 17:18:44

From: weequ
You are missing a begin after for c:=0 to high (…
Maybe try waiting untill the color has changed and remained constant for a period of time? That would mean that there is nothing animating over it.


Ah, alright. I'll add that begin in :p

And what could I use to check for that?

EDIT:
From: weequ
Edit btw you are now sorting by the amount of matches (size) and not by distance like you intended to? Use sortatpafrom I stead. Also the for c..to loop is unnecessary if only want to deal with the closest rock. If you want the furthest point of the rock you should short the tpointaaray atpa [0] from the middle (use middletpa or gettpabounds) and use the last point of that array.

Sorry I'm typing on my phone so it's not very easily readable.


I don't know where to put sortatpafrom. The specified Tpoint would vary. If possible I wanted to make a circle around the original point I found (roughly the middle of the rock) and make a circle around it, so the furthest distance would contain the color furthest away from me. But if I can't get a point constantly the furthest away from me, then I don't know how I can use sortatpafrom correctly since I'm always changing what side I'm mining on.

And alright I can just take out that and change it to cATPA[0]. Just added that there in case I would have needed it :p

EDIT2: So use GetTPABounds will get me points and I can somehow use the furthest away to sort from that? I'll look into that function :D Thanks!

Roflme

2012-11-14 19:27:24

I keep getting like coordinates are out of bounds setting them to 0 errors. Just switched computers because my laptop crashed so I can't post exact error :(