SRL Archive - SRL Archives

MMFinding.scar


Naike

2009-07-03 00:27:46

My latest project ;)
Thanks to Home for the idea.

I explain the "main" function called FindObjectsFromMM.. Depending on the parameters it will get the dots from Minimap. Valid ones are NPCs, Players or Items(It can find one, two or all three of them). When it finds them it creates a nice box of 150*150 pixels around all the items and searches for the colors/tol thats been given on the mainscreen. At the end it hovers these points searching for the giving uptext, if it's found it results true and wolhaa! You found a object using the MM to narrow down your search area ;)

Example of usage:

FindObjectsFromMM(x, y, ['item'], ['eather'], [12106177], 10);

would search for a feather…

Note: Needs high angle.

Hope you like it.


//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ยป Minimap finding Routines --//
//-----------------------------------------------------------------//
// * Function MMToMS(MM: TPoint): TPoint; // * by N1ke! (Thanks to Special Ed for insparation)
// * Function MMToMSBox(MM: TPoint; Space: Integer): TBox; // * by N1ke!
// * Function FindObjectsMM(var X, Y: integer; MM: TPointArray; UpTexts: TStringArray; Colors: TIntegerArray; Tol: Integer): Boolean; // * by N1ke!
// * Function FindObjectMM(var X, Y: integer; MM: TPoint; UpText: String; Color: Integer; Tol: Integer): Boolean; // * by N1ke!
// * Function FindObjectsFromMM(var X, Y: Integer; Kind: TStringArray; UpTexts: TStringArray; Colors: TIntegerArray; Tol: Integer): Boolean; // * by N1ke!
// * Function FindObjectFromMM(var X, Y: Integer; Kind: String; UpText: String; Color: Integer; Tol: Integer): Boolean; // * by N1ke!
//-----------------------------------------------------------------//

{*******************************************************************************
Function MMToMS(MM: TPoint): TPoint;
By: N1ke!
Description: Turns a Minimap point into a close MS point.
*******************************************************************************}
Function MMToMS(MM: TPoint): TPoint;
var
X, Y: Integer;
Dis: TPoint;
begin
X := ((MM.X - 647));
Y := ((MM.Y - 84));

Dis := Point( (MMCX - MM.X)*-1, (MMCY - MM.Y)*-1);
Result := Point(Round((259.5 + X)+ Dis.X*10), Round((170.0 + Y)+ Dis.Y*6.5));

If Not IntInBox(Result.X, Result.Y, IntToBox(MSX1, MSY1, MSX2, MSY2))then
Result := Point(-1, -1);
end;

{*******************************************************************************
Function MMToMSBox(MM: TPoint; Space: Integer): TBox;
By: N1ke!
Description: Same as MMToMS but creates a TBox, it size depending on
given parameter(Space).
*******************************************************************************}
Function MMToMSBox(MM: TPoint; Space: Integer): TBox;
var
Cords: TPoint;
begin
Cords := MMToMS(MM);
Result := IntToBox(Cords.X-Space, Cords.Y-Space, Cords.X+Space, Cords.Y+Space);
end;

{*******************************************************************************
Function GetMMDotsTPA(Kind: TStringArray): TPointArray;
By: N1ke!
Description: Gets the a TPA of the all the dots on Minimap.
Valid kinds are
- npc/yellow
- item/red
- player/white
*******************************************************************************}
Function GetMMDotsTPA(Kind: TStringArray): TPointArray;
var
I, H: Integer;
TPA, tTPA: TPointArray;
begin
H := High(Kind);
For I:=0 to H do
begin
tTPA := GetMiniMapDots(Kind[I]);
Result := CombineTPA(Result, tTPA);
end;
end;

{*******************************************************************************
Function FindObjectsMM(var X, Y: integer; MM: TPointArray; UpTexts: TStringArray; Colors: TIntegerArray; Tol: Integer): Boolean;
By: N1ke!
Description: Finds multiplie objects using a MM cords to narrow down the used
search area.
*******************************************************************************}
Function FindObjectsMM(var X, Y: integer; MM: TPointArray; UpTexts: TStringArray; Colors: TIntegerArray; Tol: Integer): Boolean;
var
MSCords: TPoint;
TPA, tTPA: TPointArray;
I, II, H, HH, XX, YY: Integer;
ATPA: T2DPointArray;
begin
Result := False;

