1. ## MS Grid system

What can this be used for?
• Main screen click walking.
• Item tracking
• MMtoMS (inaccurate atm, but close)

Shown above is the mid points of GridCoords and a box around it (example in GridBox).

Assuming you are facing at near perfect 0, 90, 180, 270 degrees and the ground is level this will get the mid point of the tile on main screen at high angle.

Point(0, 0) is on Character location (Grid coords example in code below). If point isn't in MSBox then the result is Point(-1, -1).

The Mini-Map is too distorted to get perfect position of what tile that grid is on. But I gave it a rough estimate and threw it in, its fairly accurate.

Simba Code:
program new;{$i srl/srl/misc/Smart.simba}{$i srl/srl.simba}{$i srl/srl/misc/paintsmart.simba} Function GridCoords(GridPoint: TPoint): TPoint;var Yh: Extended;begin Yh := Abs((GridPoint.y+0.0) + 6.0); Result.x := Round(259.5 + ((GridPoint.x+1.0)*38.0/(45.7-(Yh/9.0*12.8))) * 38.0); Result.y := Round(178.5 + (GridPoint.y+0.0) * (36.0 + ((GridPoint.y+0.0)*37.0)/25.0)); if not PointInBox(Result, MSBox) then Result := Point(-1, -1);end;Function MMToGrid(x, y: integer): TPoint;//Still needs workbegin Result := Point(Round((x-626.5)/4.2), Round((y-84.5)/4.2));end;Function MMtoMSGrid(x, y: integer): TPoint;begin Result := GridCoords(MMtoGrid(x, y));end;Function GridBox(GridPoint: TPoint): TBox;//19x17 box around mid point (Just an example)var T: TPoint;begin T := GridCoords(GridPoint); Result := IntToBox(T.x-10, T.y-8, T.x+8, T.y+8);end;var x, y: integer; T: TPoint;begin Smart_Server := 1; Smart_Members:= true; Smart_Signed := true; Smart_SuperDetail := false; SetupSRL; SMART_ClearCanvas; for x := -8 to 8 do for y := -6 to 3 do begin T := GridCoords(Point(x, y)); if (T.x = -1) then Continue; SMART_DrawBoxEx(False, GridBox(Point(x, y)), clRed); SMART_DrawDotsEx(False, [GridCoords(Point(x, y))], clBlue); end; Writeln(MMtoGrid(632, 65)); Writeln(MMtoMSGrid(651, 65));end. This is Grid 16 with polygon boxes showing tiles as well as the MMtoMS formula it uses. (which is basically what Grid 16 is) Its the most accurate MMtoMS I think we can manage right now. Note it returns the TPoint position on the ground. (This is assuming all tiles on MM are 4x4) Example code below. Simba Code: program new;{$i srl/srl/misc/Smart.simba}{$i srl/srl.simba}{$i srl/srl/misc/paintsmart.simba}    Function GridCoords16(Grid16: TPoint): TPoint;var  Yh, yMod: Extended;begin  yMod := 36.0;  Yh := Abs((Grid16.y+0.0) + yMod);  Result.x := Round(263.5 + ((Grid16.x)*9.75/(12.8-(Yh/yMod*3.15))) * 9.75);  Result.y := Round(182.0 + (Grid16.y+0.0) * (6.3 + ((Yh/yMod)*2.4)));  if not PointInBox(Result, MSBox) then    Result := Point(-1, -1);end;Function MMtoMSG16(x, y: integer): TPoint;begin  Result := GridCoords16(Point(x-627, y-85));end; procedure DrawGridBox(PT: TPoint; Color: integer);var  T: TPoint;  i: integer;  ATPA: T2DPointArray;begin  T := Point(PT.x*4, PT.y*4);  SetLength(ATPA, 4);  ATPA[0] := [GridCoords16(Point(T.x-2, T.y-2)), GridCoords16(Point(T.x+1, T.y-2))];  ATPA[1] := [GridCoords16(Point(T.x-2, T.y+1)), GridCoords16(Point(T.x+1, T.y+1))];  ATPA[2] := [GridCoords16(Point(T.x-2, T.y-2)), GridCoords16(Point(T.x-2, T.y+1))];  ATPA[3] := [GridCoords16(Point(T.x+1, T.y-2)), GridCoords16(Point(T.x+1, T.y+1))];  for i := 0 to 3 do  begin    if (ATPA[i][0].x = -1) or (ATPA[i][1].x = -1) then      Continue;    SMART_DrawLine(False, ATPA[i][0], ATPA[i][1], Color);  End;end;  var  x, y, i: integer;  T: TPoint;  npc: TPointArray;begin  Smart_Server := 1;  Smart_Members:= true;  Smart_Signed := true;  Smart_SuperDetail := false;  SetupSRL;  //SaveScreenshot(AppPath+'Grid shit 3.bmp');  SMART_ClearCanvas;  for x := -36 to 36 do    for y := -30 to 14 do    begin      T := GridCoords16(Point(x, y));      if (T.x = -1) then        Continue;      //SMART_DrawBoxEx(False, GridBox(Point(x, y)), clRed);      if (x = 0) and (y = 0) then        SMART_DrawDotsEx(false, [GridCoords16(Point(x, y))], clRed)      else        SMART_DrawDotsEx(false, [GridCoords16(Point(x, y))], clBlue);    end;  for x := -8 to 8 do    for y := -8 to 5 do     DrawGridBox(Point(x,y), clGreen);  npc := GetMiniMapDots('npc');  for i := 0 to high(NPC) do  Begin    T := MMtoMSG16(NPC[i].x, NPC[i].y);    SMART_DrawDotsEx(false, [T], clRed);    SMART_DrawBoxEx(False, IntToBox(T.x-2, T.y-2, T.x+2, T.y+2), clYellow);    SMART_DrawBoxEx(False, IntToBox(T.x-10, T.y-30, T.x+10, T.y+10), clBlue);  end;end.
Last edited by Narcle; 01-23-2012 at 09:18 PM.

