SRL Archive - SRL Archives

MMtoMS


Special Ed

2007-04-16 16:19:01

I've developed a Function in which all you do is put in the coordinates of an object on the Minimap (tree,rock,ect using FindDTM or something) and It will return the coordinates of the Item on the Main Screen. Also returns true if the object is found in case you want to use it for rightclick, leftclick, mining, ect also works well with UpText, to double check. Make sure you have your camera at the highest angle! It has hit its' target 99% of the time for me since I've worked out the bugs, If you find some more please tell me!

Note: if your using a DTM make the parent point as close to the top of the DTM as possible, it will make to MMtoMS more accurate.

FeedBack

[1] Did It Work?
[2] Problems you noticed.
[3] Incorrect measurements.
[4] Any other thoughts / ideas.

Things Its been Tested With

[1] Tree's
[2] Rock's
[3] People [White Dot]
[4] Items [White Dot]

Known Problems

[1] First Problem: Gets Less Accurate farther away from Center [Working on it]

EDIT: Camera Must be at highest angle.

*NEW* Version 1.5

// Credits to nielsie95 for the conversion idea.
function MMtoMS(MMX, MMY :integer; var x, y :integer):boolean;
var
XX,YY:integer;
Ptx,Pty:extended;
begin
XX:= (MMX - 647);
YY:= (MMY - 84);
Ptx:= (XX * 9.25);
Pty:= (YY * 9.25);
if(Pty < 0)then Pty:= (Pty + (-Pty / 4)) else
x:= Trunc(259.5 + Ptx);
y:= Trunc(170.5 + Pty);
if((MMX < 621) or (MMX > 672))then Result:= false else
if((MMY < 66) or (MMY > 102))then Result:= false else
if((x < 4) or (x > 515))then Result:= false else
if((y < 4) or (y > 337))then Result:= false else
Result:= true;
end;

Smartzkid

2007-04-16 16:25:38

heey…amazing if it works

I'll have to try it out!

Special Ed

2007-04-16 16:34:08

It's been working for me so far even today…

Things I've gotten it to work with…

Trees
Rocks
People [White Dot]
Testing - Items [Red Dot]
Testing - Creatures [Yellow Dot]

Ruroken

2007-04-16 17:38:02

:)

I was making one of these…

Sopped though.

Special Ed

2007-04-16 17:46:33

Any thoughts on it / feedback?

Ruroken

2007-04-16 19:11:41

Yeah…

Does it compensate for the MM skewing?

Special Ed

2007-04-16 19:44:10

What now? You mean when the Minimap turns, or what? I think I could make it use FindBitmapRotationIn right?

lolpie

2007-04-16 19:58:46

Will this work well for walking to certain places?

Markus

2007-04-17 05:10:11

This is a actually great!
Will test this ASAP! This will make it much easier for me to find some RC altars once I created the right bitmap of the MM.

Ruroken

2007-04-17 07:31:36

From: Special Ed
What now? You mean when the Minimap turns, or what? I think I could make it use FindBitmapRotationIn right?


Right, but the MM stops corresponding with the MS after a while….you are gonna have to be good at the maths :p

Special Ed

2007-04-17 17:01:45

From: Ruroken
Right, but the MM stops corresponding with the MS after a while….you are gonna have to be good at the maths :p


Really? I hadn't noticed that changes… You mean to tell me that the minimap changes all of the trees/rocks/players/ect all the time?

It shouldn't matter whether or not the minimap changes that just depends on the bitmap… I could just make it use FindDeformedBitmapRotationIn or whatever… then it wouldn't ever not find it, but it will always stay the same measurements, those have to be static.

Also I was thinking of using degrees in version 2 so instead of having x,y it would find the degree that the obj is at like in RadialWalk and then use those measurements on the mainscreen, I just need to use the formula for the distance. Hopefully this will make it more accurate.

Sadly I had to reformat my computer so I need to re-download SRL / Scar ect… and I lost all my scripts because oh lucky me my disk got ran over with all my stuff on it…

nielsie95

2007-04-21 11:56:10

I really like this. I made some things with it :) :


Converts Coords from MM to MS (actually this is all you need)

function MMtoMS(var x, y :integer; tx, ty :integer):boolean;
var
XX,YY,Ptx,Pty:integer;
begin
XX:= Trunc(tx - MMCX);
YY:= Trunc(ty - MMCY);
Ptx:= Trunc(XX * 7.5);
Pty:= Trunc(YY * 7.25);
x:= (MSCX + Ptx);
y:= (MSCY + Pty);
if (x < MSX1) or (x > MSX2) then Result := False else
if (y < MSY1) or (y > MSY2) then Result := False else
result:= true;
end;