H := High(MM);
For I:=0 to H do
begin
MSCords := MMToMS(MM[I]);
If (MSCords.X = -1)then
Continue;
HH := High(Colors);
For II:=0 to HH do
begin
FindColorsTolerance(tTPA, Colors[II], MSCords.X-75, MSCords.Y-75, MSCords.X+75, MSCords.Y+75, Tol);
TPA := CombineTPA(TPA, tTPA);
end;
end;
ClearDoubleTPA(TPA);

If GetArrayLength(TPA) = 0 then
Exit;

ATPA := SplitTPA(TPA, 5);
SortATPAFrom(ATPA, Point(MSCX, MSCY));

H := High(ATPA);
For I:=0 to H do
begin
MiddleTPAEx(ATPA[I], XX, YY);
MMouse(XX, YY, 4, 4);
If WaitUptextMulti(UpTexts, 250+Random(100))then
begin
GetMousePos(X, Y);
Result := True;
Exit;
end;
end;
end;

{*******************************************************************************
Function FindObjectMM(var X, Y: integer; MM: TPoint; UpText: String; Color: Integer; Tol: Integer): Boolean;
By: N1ke!
Description: Same as FindObjectsMM, but only finds one.
*******************************************************************************}
Function FindObjectMM(var X, Y: integer; MM: TPoint; UpText: String; Color: Integer; Tol: Integer): Boolean;
begin
Result := FindObjectsMM(X, Y, [MM], [UpText], [Color], Tol);
end;

{*******************************************************************************
Function FindObjectsFromMM(var X, Y: Integer; Kind: TStringArray; UpTexts: TStringArray; Colors: TIntegerArray; Tol: Integer): Boolean;
By: N1ke!
Description: Finds dots on Minimap and searches for the object.
Valid kinds are
- npc/yellow
- item/red
- player/white
*******************************************************************************}
Function FindObjectsFromMM(var X, Y: Integer; Kind: TStringArray; UpTexts: TStringArray; Colors: TIntegerArray; Tol: Integer): Boolean;
var
I, H: Integer;
TPA: TPointArray;
begin
Result := False;
TPA := GetMMDotsTPA(Kind);
If GetArrayLength(TPA) = 0 then
Exit;
Result := FindObjectsMM(X, Y, TPA, UpTexts, Colors, Tol);
end;

{*******************************************************************************
Function FindObjectFromMM(var X, Y: Integer; Kind: String; UpText: String; Color: Integer; Tol: Integer): Boolean;
By: N1ke!
Description: Same as FindObjectsFromMM, but only looks for one.
*******************************************************************************}
Function FindObjectFromMM(var X, Y: Integer; Kind: String; UpText: String; Color: Integer; Tol: Integer): Boolean;
begin
Result := FindObjectsFromMM(X, Y, [Kind], [UpText], [Color], Tol);
end;

Home

2009-07-03 00:31:09

See Everyone! Me In the Idea thing! MEEE!
:):)
Good job man :) I knew that you can do it.. And yes i think this should be in SRL Include!
Once again! Good JOB!

Your Friend,
~Home

Gu3st...

2009-07-03 01:03:13

Only problem is that the compass angle is off by MANY degrees :/

MylesMadness

2009-07-03 01:05:39

After
TPA := CombineTPA(TPA, tTPA);
Do
ClearDoubleTPA(TPA);
Most of the points your finding will be duplicates. Anyway I picked up 1 coin on the ground with it, so its cool

Naike

2009-07-03 01:09:03

From: Zyt3x
Only problem is that the compass angle is off by MANY degrees :/

It still works as the Minimap rotates aswell…

From: MylesMadness
After
TPA := CombineTPA(TPA, tTPA);
Do
ClearDoubleTPA(TPA);
Most of the points your finding will be duplicates. Anyway I picked up 1 coin on the ground with it, so its cool


Ohh shit, my bad ^^ Thanks ;)

Gu3st...

2009-07-03 01:26:38

From: N1ke!
It still works as the Minimap rotates aswell…

Yeah but the compass rotation and the main screen rotation are different.

Naike

2009-07-03 01:29:16

Not by that much that this will miss it..

To prove my point I suggest you try the function out..

FindObjectsFromMM.

Gu3st...

2009-07-03 01:31:40

From: N1ke!
Not by that much that this will miss it..

To prove my point I suggest you try the function out..

