SRL Archive - SRL Snippets

MMToMS etc


ReadySteadyGo

2012-01-22 01:46:29


program new;
{$DEFINE SMART}
{$i SRL/SRL.simba}
{$i SRL/SRL/misc/paintsmart.simba}

const
TILE = 12;

type
TPoint3D = record
x, y, z: Extended;
end;

TRotation = TPoint3D;
ATPoint3D = Array of TPoint3D;

TMatrix = record
Data: Array of Extended;
end;

TScene = record
TilePosition, PlayerTile, CameraPosition: TPoint3D;
TileRotation, CameraRotation: TRotation;
end;

function Point3D(x, y, z: Extended): TPoint3D;
begin
Result.x := x;
Result.y := y;
Result.z := z;
end;

function Rotation(xpheta, ypheta, zpheta: Extended): TRotation;
begin
Result.x := xpheta;
Result.y := ypheta;
Result.z := zpheta;
end;

function Multiply_Point3D_Matrix3x3(p: TPoint3D; m: TMatrix): TPoint3D;
begin
Result.x := (m.Data[0] * p.x) + (m.Data[1] * p.y) + (m.Data[2] * p.z);
Result.y := (m.Data[3] * p.x) + (m.Data[4] * p.y) + (m.Data[5] * p.z);
Result.z := (m.Data[6] * p.x) + (m.Data[7] * p.y) + (m.Data[8] * p.z);
end;

procedure TranslatePoints3D(var p: ATPoint3D; v: TPoint3D);
var
Len, i: Integer;
begin
Len := Length(p);
for i := 0 to Len-1 do
p[i] := Point3D(p[i].x + v.x, p[i].y + v.y, p[i].z + v.z);
end;

function RotatePoints3D(Points: ATPoint3D; rp: TPoint3D; r: TRotation): Array of TPoint3D;
var
m: TMatrix;
Len, i: Integer;
begin
R.x := radians(R.x);
R.Y := radians(R.Y);
r.z := radians(R.z);
SetLength(m.Data, 9);
m.Data := [Cos(r.y)*Cos(r.z), -Cos(r.x)*Sin(r.z) + Sin(r.x)*Sin(r.y)*Cos(r.z), Sin(r.x)*Sin(r.z)+Cos(r.x)*Sin(r.y)*Cos(r.z),
Cos(r.y)*Sin(r.z), Cos(r.x)*Cos(r.z) + Sin(r.x)*Sin(r.y)*Sin(r.z), -Sin(r.x)*Cos(r.z)+Cos(r.x)*Sin(r.y)*Sin(r.z),
-Sin(r.y), Sin(r.x)*Cos(r.y), Cos(r.x)*Cos(r.y)];

Len := Length(Points);
SetLength(Result, Len);

TranslatePoints3D(Points, Point3D(-rp.x, -rp.y, -rp.z));
for i := 0 to Len-1 do
Result[i] := Multiply_Point3D_Matrix3x3(Points[i], m);
TranslatePoints3D(Result, rp);
end;

function PerspectiveProject(p: ATPoint3D; cPos:TPoint3D): TPointArray;
var
Len, i: Integer;
begin
Len := Length(p);
SetLength(Result, Len);
for i := 0 to Len-1 do
begin
if (p[i].z - cPos.z) < 1 then
begin
Result[i].x:= 0;
Result[i].y:= 0;
Exit;
end;
Result[i].x:= Round((p[i].x - cPos.x) * {((512/2) / Tan(33/2))}864 / (p[i].z - cPos.z));
Result[i].y:= Round((p[i].y - cPos.y) * {(512/2) / Tan(33/2)}864 / (p[i].z - cPos.z));
end;
end;

function ProjectTile(var x, y: Integer; s: TScene; DrawColor{-1 to not Draw}: Integer): Boolean;
var
_3DPoints: ATPoint3D;
_2DPoints: TPointArray;
Len, i: Integer;
MSBox: TBox;
tp: TPoint3D;
begin
if DrawColor = -1 then
Len := 2
else
Len := 6;

SetLength(_3DPoints, Len);
SetLength(_2DPoints, Len);

tp := s.TilePosition;

_3DPoints[0] := s.PlayerTile;
_3DPoints[1] := Point3D(tp.x + TILE/2, tp.y + TILE, tp.z + TILE/2); // Center of input Tile