2. OMG! awesome!

mind if i use this for a bird nest finder?

~shut

3. Wow this is awesome, nice job!

4. Originally Posted by Shuttleu
OMG! awesome!

mind if i use this for a bird nest finder?

~shut
Ja. I was planning on adding it to math.simba in SRL after I get a better MMtoMSGrid.

Edit:
I still have grid walking functions to add.

5. That's great for many things! Was waiting for something like that!
I'll take a deeper watch to it.

~onilika

6. Originally Posted by Narcle
Ja. I was planning on adding it to math.simba in SRL after I get a better MMtoMSGrid.

Edit:
I still have grid walking functions to add.
OMG ILU.. I'm going to use this in every script if its successful.. Of course all credit to you. And where did u get the formula for the MMToMS? Is it a new one or the one from the include? if its the one from the include this will also have a tolerance of 1 tile off right?

Oh and my last and final question.. the picture shows grids spaced apart like that, what about the boxes that are in-between the grid boxes? Going to be the next SPS?

P.S. This will be the first thread I watch lol.

7. I was talking to Naum a while back about developing a relative tiling system like this, just never got round to it with us both having A-levels. Very glad someone did it, though! Something that I was going to make an effort to create would be a way of detecting the pitch, then use the information on the pitch and rotation of the screen to get detailed coordinates at any screen angle and compass direction. The issue that I foresaw was that of tiles not all being flat, I guess this hasn't countered that problem just yet?

8. SRL Junior Member
Join Date
Dec 2011
Posts
497
Mentioned
0 Post(s)
Quoted
2 Post(s)
Originally Posted by ggzz
OMG ILU.. I'm going to use this in every script if its successful.. Of course all credit to you. And where did u get the formula for the MMToMS? Is it a new one or the one from the include? if its the one from the include this will also have a tolerance of 1 tile off right?

Oh and my last and final question.. the picture shows grids spaced apart like that, what about the boxes that are in-between the grid boxes? Going to be the next SPS?

P.S. This will be the first thread I watch lol.
The spaces are insignificant, so even if you press on that space, you'll end up in the square (grid thing) closest to the space you clicked the squares are the "tile".

Does that make any sense?

9. Originally Posted by momotron
The spaces are insignificant, so even if you press on that space, you'll end up in the square (grid thing) closest to the space you clicked the squares are the "tile".

Does that make any sense?
No.. because it states it can be used for item finding when completed.. what happens when an item is directly in between a space and ur mouse only hovers on those grid boxes.. Not all tiles are flat so of course items can be on those spaces.

10. so far its been working perfectly for my birds nest finder

~shut

11. This is cool! I love the math!

12. This is amazing!! Good work Narcle