from this out you can make it work with Bitmaps, Dtm's, Colors, etc :)

Example:


function BMP(var x, y: integer; Bitmap, Tol: integer): Boolean;
var tx, ty: integer;
begin
tx := MMCX;
ty := MMCY;
if FindBitmapSpiralTolerance(Bitmap, tx, ty, MMX1, MMY1, MMX2, MMY2, Tol) then if MMtoMS(x, y, tx, ty) then Result := True;
end;

This will open the closest door (Could be improved):

program OpenDoor;
{.Include SRL/SRL.SCAR}
function MMtoMS(MMX, MMY :integer; var x, y :integer):boolean;
var
XX,YY:integer;
Ptx,Pty:extended;
begin
XX:= (MMX - 647);
YY:= (MMY - 84);
Ptx:= (XX * 9.25);
Pty:= (YY * 9.25);
if(Pty < 0)then Pty:= (Pty + (-Pty / 4)) else
x:= Trunc(259.5 + Ptx);
y:= Trunc(170.5 + Pty);
if((MMX < 621) or (MMX > 672))then Result:= false else
if((MMY < 66) or (MMY > 102))then Result:= false else
if((x < 4) or (x > 515))then Result:= false else
if((y < 4) or (y > 337))then Result:= false else
Result:= true;
end;


function GetDoorColor: integer; //Boreas
var Color,tmpx,tmpy,MinOfRange:integer;
Length206,Length217,Length233,Length241:integer;
Array206,Array217,Array233,Array241:array of tpoint;
RangeOfOthers206,RangeOfOthers217,RangeOfOthers233,RangeOfOthers241:integer;
tmpbool:boolean;
begin
for Color:=254 downto 200 do
begin
if not(((Color=206)or(Color=217)or(Color=233)or(Color=241))) then
begin
if FindColor(tmpx,tmpy,Color,mmx1,mmy1,mmx2,mmy2) then
begin
result:=Color;
tmpbool:=true;
end;
end;
if tmpbool then break;
end;
if not(tmpbool) then
begin
//writeln('its a drop dot color');
FindColorsTolerance(Array206,206,mmx1,mmy1,mmx2,mmy2,0);
Length206:=getarraylength(Array206);
FindColorsTolerance(Array217,217,mmx1,mmy1,mmx2,mmy2,0);
Length217:=getarraylength(Array217);
FindColorsTolerance(Array233,233,mmx1,mmy1,mmx2,mmy2,0);
Length233:=getarraylength(Array233);
FindColorsTolerance(Array241,241,mmx1,mmy1,mmx2,mmy2,0);
Length241:=getarraylength(Array241);
RangeOfOthers206:=max(Length233,max(Length217,Length241))-min(Length233,min(Length217,Length241));
RangeOfOthers217:=max(Length233,max(Length206,Length241))-min(Length233,min(Length206,Length241));
RangeOfOthers233:=max(Length206,max(Length217,Length241))-min(Length206,min(Length217,Length241));
RangeOfOthers241:=max(Length233,max(Length217,Length206))-min(Length233,min(Length217,Length206));
MinOfRange:=min(RangeOfOthers206,min(RangeOfOthers217,min(RangeOfOthers233,RangeOfOthers241)));
case MinOfRange of
RangeOfOthers206: result:=206;
RangeOfOthers217: result:=217;
RangeOfOthers233: result:=233;
RangeOfOthers241: result:=241;
end;
end;
end;

Function OpenMMDoor: Boolean;
var fx, fy, tx, ty, DoorColor, i, ci: integer; Doors: TPointArray;
begin
DoorColor := GetDoorColor;
if DoorColor < 1 then Exit;

FindColorsTolerance(Doors, DoorColor, 623, 61, 673, 111, 0)
for i := 0 to GetArrayLength(Doors) - 1 do
begin
if (Distance(Doors[ci].x, 0, Doors[i].x, 0) >= 4) and
(Distance(0, Doors[ci].y, 0, Doors[i].y) >= 4) then ci := i else
begin
Doors[i].x := 0;
Doors[i].y := 0;
end;
end;