if DrawColor <> -1 then
begin
_3DPoints[2] := Point3D(tp.x + TILE, tp.y + TILE, tp.z);
_3DPoints[3] := Point3D(tp.x, tp.y + TILE, tp.z);
_3DPoints[4] := Point3D(tp.x + TILE, tp.y + TILE, tp.z + TILE);
_3DPoints[5] := Point3D(tp.x, tp.y + TILE, tp.z + TILE);
end;

TranslatePoints3D(_3DPoints, Point3D(-TILE/2, -TILE/2, 0));

_3DPoints := RotatePoints3D(_3DPoints, _3DPoints[0], s.TileRotation);

_3DPoints := RotatePoints3D(_3DPoints, s.CameraPosition, s.CameraRotation);
_2DPoints := PerspectiveProject(_3DPoints, s.CameraPosition);

MSBox.X1 := MSX1;
MSBox.Y1 := MSY1;
MSBox.X2 := MSX2;
MSBox.Y2 := MSY2;

for i := 0 to Len-1 do
begin
_2DPoints[i].x := _2DPoints[i].x + {(511/2) + 4}260;
_2DPoints[i].y := _2DPoints[i].y + {(334/2) - 4}163;
if not PointInBox(_2DPoints[i], MSBox) then
begin
Result := False;
Exit;
end;
end;

if DrawColor <> -1 then
begin
SMART_DrawLine(False, _2DPoints[2], _2DPoints[3], DrawColor);
SMART_DrawLine(False, _2DPoints[4], _2DPoints[5], DrawColor);
SMART_DrawLine(False, _2DPoints[3], _2DPoints[5], DrawColor);
SMART_DrawLine(False, _2DPoints[2], _2DPoints[4], DrawColor);
end;

x := _2DPoints[1].x;
y := _2DPoints[1].y;
Result := True;
end;

function GetTile(var x, y: Integer; tx, tz: Integer; Draw: Boolean; Color: Integer): Boolean;
var
s: TScene;
begin
with s do
begin
PlayerTile := Point3D(TILE/2, 20 + TILE, (TILE*10) - 8 + TILE/2);
TilePosition := Point3D((tx*TILE)-(8*TILE), 23, (tz*TILE) + (2*TILE)-8);
TileRotation := Rotation(0, (Round(0-rs_GetCompassAngleDegrees)), 0);
CameraPosition := Point3D(0, -233, 0);
CameraRotation := Rotation(65, 0, 0);
end;
if (not Draw) then
Color := -1;
Result := ProjectTile(x, y, s, Color);
end;

function MMToMSTileEx(var x, y: Integer; MMx, MMy:Integer; Draw: Boolean; Color: Integer): Boolean;
var
p: TPoint;
begin
p := RotatePoint(Point(MMx, MMy), rs_GetCompassAngleRadians, MMCX, MMCY);
p.x := Floor((p.x - (MMCX - 33)) / 4.0);
p.y := 17- Floor((p.y - (MMCY - 37)) / 4.0);

Result := GetTile(x, y, p.x, p.y, Draw, Color);
end;

function MMToMSTile(var x, y: Integer; MMx, MMy: Integer): Boolean;
begin
Result := MMToMSTileEx(x, y, MMx, MMy, False, 0);
end;


procedure ProjectTiles;
var i, j, x, y: Integer;
begin
for i := 0 to 16 do
for j := 0 to 16 do
GetTile(x, y, i, j, True, clGray);
end;

function GetMMDotsOnMS2(WhatDot: String; ShowGrid:Boolean): TPointArray;
var
x, y, Len, i, c, Col: Integer;
p: TPointArray;
begin
if ShowGrid then
ProjectTiles;
p := GetMiniMapDots(WhatDot);

case LowerCase(WhatDot) of
'npc', 'n', 'yellow', 'y': Col := clYellow;
'item', 'i', 'red', 'r': Col := clRed;
'player', 'p', 'white', 'w': Col := clWhite;
'friend', 'f', 'green', 'g': Col := clFriend;
'team', 't', 'blue', 'b', 'cape': Col := clBlue;
end;