FindObjectsFromMM.

Ok, I'll test it :)

EDIT: It worked 50% of the time, sometimes the item was clearly visible and the color was there but it still did not found it. The compass was directed at SE.

Naike

2009-07-03 02:20:01

What item did you use, and what tolerance?

also, having it at the last tile on the MS won't make it try..


Edit: Just tested it again, Zyt3x your doing something wrong.. as it's flawless for me.

Naum

2009-07-03 10:47:35

Looks good.
One thing:
Function FindObjectsFromMM(var X, Y: Integer; Kind: TStringArray; UpTexts: TStringArray; Colors: TIntegerArray; Tol: Integer): Boolean;
var
I, H: Integer;
TPA, tTPA: TPointArray;
begin
Result := False;

H := High(Kind);
For I:=0 to H do
begin
tTPA := GetMiniMapDots(Kind[i]);
TPA := CombineTPA(TPA, tTPA);
end;

If GetArrayLength(TPA) < 1 then
Exit;

Result := FindObjectsMM(X, Y, TPA, UpTexts, Colors, Tol);
end;

you don't need that first result:= false;, this is because SCAR sets the default boolean to false.

You can also do If Not GetArrayLength(Arr) Then, as SCAR recognizes 0's as false and 1's as true.

Sir R. M8gic1an

2009-07-03 11:00:30

From: NaumanAkhlaQ
Looks good.
One thing:
Function FindObjectsFromMM(var X, Y: Integer; Kind: TStringArray; UpTexts: TStringArray; Colors: TIntegerArray; Tol: Integer): Boolean;
var
I, H: Integer;
TPA, tTPA: TPointArray;
begin
Result := False;

H := High(Kind);
For I:=0 to H do
begin
tTPA := GetMiniMapDots(Kind[i]);
TPA := CombineTPA(TPA, tTPA);
end;

If GetArrayLength(TPA) < 1 then
Exit;

Result := FindObjectsMM(X, Y, TPA, UpTexts, Colors, Tol);
end;

you don't need that first result:= false;, this is because SCAR sets the default boolean to false.

You can also do If Not GetArrayLength(Arr) Then, as SCAR recognizes 0's as false and 1's as true.


It's fine as it is, and it's good practice to initialize the result.

GJ mate.

~RM

Gu3st...

2009-07-03 12:18:05

From: N1ke!
What item did you use, and what tolerance?

also, having it at the last tile on the MS won't make it try..


Edit: Just tested it again, Zyt3x your doing something wrong.. as it's flawless for me.

That explains it, it was on one of the tiles at the end of the MS.

Markus

2009-07-03 12:34:18

you don't need that first result:= false;, this is because SCAR sets the default boolean to false.

Runme:

program ProofNaumanIsWrong;
function CountItems : integer ;//Something similar to this actually happened with CountItems, took over two years before we noticed it
var
TestArray : array of boolean;
i : integer;
begin
TestArray := [false, false, true, false, true, true];
for i := 0 to high(testarray) do
if testarray[i] then
inc(result);
end;
var hoi : integer;
begin
repeat
hoi := countitems;
writeln(inttostr(hoi));
wait(100);
until false;
end.
Ofcourse this isn't with booleans but with integers, but the same thing can happen with booleans.
And no it' s not a bug, it's a feature.

Gu3st...

2009-07-03 13:02:29

From: Da 0wner
Runme:
Code:
[LEFT]program ProofNaumanIsWrong;
function CountItems : integer ;//Something similar to this actually happened with CountItems, took over two years before we noticed it
var
TestArray : array of boolean;
i : integer;
begin
TestArray := [false, false, true, false, true, true];
for i := 0 to high(testarray) do
if testarray then
inc(result);
end;
var hoi : integer;
begin
repeat
hoi := countitems;
writeln(inttostr(hoi));
wait(100);
until false;
end.
[/LEFT]

Ofcourse this isn't with booleans but with integers, but the same thing can happen with booleans.
And no it' s not a bug, it's a feature.


What exactly makes him wrong? Explain.
Each time you run the function the result adds up. Common sense says that each time it will only result 3, but it actually results 3 * EachTimeRun, so if you run this function 3 times then it would result 9.

Markus: I didn't know about that :O
That is impressive…

EDIT: Gah, all the posts are mucked up thanks to our beloved markus who had a in his post >_<"

Da 0wner

