SRL Archive - Reflection Development

FindColorOnTile!


HarryJames

2011-04-18 17:02:32

program Untitled;
{$DEFINE SMART}
{$i SRL/SRL.scar}
{$i Reflection/Reflection.simba}

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

with Players[0] do
begin
Name := '+5"gmail.com';
Pass := '';
Nick := 'ake';
Active := True;
end;
end;

function FindColorOnTile(theTile : TTile; theColour : Integer) : TPoint;
var
MSPoint, ReturningValue : TPoint;
rx,ry : integer;
begin
MSPoint := TileToMS(theTile, 0);
if ((MSPoint.x = -1) or (MSPoint.y = -1)) then
begin
Writeln('The tile is not on screen, exiting the FindColorOnTile.');
exit;
end;
FindColorTolerance(rx, ry, theColour, MSPoint.X - 10, MSPoint.Y - 10, MSPoint.X + 10, MSPoint.Y + 10, 20);
ReturningValue.x := rx;
ReturningValue.y := ry;

result := ReturningValue;
end;

Procedure click;
var
a : TPoint;
begin
a := FindColorOnTile(Tile(3223, 3217), 3827548);
Mouse(a.x,a.y,0,0,True);
end;

begin
Smart_Server := 36;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
SetupSRL;
DeclarePlayers;
loginPlayer;

click;
end.

You have your TTile, and a colour. It's helpful for things that don't have solid models :)
I suppose it could also be adapted to be used well with NPCs!

I'm going to improve this when I get a chance.

Yago

2011-04-18 17:32:25

You would have to be facing north at highest angle right? I believe there was also another method of doing this… with offsets at 0 and 1

HarryJames

2011-04-18 17:34:45

I'm going to make it work with any angle at any height, when I find the will and the time :)

Yago

2011-04-18 18:39:39

Maybe this might help:

Its not my code i just saw it somewhere:


TopLeft := TileToMSEx(Tile, 0, 0, 0);
Downright := TileToMSEx(Tile, 1, 1, 0);
FindColorsSpiralTolerance(Click.x, Click.y, Points, Color, TopLeft.x, TopLeft.y, DownRight.x, Downright.y, 15)

You get the main idea right?

Edit: Also you should make the tolerance a variable that can be inputted.

Also, with the above methods you get alot of passing errors so just do something like this :


if TopLeft.x < MSx1 then
TopLeft.x := MSx1;
if TopLeft.y < MSy1 then
TopLeft.y := MSy1;
if DownRight.x > MSx2 then
DownRight.x := MSx2;
if DownRight.y > MSy2 then
DownRight.y := MSy2;

Echo_

2011-04-19 07:42:41

From: Yago

if TopLeft.x < MSx1 then
TopLeft.x := MSx1;
if TopLeft.y < MSy1 then
TopLeft.y := MSy1;
if DownRight.x > MSx2 then
DownRight.x := MSx2;
if DownRight.y > MSy2 then
DownRight.y := MSy2;

You could have used a case statement in that snippet, it would have made it a lot neater.

OT: This is quite interesting, reflection is usually oriented towards reading integers reflected from the client at runtime, the closest use of color I've seen in the include is the use of texture IDs.

HarryJames

2011-04-19 08:33:55

I'm going to add the changes today, during cisco.

Yago, what exactly does this do?
Seems to me like it's saying, if the tile isn't on the screen then make it the bottom right.

Thinking about it, does it mean if the tile point is slightly off screen?

Yago

2011-04-19 12:44:03

TopLeft := TileToMSEx(Tile, 0, 0, 0);
Downright := TileToMSEx(Tile, 1, 1, 0);
FindColorsSpiralTolerance(Click.x, Click.y, Points, Color, TopLeft.x, TopLeft.y, DownRight.x, Downright.y, 15)

I believe I read somewhere that this gets you the top left and bottom right points of a tile as tiletoms is really tiletomsex(tile,0.5,0.5,height) so this gets you the top and bottom

i luffs yeww

2011-04-19 14:03:50

From: Echo_
You could have used a case statement in that snippet, it would have made it a lot neater.


You'd need four case statements, which would make it longer and slower. Not the best plan of action. What he had was fine.

HarryJames

2011-04-19 18:05:06

Improved based on suggestions, I've not had time to test it, or even compile it. (shower time nao)

function FindColorOnTile(theTile : TTile; theColour, theTolerence : Integer) : TPoint;
var
MSPoint, ReturningValue, TopLeft, DownRight : TPoint;
rx,ry : integer;
begin
MSPoint := TileToMS(theTile, 0);
if ((MSPoint.x = -1) or (MSPoint.y = -1)) then
begin
Writeln('The tile is not on screen, exiting the FindColorOnTile.');
exit;
end;

TopLeft := TileToMSEx(Tile, 0, 0, 0);
Downright := TileToMSEx(Tile, 1, 1, 0);

if TopLeft.x < MSx1 then
TopLeft.x := MSx1;
if TopLeft.y < MSy1 then
TopLeft.y := MSy1;
if DownRight.x > MSx2 then
DownRight.x := MSx2;
if DownRight.y > MSy2 then
DownRight.y := MSy2;



FindColorsSpiralTolerance(Click.x, Click.y, Points, Color, TopLeft.x, TopLeft.y, DownRight.x, Downright.y, theTolerence)
ReturningValue.x := rx;
ReturningValue.y := ry;

result := ReturningValue;
end;