Len := Length(p);
SetLength(Result, Len);
c := 0;
for i := 0 to Len-1 do
if MMToMSTileEx(x, y, p[i].x, p[i].y, True, Col) then
begin
Result[i] := Point(x, y);
Inc(c);
end;
SetLength(Result, c);
end;

var x, y: Integer;
begin
ClearDebug();
Smart_Server := 1;
SetupSRL();
SMART_SetupDebug;
SMART_ClearCanvas;

GetMMDotsOnMS2('Red', True);
GetMMDotsOnMS2('White', False);
GetMMDotsOnMS2('Yellow', False);
end.

Main

2012-01-22 01:50:45

sweett, but does it has to be highest camera angle?

senrath

2012-01-22 01:53:10

Even with the one box being a bit off, that is really impressive. Good job.

ReadySteadyGo

2012-01-22 01:53:31

Yes, I could add lowest camera angle trivally, but unless anyone knows a way to work out the angles in between, they are not possible.

Thanks senrath, yes it could do with a bit of tweeking. I made it a while ago and just cleaned it up today. I haven't really had a chance to play around with it. :)

NZ John

2012-01-22 01:57:23

Top of image.. "meatspin.com"… What're you upto? lol

ReadySteadyGo

2012-01-22 02:00:59

ask #srl

Harry

2012-01-22 02:04:48

From: NZ John
Top of image..

Welcome to #SRL IRC.

Really neat. Basic autofighter PoC code with that would be a useful intermediate tutorial for newbies who want to make more accurate object findings based off the NPC dot.

Flight

2012-01-22 02:23:52

A bit off but I like where it's going. Really nice job. :) I want to see this improved.

Richard

2012-01-22 06:33:25

From: ReadySteadyGo
Yes, I could add lowest camera angle trivally, but unless anyone knows a way to work out the angles in between, they are not possible.

Thanks senrath, yes it could do with a bit of tweeking. I made it a while ago and just cleaned it up today. I haven't really had a chance to play around with it. :)


I'm currently working on something that can get the pitch. Might not be hugely reliable, relying on the character standing in a certain place etc.

This is great work, would you mind if I worked on this a bit? Science building on the shoulders of giants and all that.

Gu3st...

2012-01-22 07:09:14

Woah, that is near to perfect, ReadySteadyGo! I love it!

Home

2012-01-22 07:23:50

Please improve it more! Looks awsome!


~Home

loser69

2012-01-22 07:44:29

Wow looks neat.

nokkasiili

2012-01-22 08:44:26

Look like tileview from javabots very nice that you was able do that color

ReadySteadyGo

2012-01-22 09:54:33

Unfortunately, we are limited as to how accurate it can be, due to the 3 Camera views all being randomised slightly differently (MM, Compass, and MS). It can be improved slightly though. You can see in my screenshot that the FOV is ever so slightly off, ruining the perspective of the tiles closer to the viewer.

I need to find away to plug in information that I work out, rather than fiddling around to get it right. This is worked out with a UVN Camera system, so if I implement that to determine the camera position and pitch (rather than my current technique of fiddling with it almost manually), it will technically be perfect.

Thank you everyone for your comments, I will do my best to make this more accurate. Richard, of course, please go ahead.

Harry

2012-01-22 16:31:38

You could try that console command that gives your camera angle, and do some maths with that? Open dev console and type "help".

ReadySteadyGo

2012-01-22 16:40:28

Only problem is that I don't understand the output, the height seems to change a lot even without moving the compass or pitch. I'm assuming they use something along the lines of http://gra-phic.blogspot.com/2011/08/u-v-n-system.html

To get the values I currently use, I just used photo match in Google Sketch up, which is incredible. You can then use the ruby console to get information about the camera setup, but I must be botching something with my calculations because I can't replicate it exactly.

Shatterhand

2012-01-30 17:10:14

The picture looks cool, but could you give me some explanataion?

ReadySteadyGo

2012-01-31 12:33:07

Hi hunt3rx3

I have actually released a tutorial today which uses this. Check out http://villavu.com/forum/showthread.php?p=911890

If you were enquiring how it actually works, let me know and I'll write up an explanation.

Flight

2012-03-27 09:59:39

I'm bumping this. I personally think it should be added to the library. Anyways, if it's OK by you, RSG, I'll be using most of this in an Essence-Mining script.

