SRL Archive - Test corner

GetRoadColor


imafatmess

2007-10-24 07:35:45

Before I show my function, I'd just like to say that most people wont know me as I was here, well, ages ago, before the whole application thing and that's why I'm a member, but anyway, I have come back in the past week and have been catching up on what I've missed, which is a hell of a lot and I have been reading many tutorials and other things, just to keep up. Anyway, I was looking through the manual and I couldn't find a GetRoadColor function (I've found one now, was looking in the wrong place :P) so I decided to try to see if I could make one…

Here it is, where I've tested it, it is 100% accurate although I know from past experiances that this doesn't by a long shot mean it's 100% accurate everywhere!

Anyway, what it does is it checks all the colors on the minimap and gets their hues. If the hues are between 0 and 5 or 95 and 100 and the luminance between 20 and 80 then it will save them to an array and will count the number of each different color. It will then return the color with the highest frequency. Here's it is:

function GetMapCoords : TPointArray;
var xi, yi : integer;
i : LongInt;
TempTPA : TPointArray;
begin
xi := MMX1 - 1;
yi := MMY1 - 1;
i := 0;
SetArrayLength(TempTPA, (MMX2 - (MMX1 - 1)) * (MMY2 - (MMY1 - 1)));
repeat
yi := yi + 1;
repeat
xi := xi + 1;
TempTPA[i].X := xi;
TempTPA[i].Y := yi;
i := i + 1;
until(xi = MMX2)
xi := MMX1 - 1;
until(yi = MMY2)
Result := TempTPA;
end;

function GetRoadColor : integer;
var RoadCol, i, i2, i3, Largest1, Largest2 : integer;
Ho, So, Lo : extended;
time : LongInt;
arMinimapColors: TIntegerArray;
arGreyCols : array[0..100] of array[0..1] of integer;
begin
arMinimapColors := GetColors(GetMapCoords);
i2 := 0;
for i := 0 to Length(arMinimapColors) - 1 do
begin
ColorToHSL(arMinimapColors[i], Ho, So, Lo);
if ((Ho >= 0) and (Ho < 5)) or ((Ho > 95) and (Ho < 100)) and ((Lo > 20) and (Lo < 20)) then
begin
for i3 := 0 to i2 do
begin
if i3 > 100 then Break;
if arGreyCols[i3][0] = 0 then
begin
arGreyCols[i3][0] := arMinimapColors[i];
arGreyCols[i3][1] := arGreyCols[i3][1] + 1;
i2 := i2 + 1;
break;
end else if arGreyCols[i3][0] = arMinimapColors[i] then
begin
arGreyCols[i3][1] := arGreyCols[i3][1] + 1;
break;
end;
end;
end;
end;
for i := 0 to 100 do
begin
if arGreyCols[i][1] > Largest1 then
begin
Largest1 := arGreyCols[i][1]
Largest2 := i;
end;
end;
Result := arGreyCols[Largest2][0];
end;

Btw, GetMapCoords will get the coordinates of all the points on the minimap, I don't know if there's something in SRL that already did this so I made it myself…

King of Knives

2007-10-24 08:12:43

There is a similar one in SRL/SRL/Core/Autocolor.scar.

There are a lot of others there, and welcome back :D

-Knives

imafatmess

2007-10-24 08:15:35

I didn't realise until I wrote this one but tbh, I don't mind, it got me to learn HSL and it helped me remember many of ma old scripting techniques

Bobarkinator

2007-10-24 08:50:03

Very good work, and welcome back. Hope you have a great time :)

imafatmess

2007-10-24 12:21:44

Thanks, so has anyone tested it yet?

ShowerThoughts

2007-10-24 12:30:00

welcome back, no i wont test it sorry

HyperSecret

2007-10-24 14:05:41

seems to have worked…had it write the color…

SRL Compiled in 15 msec
5789791 is the road color
Successfully executed