PDA

View Full Version : FindObjOre rewamp...



n3ss3s
11-17-2007, 09:04 AM
Well actually Im not sure can this be called FindObjOre anymore :p

But anyways, the reason I didn't post this in my thread in members section was
that I haven't given any 'big' functions to the Junior section (well this is 100 lines :) ) and if there are any a bit more advanced Junior Members that wanna learn about TPAs they can try and learn from this...

Also if someone feels like, is completely free to use this
as long as I get credit from these

Tested in Varrock East Mine
Tin rock
ColorToleranceSpeed(2)

Found the rock in 282ms, no world record but I didn't concentrate on the speed so much on this one.

Also the TPAFromBox takes 100ms, Wizzy should stuff something like that in his plugin.

Here you go -


program New;
{.include SRL/SRL.scar}
Var
Myx, Myy, MyOreColor, MyDirtColor: Integer;

Function CheckRockDirt(Var RefColor: Integer; Var rTPA: TPointArray; X, Y, Tol, HowMany, TheCTS, Dbg: Integer): Boolean;
Var
CTS, F, I, C, SmallTol: Integer;
TPA: TPointArray;
Begin
CTS := GetColorToleranceSpeed;
If Not CTS = TheCTS Then ColorToleranceSpeed(TheCTS);
FindColorsSpiralTolerance(X, Y, TPA, RefColor, X - 12, Y - 12, X + 12, Y + 12, Tol);
SmallTol := Tol;
For I := 0 To High(TPA) Do
Begin
C := GetColor(TPA[i].x, TPA[i].y);
If SimilarColors(C, RefColor, Tol) Then
Begin
F := F + 1;
If Round(Abs(C - RefColor)) < SmallTol Then
Begin
RefColor := C;
If Dbg = 1 Then Writeln('Found new RefColor!');
End;
SetArrayLength(rTPA, GetArrayLength(rTPA) + 1);
rTPA[High(rTPA)] := TPA[i];
End;
End;
If F >= HowMany Then
Result := True;
ColorToleranceSpeed(CTS);
End;

Procedure TPAFromBox(Var TPA: TPointArray; x1, y1, x2, y2: Integer);
Var
W, H, I, L, WD, HD: Integer;
Begin
WD := x2 - x1;
HD := y2 - y1;
L := (WD + 1) * (HD + 1);
SetArrayLength(TPA, L);
For W := x1 To x2 Do
For H := y1 To y2 Do
Begin
TPA[i] := IntToPoint(W, H);
I := I + 1;
End;
End;

Function OreColorsTPA(Var OreColor: Integer; Tol, TheCTS: Integer; TPA: TPointArray): Integer;
Var
I, CTS, C, X, Y: Integer;
colPoints: TPointArray;
Colors: TIntegerArray;
Begin
CTS := GetColorToleranceSpeed;
If Not CTS = TheCTS Then ColorToleranceSpeed(TheCTS);
MiddleTPAEx(TPA, X, Y);
TPAFromBox(colPoints, X - 12, Y - 12, X + 12, Y + 12);
Colors := GetColors(colPoints);
For I := 0 To High(colPoints) Do
If SimilarColors(Colors[i], OreColor, Tol) Then
Result := Result + 1;
ColorToleranceSpeed(CTS);
End;

Function FindObjNewOre(Var OreX, OreY: Integer; Var Color, DirtColor: Integer; Tol, DirtTol, Count, CTS: Integer): Boolean;
Var
Veins: Array of TPointArray;
rTPA, rPts: TPointArray;
TheCTS, C: Integer;
TP: TPoint;
Begin
TheCTS := GetColorToleranceSpeed;
If Not TheCTS = CTS Then ColorToleranceSpeed(CTS);
MA := GetSystemTime;
FindColorsSpiralTolerance(MSCX, MSCY, rTPA, Color, MSX1, MSY1, MSX2, MSY2, Tol);
Veins := SplitTPAEx(rTPA, 2, 2);
SetArrayLength(rTPA, GetArrayLength(Veins));
For C := 0 To High(rTPA) Do
Begin
rTPA[c] := MiddleTPA(Veins[c]);
If CheckRockDirt(DirtColor, rPts, rTPA[c].x, rTPA[c].y, DirtTol, 30, CTS, 2) Then
Begin
If OreColorsTPA(Color, Tol, Cts, rPts) >= Count Then
Begin
TP := MiddleTPA(rPTs);
MMouse(TP.x, TP.y, 2, 2);
If IsUpTextMulti('ine', 'Mine', 'ocks') Then
Begin
Result := True;
GetMousePos(OreX, OreY);
Break;
End;
End;
End;
End;
ColorToleranceSpeed(TheCTS);
End;