Coh3n

2012-03-27 19:00:57

Doesn't the grid functions Narcle added a while back do the same thing?

Gu3st...

2012-03-27 19:39:09

From: Coh3n
Doesn't the grid functions Narcle added a while back do the same thing?
type
TPoint3D = record
x, y, z: Extended;
end;

This one uses a 3D engine for more accurate results, so no. Not the same thing

Narcle

2012-03-27 20:19:29

From: Zyt3x
type
TPoint3D = record
x, y, z: Extended;
end;

This one uses a 3D engine for more accurate results, so no. Not the same thing


Umm the Z axis is unknown so it can't be accurate, its just a guess. However his uses the compass so it can be used at more compass angles but doesn't mean its accurate. Same with mine its just a 'guess'.

ReadySteadyGo

2012-03-29 07:36:13

From: Flight
I'm bumping this. I personally think it should be added to the library. Anyways, if it's OK by you, RSG, I'll be using most of this in an Essence-Mining script.


Yes of course, please go ahead. :)

Adding to what Narcle said. Yeah if there is overly bumpy terrain it will not be able to account for this. I don't see why people shouldn't try this out though, I've got some rather accurate results with this, and although the camera does need to be at its highest point, it really allows the minimap information to be utilised at any angle.

It is also very fast. I have found it actually reduced the time searching for objects because it cuts down the possible locations of the object considerably.

There is also the potential to map out things that you know the height of, a table for instance (I used this when I was working on a Dungeoneer).

Flight

2012-03-29 07:50:18

From: ReadySteadyGo
There is also the potential to map out things that you know the height of, a table for instance (I used this when I was working on a Dungeoneer).


I was thinking about this as well. The higher an object, the further away from the center of the MS it would appear.

Yes it does give very accurate results. In my essence-miner I use this for searching for the exit portals in the mine. I grab the teleport MM symbol, get the middle point of that and plug it into your MMToMSEx to get an (wonderfully) accurate starting point, then split the screen into 35x35 boxes and count pixelshift in each. I search each box with a high count starting from your MMToMSEx point. Never fails me. ;)

ReadySteadyGo

2012-03-29 07:52:06

From: Flight
I was thinking about this as well. The higher an object, the further away from the center of the MS it would appear.

Yes it does give very accurate results. In my essence-miner I use this for searching for the exit portals in the mine. I grab the teleport MM symbol, get the middle point of that and plug it into your MMToMSEx to get an (wonderfully) accurate starting point, then split the screen into 35x35 boxes and count pixelshift in each. I search each box with a high count starting from your MMToMSEx point. Never fails me. ;)


That sounds ridiculously sexy, can't wait to see it. :)

Also, you don't even need to worry about the MS at all, you just modify the z value and it will calculate it for you.

Wetish

2012-03-29 22:32:37

This looks amazing. Like reflection but color

euphemism

2012-03-30 10:05:49

From: Siel
This looks amazing. Like reflection but color


It's more like math than reflection. In fact, it isn't reflection or color, it IS math. So, it is much cooler.

Flight

2012-03-30 10:14:05

From: euphemism
It's more like math than reflection. In fact, it isn't reflection or color, it IS math. So, it is much cooler.


Exactly what makes it so interesting.

Er1k

2012-03-30 10:20:32

From: Flight
Exactly what makes it so interesting.


I thought only the grid16 functions was implemented? Is this one we're talking about a far more accurate one?

I know this can forever change the way of object finding because being able to convert a MM point to a MS point allows for many crazy applications, e.g. using SPS/DTM/ODTM/NPCDots/etc to locate an object. It will save so many efforts in some of the traditionally difficult areas in color object finding, the most important being doors :D

Coh3n

2012-03-30 13:09:49

Has anyone tried using this in combination with SPS to find an object on the MS? It will be more accurate with SPS2.0, but I'm just wondering if it's possible.

ReadySteadyGo

2012-03-30 14:53:34

From: Coh3n
Has anyone tried using this in combination with SPS to find an object on the MS? It will be more accurate with SPS2.0, but I'm just wondering if it's possible.


I'm not familiar with SPS but I've used this with TPA colour finding for doors etc so assuming SPS can give you a minimap co-ord that is visible on the minimap, it's definitely possible.

Abu