13. Originally Posted by Richard
I was talking to Naum a while back about developing a relative tiling system like this, just never got round to it with us both having A-levels. Very glad someone did it, though! Something that I was going to make an effort to create would be a way of detecting the pitch, then use the information on the pitch and rotation of the screen to get detailed coordinates at any screen angle and compass direction. The issue that I foresaw was that of tiles not all being flat, I guess this hasn't countered that problem just yet?
Yeah Pitch would be difficult but I know it can be applied to the Compass and use it at any compass angle (I just didn't want to go into the math yet). Usually people always set scripts to be N, S, E or W.

Until we can map it out (hopefully via SPS) you could set a Height variable for that particular tile in a database of sorts.

This is just a very BASIC formula, then gives you a rough idea.

I have a lot more to add to this (hopefully).

I also have ideas to use this with ObjectDTM to map out the area, but I don't know how accurate in pixels it will be yet.
Last edited by Narcle; 01-22-2012 at 04:21 AM.

14. Ohhh this looks sexy! Great work!

15. I did something like this a while ago but using a perspective transformation.

I will create my own thread with the source as I don't want to hijack yours Narcle.

16. I use a much simpler version of this to pick up ground items in my roach killer.

17. Lovely. Code is Smexy.

I did something like this a while ago but using a perspective transformation.

I will create my own thread with the source as I don't want to hijack yours Narcle.
Ya w/e, i just want to see code. XD

Also I'm going to make a grid setup where each tile is a 4x4 (about the size in pixels of a tile on minimap). Then draw a polygon for the general area inside it.

19. Originally Posted by Narcle
Ya w/e, i just want to see code. XD

Also I'm going to make a grid setup where each tile is a 4x4 (about the size in pixels of a tile on minimap). Then draw a polygon for the general area inside it.
Sweet, we should try and combine our work. I'm going to try and make it a bit more robust. Atm, it takes a lot of fiddling for my one to look right. I want to be able to just plug in the values that you get when you type getcamerapos into the developer console. :P

20. My ghetto implementation of this..picks up all items.
Simba Code:
function MMMS(MM: TPoint): TPoint;//credit Home Var  X, Y :Extended;begin  X := (((MM.X - 626.5) * 9.81119354838709677419354838709677) + 258.531);  Y := (((MM.Y - 84.5) * 8.84193548387096774193548387096777) + 175.341);  Result := Point(Round(X), Round(Y));end;function GetSBox(P: TPoint): TBox;begin  if not LoggedIn then Exit;  Result := PointToBox(MMMS(Point(P.x - 2, P.y - 3)),    MMMS(Point(P.x + 3, P.y + 2)));end;procedure RemoveColorTPA(SB: TBox; var TPA: TPointArray; Col, Tol: Integer;  H, S: Extended);var  RTPA: TPointArray;  HM, SM: Extended;  CTS: Integer;begin  GetColorspeed2Modifiers(HM, SM);  CTS := GetColorToleranceSpeed;  SetColorspeed2Modifiers(H, S);  ColorToleranceSpeed(2);  if FindColorsTolerance(RTPA, Col, SB.X1, SB.Y1, SB.X2, SB.Y2, Tol) then    TPA := ClearTPAFromTPA(TPA, RTPA);  SetColorspeed2Modifiers(HM, SM);  ColorToleranceSpeed(CTS);end;procedure RemoveBadColors(SB: TBox; var TPA: TPointArray);var  CT1, CT2, CT3, CT4, CT5, CT6, CT7, CT8: array[0..1] of Integer;  HS1, HS2, HS3, HS4, HS5, HS6, HS7, HS8: array[0..1] of Extended;begin  CT1[0] := 3427197; CT1[1] := 18;//body  HS1[0] := 0.25;    HS1[1] := 0.75;//body  CT2[0] := 2637130; CT2[1] := 8;//legs  HS2[0] := 0.27;    HS2[1] := 1.37;//legs  CT3[0] := 2313556; CT3[1] := 13;//feet  HS3[0] := 0.19;    HS3[1] := 1.08;//feet  CT4[0] := 3233380; CT4[1] := 14;//wall  HS4[0] := 0.04;    HS4[1] := 0.50;//wall  CT5[0] := 3377517; CT5[1] := 13;//greenwall  HS5[0] := 0.03;    HS5[1] := 0.68;//greenwall  CT6[0] := 2503482; CT6[1] := 15;//switch  HS6[0] := 0.21;    HS6[1] := 0.20;//switch  CT7[0] := 855310;  CT7[1] := 1;//switchblack  HS7[0] := 16.67;   HS7[1] := 3.71;//switchblack  CT8[0] := 725785;  CT8[1] := 2;//tile  HS8[0] := 0.36;    HS8[1] := 1.53;//tile  RemoveColorTPA(SB, TPA, CT1[0], CT1[1], HS1[0], HS1[1]);  RemoveColorTPA(SB, TPA, CT2[0], CT2[1], HS2[0], HS2[1]);  RemoveColorTPA(SB, TPA, CT3[0], CT3[1], HS3[0], HS3[1]);  RemoveColorTPA(SB, TPA, CT4[0], CT4[1], HS4[0], HS4[1]);  RemoveColorTPA(SB, TPA, CT5[0], CT5[1], HS5[0], HS5[1]);  RemoveColorTPA(SB, TPA, CT6[0], CT6[1], HS6[0], HS6[1]);  RemoveColorTPA(SB, TPA, CT7[0], CT7[1], HS7[0], HS7[1]);  RemoveColorTPA(SB, TPA, CT8[0], CT8[1], HS8[0], HS8[1]);end;function FindDrop(var P: TPoint; var UT: String): Boolean;var  SB: TBox;  PP: TPoint;  FTPA, TTPA: TPointArray;  ATPA: T2DPointArray;  HM, SM: Extended;  i, Hi, CTS: Integer;begin  Result := False;  if not LoggedIn then Exit;  if not rs_OnMinimap(P.x, P.y) then Exit;  SB := GetSBox(P);  PP := MMMS(P);  P := Point(-1, -1);  GetColorspeed2Modifiers(HM, SM);  CTS := GetColorToleranceSpeed;  //get floor in area  SetColorspeed2Modifiers(0.05, 0.36);  ColorToleranceSpeed(2);  if not FindColorsTolerance(FTPA, 5468278, SB.X1, SB.Y1, SB.X2, SB.Y2, 14) then  begin    SetColorspeed2Modifiers(HM, SM);    ColorToleranceSpeed(CTS);    Exit;  end;  //get floor bounds and tpa  SB := GetTPABounds(FTPA);  if Debug then SMART_DrawBoxEx(True, SB, clPurple);  TTPA := TPAFromBox(SB);  //remove roach/floor colors from tpa  TTPA := ClearTPAFromTPA(TTPA, FTPA);  TTPA := ClearTPAFromTPA(TTPA, TPAFromBox(IntToBox(243, 143, 275, 182)));  if m_HPBar then    TTPA := ClearTPAFromTPA(TTPA, TPAFromBox(IntToBox(227, 121, 293, 149)));  RemoveBadColors(SB, TTPA);  SetColorspeed2Modifiers(HM, SM);  ColorToleranceSpeed(CTS);  //split tpa by 1  ATPA := SplitTPA(TTPA, 1);  Hi := High(ATPA);  if Hi < 0 then Exit;  //sort arrays  SortATPASize(ATPA, True);  for i := 0 to Hi do  begin    if Debug then    begin      SMART_DrawDotsEx(False, ATPA[i], clYellow);    end;    {if (PixelShift(GetTPABounds(ATPA[i]), 120) > 20) then    begin      m_Debug('Removing Item: PixelShift', False);      Continue;    end;}    if not InRange(Length(ATPA[i]), 10, 430) then    begin      m_Debug('Removing Item: Length', False);      Continue;    end;    P := RPDist(ATPA[i], 3);    MMouse(P.x, P.y, 0, 0);    Wait(150);    if WaitText(UT, ['alk here'], 150) then    begin      P := Point(-1, -1);      m_Debug('Removing Item: Uptext', False);      Continue;    end;    if Debug then    begin      SMART_DrawDotsEx(False, ATPA[i], clGreen);      SMART_DrawBoxEx(False, GetTPABounds(ATPA[i]), clBlue);    end;    Break;  end;  Result := PointInBox(P, MSBox);end;

21. An update.

(stupid net was out)

22. Looks extremely good, can't wait to try and use it for somthing

23. This might just make chin scripts near enough flawless to detect your own trap, like if you successfully put one down in 5,5.

24. Originally Posted by akonowns
This might just make chin scripts near enough flawless to detect your own trap, like if you successfully put one down in 5,5.
Its one reason I made it.

25. SRL Junior Member
Join Date
Dec 2007
Posts
288
Mentioned
4 Post(s)
Quoted
86 Post(s)
I want to be able to just plug in the values that you get when you type getcamerapos into the developer console. :P
This whole thing is really impressive but I think being able to just plug in the values would make it doubly as impressive :P

This has a lot of applications and I can't wait to see a more polished version of it all.