SRL Archive - Reflection Development

SearchForColorOnTile


weezy

2010-11-26 16:33:05

Function that will search for colors on a specific tile, very useful for respawning objects such as Wine of Zamorak (that's where I personally use this function), tested but only for wines of zammy.

function SearchForColorOnTile(var x,y:integer;tile:TTile;heigth,spread,color,tolerance,number:integer):boolean;
var pt:TPoint;
tpa:TPointArray;
begin
result := false;
if not TileOnMS(tile,heigth) then
begin
writeln('Attempting to search for color on a tile that''s outside the main screen!');
exit;
end;
pt := TileToMS(tile,heigth);
FindColorsTolerance(tpa, color, (pt.x - (spread/2)), (pt.y - (spread/2)), (pt.x + (spread/2)), (pt.y + (spread/2)), tolerance);
result := Length(tpa) >= number;
if result then
MiddleTPAEx(tpa, x, y);
end;

bbri06

2010-11-26 16:49:35

I use something like this for finding monsters that take up multiple tiles. It works pretty well. By the way, you don't need to set the function to return false like that. It always returns false unless told otherwise.

i luffs yeww

2010-11-26 18:15:40

There are some instances where it is necessary. If you use something like "if Result then…" then it does matter if Result is true or false, and it will always be what it was last set to if you don't set Result at the beginning of the function, which may matter.

And it's just good practice in general for the above purpose, usually.