2012-03-30 15:21:17

Looks amazing :)

Can't wait to see what this can lead to…

mormonman

2012-03-30 15:57:13

From: euphemism
It's more like math than reflection. In fact, it isn't reflection or color, it IS math. So, it is much cooler.


Reflection used math…it converted certain information from the client to an x, y point on the screen.

Aegis

2012-03-30 16:34:53

Woah, this looks awesome! I'm tempted to implement this in the script I'm working on right now!

Gu3st...

2012-03-30 17:06:53

From: mormonman
Reflection used math…it converted certain information from the client to an x, y point on the screen.
I was just about to say this, reflection used reflection + math, we use color + math :)

Joe

2012-03-30 19:06:42

From: NZ John
Top of image.. "meatspin.com"… What're you upto? lol


I had to do a double-take… L-0h-freakin-L

Imagine

2012-04-08 21:35:20

So if I was to use this, what would be a sample "short" function implementing this?

Would I first copy the whole code above the mainloop, and then just use the GetMMDotsOnMS2
and use the returned points to search for a specified monster/item from that point?

ReadySteadyGo

2012-04-10 09:41:18

From: Imagine
So if I was to use this, what would be a sample "short" function implementing this?

Would I first copy the whole code above the mainloop, and then just use the GetMMDotsOnMS2
and use the returned points to search for a specified monster/item from that point?


I've written a tutorial which includes a sample script using the include.
http://villavu.com/forum/showthread.php?p=911890

Imagine

2012-04-10 18:51:42

^ Thank you, I'm reading it now :)

m34tcode

2012-04-13 00:33:18

This really should be included in the srl include. While it may not be accurate enough to click small objects, it is clearly good enough to use for sorting tpas. Could enhance the speed of scripts incredibly.

I can see that being used in agility courses

bg5

2012-04-23 09:33:48

Hi, your project is very impressive.
I have been playing with it in dungeon for some time. I modificated it a bit to get 4 corners of tile as output and than search inside tile for objects with canny core. It has potential to be very powerfull tool:

However I noticed few things:
- sometimes it misses dots ,when they are close to each other (like in screen below and above) ,but I think it rather has to do with GetMiniMapDots SRL function.
- it's rarery losing accuracy
- only one-way conversion MM->MS. Would it be hard to add conversion in opposite direction? ;)

Olly

2012-04-23 17:01:16

From: beginner5
Hi, your project is very impressive.
I have been playing with it in dungeon for some time. I modificated it a bit to get 4 corners of tile as output and than search inside tile for objects with canny core. It has potential to be very powerfull tool:

However I noticed few things:
- sometimes it misses dots ,when they are close to each other (like in screen below and above) ,but I think it rather has to do with GetMiniMapDots SRL function.
- it's rarery losing accuracy
- only one-way conversion MM->MS. Would it be hard to add conversion in opposite direction? ;)


Now that sir looks very promising. +rep!

Narcle

2012-04-23 17:10:50

From: beginner5

- sometimes it misses dots ,when they are close to each other (like in screen below and above) ,but I think it rather has to do with GetMiniMapDots SRL function.


Its the way they show the dots on the mini map. The dots are distorted so they aren't actually in the correct place they should be (this is obviously done on purpose by Jagex). GetMiniMapDots works as it should, its the game distorting the location so you can't use it perfectly.

So as in your case the distorting will change 2 dots to be in each other, even though they shouldn't be.

Gala

2012-04-26 06:47:45