for i := 0 to GetArrayLength(Doors) - 1 do
begin
if (Doors[i].x <> 0) then if MMtoMS(Doors[i].x, Doors[i].y, tx, ty) then
begin
//WriteLn('MMx: '+IntToStr(Doors[i].x)+' MMy: '+IntToStr(Doors[i].y)+' MSx: '+IntToStr(tx)+' MSy: '+IntToStr(ty));
if FindObjEx(fx, fy, 'Door', tx -30, ty -45, tx +30, ty +45, 1791857, 20, 12, 12, 150, False) then
begin
if IsUpText('Close') then
begin
WriteLn('Door was already open');
Result := False;
Exit;
end else
if IsUpText('Open') then
begin
WriteLn('Opening Door..');
GetMousePos(tx, ty);
Mouse(tx, ty, 0, 0, True);
Result := True;
Flag;
Wait(2500 +Random(500));
Exit;
end
end
end;
end;
end;

begin
setupsrl;
ActivateClient;
OpenMMDoor;
end.

Special Ed

2007-04-21 12:18:08

Ohh I guess that would make sense… lol I've been working on it and I think I've gotten a more stable formula, will post soon.

nielsie95

2007-04-21 13:28:55

Ohh I guess that would make sense…

What do you mean with that :p?

Special Ed

2007-04-21 13:32:32

Oh, I meant that it makes sense just to use it as a converter rather than have it specific to DTM's or Bitmaps or whatever. I thought that was a great idea, so here's my new one, it works a bit better I think… XD

// Credits to nielsie95 for the conversion idea.
function MMtoMS(MMX, MMY :integer; var x, y :integer):boolean;
var
XX,YY:integer;
Ptx,Pty:extended;
begin
XX:= (MMX - 647);
YY:= (MMY - 84);
Ptx:= (XX * 9.25);
Pty:= (YY * 9.25);
if(Pty < 0)then Pty:= (Pty + (-Pty / 4)) else
x:= Trunc(259.5 + Ptx);
y:= Trunc(170.5 + Pty);
if((MMX < 621) or (MMX > 672))then Result:= false else
if((MMY < 66) or (MMY > 102))then Result:= false else
if((x < 4) or (x > 515))then Result:= false else
if((y < 4) or (y > 337))then Result:= false else
Result:= true;
end;

nielsie95

2007-04-21 14:16:38

Nice! Tested it really quickly and I think it's more accurate! :)
I shall edit my DoorOpener so that it works with your new formula :)

Special Ed

2007-04-21 14:26:02

Awesome, I really hope that Boreas or someone checks this out I'm sure that they'd have some good input on this.

Boreas

2007-04-21 14:58:29

I just glanced and it looks good. I'll do some testing tonight or tomorrow.

Btw, nielsie check out Doors, link in sig.

Special Ed

2007-04-21 15:02:25

Wow… was that pure coincidence or do you only post when someone says your name?

Mutant Squirrle

2007-04-21 15:56:14

hahaha maybe if i say boreas again he'll pop back over here :D

Boreas

2007-04-21 16:17:30

Huh? How did I get here? I was just looking at an app and now I'm here, wtf?

Special Ed

2007-04-21 16:22:16

Anyways.. has anyone gotten around to testing it yet?

Bobarkinator

2007-04-21 18:20:43

[Offtopic]He's got alerts for any post containing "boreas"[/Opptopic]

Great, script I want to test and use. This will be cool. It's stuff like this that advances scar so much.

SKy Scripter

2007-04-21 18:33:11

this could be useful i just dont see how it would work…

Special Ed

2007-04-21 20:52:46

ORLY? Lol… that would explain a lot… well i know what to do when I need BOREAS!

So… has anyone tested it other than nielsie? Because its hard to fix bugs if you can't find any. XD

@Sky : It's not that hard to make it work, you just get the dimensions of the mainscreen and what you can see on your mainscreen that corresponds with the minimap and then you just find the ratio of distances on the minimap compared to the mainscreen.

nielsie95

2007-04-22 05:39:05

@Boreas: *Hopes he reads this, lol* Why did I have to take a look in Doors (not that I didn't read it :p)? My procedure just tries to open the closest door with MMtoMS. Is there a similar funtion in DoorProfiles?

Markus

2007-04-26 09:26:19

Ok, I've tested it, and this is really great! Maybe this is usefull for Lefamasters Rune Abuse or something…

Smartzkid

2007-04-28 15:47:33

I think I'm gonna try to make an axehead finder with this….

Special Ed

2007-04-29 21:58:42

Hey if your going to use it to find items on the ground it may or may not work… I've gotten it to pick up some items sometimes but it doesn't 100% of the time, I just got back for jamaica so I'll be continuing my work in this now. XD, Also any suggestions yet?