begin
SetupSRL;
MyOreColor := 7698047;
MyDirtColor := 1592925;
If FindObjNewOre(MyX, MyY, MyOreColor, MyDirtColor, 12, 12, 5, 2) Then
MMouse(MyX, MyY, 2, 2);
end.


EDIT: Worked for me without problem without using the uptext
(well it moved to a real rock on the first attempt so...)
but I put it there so people feel safer...

EDIT EDIT: I should use this in my VEM lol...

EDIT EDIT EDIT: I took out the re-coloring in OreColorsTPA, but anyone who can make a HelloWorld can put it back...

Santa_Clause
11-17-2007, 09:10 AM
Genius! All I can say.

n3ss3s
11-17-2007, 09:12 AM
lol thanks :D

I want some comment from devs or something, I always see them or Boreas view my threads for about 5 minutes, and not post :p

(darn leechers! :p jks)

ShowerThoughts
11-17-2007, 09:18 AM
im so jeaulous

n3ss3s
11-17-2007, 09:39 AM
So you made one last spam? :D

Dumpin
11-17-2007, 09:44 AM
So you made one last spam? :D

nice 11 posts for 3k post =P

Awsome ;o you are the SeCks at Scripting :|

n3ss3s
11-17-2007, 09:46 AM
Haha thanks

And yeah, I'll get my 3rd millenium today :)

@Nielsie: Post?

Peek to Nielsie's lab

___

| :stirthepot: |
___

ShowerThoughts
11-17-2007, 09:47 AM
lol thanks :D

I want some comment from devs or something, I always see them or Boreas view my threads for about 5 minutes, and not post :p

(darn leechers! :p jks)

i see nielsie vieuwing ^^

nielsie95
11-17-2007, 09:47 AM
OreColorsTPA is a CountColorTolerance?

How does it work on old rocks? :)

n3ss3s
11-17-2007, 09:48 AM
Its made for new rocks, and nah, no it isnt :p

ShowerThoughts
11-17-2007, 09:49 AM
OreColorsTPA is a CountColorTolerance?

How does it work on old rocks? :)


Its made for new rocks, and nah, no it isnt :p

teach it him n3ss3s :p btw, forgot to say nice function

The Claw
11-17-2007, 09:51 AM
It looks like one to me

ShowerThoughts
11-17-2007, 09:53 AM
It looks like one to me


man you avy its so burning my eyes :eek:

n3ss3s
11-17-2007, 09:53 AM
It looks like one to me

A nice function?

Yay thanks!

And thanks hermpie.

Btw, I made a decision, I am not going to finish CM4D.

I abandoned it a long time ago, but I'll post it in the members section so somebody can finish it, though mentioning me in the credits would be nice.
Its over 2k code =S

Now, I am making a VEM... Hopefully it'll end up released :)

nielsie95
11-17-2007, 09:54 AM
EDIT: Wow, this thread is going fast..

@N3ss3s: "no it isnt"

Oh really? :p

Well, you can speed it up by using a CountColorTolerance.
And you could use GetColors in CheckRockDirt + you could do this:


SetArrayLength(rTPA, GetArrayLength(Veins));
For I := 0 To High(Veins) Do
rTPA[i] := MiddleTPA(Veins[i]);


in the loop ;)

The Claw
11-17-2007, 09:54 AM
A nice function?

Yay thanks!

lolwut? I meant it looks like a CountColorsTolerance, lol. ;)

n3ss3s
11-17-2007, 10:03 AM
Go home claw :p Jks

Nielsie, why do I need it in the loop, it needs to be done only once..

I actually didn't see the CountColorTolerance, should update if I wasnt too lazy :p

EDIT: 6 posts till 3k

nielsie95
11-17-2007, 10:06 AM
Because it would be faster.. ;)
You first get all the middles, and when one of them is a rock you break out of the loop so you don't need the other ones :p
You can better do one MiddleTPA a time so it doen't do unneeded work?

n3ss3s
11-17-2007, 10:08 AM
Hey that makes sence, thanks!

ShowerThoughts
11-17-2007, 10:21 AM
i posted on your thread n3ss3s (no not this one :p)

n3ss3s
11-17-2007, 01:14 PM
Rofl, hermpie is banned, propably for spam.

Anyone knows??

Gotta go see the General News!
EDIT: 0mg 3millenium1!!!!

EDIT EDIT: Oh, for request...

rogeruk
11-17-2007, 04:27 PM
Rofl, hermpie is banned, propably for spam.

Anyone knows??

Gotta go see the General News!
EDIT: 0mg 3millenium1!!!!

EDIT EDIT: Oh, for request...

Nice revamp :D. Gonna try it later if i get a chance

//oftopic He left and wanted to be banned.

Dumpin
11-17-2007, 05:48 PM
Nice revamp :D. Gonna try it later if i get a chance

//oftopic He left and wanted to be banned.

temp ban :P for like 1 month... :)

I hope hermpie won't suicide because he can't spam ;o