I am using this in a script I am writing right now and it is really accurate.
(It detects small npc's moving non-stop without any problems.)

Shatterhand

2012-05-12 10:05:03

Ok I put this into a repeat … until False circle and its very fast and accurate! Will make more tests!

Shatterhand

2012-05-16 17:40:28

I made some further tests. The drawing is nice. But getting the points of them is not working well.
TPA := GetMMDotsOnMS2('red',false);
Writeln(IntToStr(High(TPA)));
for i:=0 to High(TPA) do
begin
Mouse(TPA[i].x,TPA[i].y,0,0,mouse_right);
Wait(1000);
end;
I tried this and while like 4 red boxes were painted on the screen, it only right clicked on one of them. Am I doing something wrong? That TPA return value isnt the middle points of the painted red boxes?

ReadySteadyGo

2012-05-16 18:05:57

Hi, it might actually be an issue with SRLs GetMiniMapDots, not sure right now though. It's being discussed in another thread.

http://villavu.com/forum/showthread.php?t=82510

weizhen

2012-05-28 10:41:37

your script of abyss can yousend me teh update version i am james my msn is [email]runescapeplayer@msn.cn[/email]

Flight

2012-05-28 10:52:47

From: weizhen
your script of abyss can yousend me teh update version i am james my msn is [email]runescapeplayer@msn.cn[/email]


Mate, you're better off contacting him directly rather than posting such messages publicly on a completely different post he made. Atleast use your PM system; it is there for a reason.

Gala

2012-05-28 14:01:50

From: weizhen
your script of abyss can yousend me teh update version i am james my msn is [email]runescapeplayer@msn.cn[/email]


So "James", let me guess. You are NOT a chinese goldfarmer looking for a way to learn script and to be a part of the community.

@topic
What is the main differnece to narcle's MMToMS?

John

2012-06-04 02:36:55

Awesome
In theory you could make it recognise the Obj-DTM's on the MM like
These?

footballjds

2013-03-28 11:53:28

ready, gravedig, steady, update this for zoom?

Olly

2013-03-28 13:38:35

From: footballjds
ready, gravedig, steady, update this for zoom?


Given up on Narcle i see :p, I don't think rsg is active either.. at-least i never see him on irc anymore. :(

footballjds

2013-03-28 13:47:59

From: Ollybest
Given up on Narcle i see :p, I don't think rsg is active either.. at-least i never see him on irc anymore. :(


I haven't gotten a reply PM from Narcle in over a month or so. Not given up, just looking for something faster!

Runehack123

2013-03-28 13:51:13

YOU TELL EM FOOTBALL you tell em
:d what football said ^ me too I full support on this been talking with footyjrsfootball on other thread about it and HE IS RIGHT
so yeah update pleaaaaaase I will do all sorts of wonderful things to you if you do :d

Olly

2013-03-28 13:51:56

From: footballjds
I haven't gotten a reply PM from Narcle in over a month or so. Not given up, just looking for something faster!


Well i actually spoke to RSG somewhat recently about this and he said you can change these values;

  PlayerTile := Point3D(TILE/2, 20 + TILE, (TILE*10) - 8 + TILE/2);
TilePosition := Point3D((tx*TILE)-(8*TILE), 23, (tz*TILE) + (2*TILE)-8);
TileRotation := Rotation(0, (Round(0-rs_GetCompassAngleDegrees)), 0);
CameraPosition := Point3D(0, -233, 0);
CameraRotation := Rotation(65, 0, 0);

Obviously for me and you its just trial and error :p

Runehack123

2013-03-28 13:58:11

From: Ollybest
Well i actually spoke to RSG somewhat recently about this and he said you can change these values;

  PlayerTile := Point3D(TILE/2, 20 + TILE, (TILE*10) - 8 + TILE/2);
TilePosition := Point3D((tx*TILE)-(8*TILE), 23, (tz*TILE) + (2*TILE)-8);
TileRotation := Rotation(0, (Round(0-rs_GetCompassAngleDegrees)), 0);
CameraPosition := Point3D(0, -233, 0);
CameraRotation := Rotation(65, 0, 0);

Obviously for me and you its just trial and error :p

I have NO IDEA what those means hahaha! :o
time for some trial and error like you said

sad times :(

Olly

2013-03-28 14:00:21

I mean its obvious what they do, but i have no real clue what changing the values etc would do + i bet you could get the camera postion from runescape directly and "convert" it onto it if you knew how it was done :P

Runehack123

2013-03-28 14:02:00

From: Ollybest
I mean its obvious what they do, but i have no real clue what changing the values etc would do + i bet you could get the camera postion from runescape directly and "convert" it onto it if you knew how it was done :P


because you are god SSRL of scripting you understand I don't even get what tilerotation means
so derp…

Olly

2013-03-28 14:08:35

From: Runehack123
because you are god SSRL of scripting you understand I don't even get what tilerotation means
so derp…


Lol, I wish i was a god but isn't it somewhat common sense?

regular tile, rotated tile (ie how much tile rotation there is), i could be wrong but it makes sense like this.