2009-07-03 13:03:51

From: Zyt3x
What exactly makes him wrong? Explain.

Each time you run the function the result adds up. Common sense says that each time it will only result 3, but it actually results 3 * EachTimeRun, so if you run this function 3 times then it would result 9.

Markus: I didn't know about that :O
That is impressive…

Yes, I just saw that before you told me :D.

I thought he was incrementing or something :p.

ShowerThoughts

2009-07-03 13:23:55

What's up with the quotes?

Btw, Naum the script would mess up badly, since it counts up like everyone said.
I mean the variable can't just be emptied sometime(Without doing so), that would be very inefficient.

Da 0wner

2009-07-03 13:27:59

Markus started the quotes being retarded.

He has a in his message without a
:p.

(on purpose :D)

Naum

2009-07-03 19:43:43

From: Markus
you don't need that first result:= false;, this is because SCAR sets the default boolean to false.
Runme:

program ProofNaumanIsWrong;
function CountItems : integer ;//Something similar to this actually happened with CountItems, took over two years before we noticed it
var
TestArray : array of boolean;
i : integer;
begin
TestArray := [false, false, true, false, true, true];
for i := 0 to high(testarray) do
if testarray[i] then
inc(result);
end;
var hoi : integer;
begin
repeat
hoi := countitems;
writeln(inttostr(hoi));
wait(100);
until false;
end.
Ofcourse this isn't with booleans but with integers, but the same thing can happen with booleans.
And no it' s not a bug, it's a feature.


From: Hermen
What's up with the quotes?

Btw, Naum the script would mess up badly, since it counts up like everyone said.
I mean the variable can't just be emptied sometime(Without doing so), that would be very inefficient.


Markus, I was pointing out that for his case, for that particular function:

program Proof_that_I_am_right;
{.Include SRL/SRL.Scar}

Var x, y : Integer;

Function A : Boolean;
Begin
If Result Then
Writeln('I am wrong')
Else
WriteLn('I am right');
End;

begin
SetupSRL;
A;
end.

It is set to false, also I never mentioned that it was a bug.

Also Hermen did you even read the post? Furthemore, he calls:

Result := FindObjectsMM(X, Y, TPA, UpTexts, Colors, Tol);
At the end of the function, if it does not find it then it is set to false, which is fine.
Its the same as doing:
Function GESellMenu: boolean;
begin
if not InGE then exit;
Result := (GetColor(187, 73) = 45055); //
end;
@Rasta: I'm not saying it's not good practice to initialize a result, but it is not really needed in that case.

Naike

2009-07-03 22:44:20

SCAR happends to bug up sometimes..
Markus got some good examples ;)

afaik 60% of all the SRL functions starts with Result := False;

Da 0wner

2009-07-03 23:00:07

As he said, it's not a bug. It is a feature :p.

Naum

2009-07-03 23:30:25

From: Da 0wner
As he said, it's not a bug. It is a feature :p.


It is a feature put in for us to use ;)

Da 0wner

2009-07-03 23:36:13

Well duh…

Da 0wner

2009-07-03 23:42:25

Of course you would use it if it is a feature………

EvilChicken!

2009-07-04 04:19:39

From: Markus
you don't need that first result:= false;, this is because SCAR sets the default boolean to false.

[…]

Ofcourse this isn't with booleans but with integers, but the same thing can happen with booleans.
And no it' s not a bug, it's a feature.


.. weren't you telling me otherwise some time ago? D:
Something about there being a bug in SCAR which wouldn't default the result to false under special circumstances..?


Anyway, great job on this, Nicklas. I've seen several threads on this issue, and I have to admit that I'll be really impressed if your formulas turn out to be more accurate that the ones presented on the other threads.

You really deserve a cookie .. e__e

Naum

2009-07-04 15:37:01

From: Da 0wner
Of course you would use it if it is a feature………


Exactly..

Anyway, how would anyone rate the usefulness of this. It's very useful in my thoughts (it's not often i say that). Great for picking up cowhides without confuzzle.
I vouch it should be added to SRL.

Gu3st...

2009-07-04 15:57:00

From: NaumanAkhlaQ
Exactly..

Anyway, how would anyone rate the usefulness of this. It's very useful in my thoughts (it's not often i say that). Great for picking up cowhides without confuzzle.
I vouch it should be added to SRL.

I vote yes :)
Very useful indeed!