SRL Archive - Research & Development Lounge

Function FindColorPriority


Macrosoft

2007-08-31 22:43:57

This is, i guess, my first, finished function.

Special thanks to StarBlaster100 for helping me with tarrays

It will find the first color, but if it doesn't find that, it will find the next color.

Im not really sure what it is usefull for, but watever lol. I dont think it has already been created…

Tell me if you like it! I might make some more functions to help my fellow scripters, in the future!

here it is:

               ////////////////////\\\\\\\\\\\\\\\\\\\\\
///////////Find Color Priority\\\\\\\\\\\\\
//////////All Credit to Macrosoft\\\\\\\\\\\\
//Please do NOT copy without giving me credit\\
//Special Thanks to StarBlaster100 for his help\\
{***********************************************************************************************
Function FindColorPriority(var x, y: Integer; Colors: TIntegerArray; Tolerance: Integer; xs, ys, xe, ye: LongInt): Integer;

Example of use: FindColorPriority(x, y, [22023, 0000], 5, 12, 34, 67, 34)
By: Macrosoft
Description: Will find a color, if the color is not found it will move
to the next color. If it returns 0, it found none of the colors,
otherwise it will return the color number (1,2,3,4,5,6, etc.; not 29849283749, 230920432984, etc.)
It Will also return the x and y coords of the color
I may make more priority Functions such as DoFunctionPriority,
FindObjectPriority, etc.
Tell me if you like it! Also, notify me for me improvements and errors.
Make sure you include SRL
********************************************************************************************************}
{.include SRL/SRL.scar}
Function FindColorPriority(var x, y: Integer; Colors: TIntegerArray; Tolerance: Integer; xs, ys, xe, ye: LongInt): Integer;
var
Counter: Integer;
begin
GetArrayLength(Colors);
Counter:=0
repeat
begin
if(FindColorTolerance(x, y, Colors[Counter], xs, ys, xe, ye, Tolerance)=True) then
begin
Result:= Counter + 1;
Exit;
end else
Counter:=Counter +1;
end;
until(GetArrayLength(Colors)=Counter);
begin
if(GetArrayLength(Colors)=Counter) then
Result:=0
end;
end;

Bam Bam

2007-08-31 22:46:51

You dont need NumberOfColors: integer; you just need to use GetArrayLength(Array);

Macrosoft

2007-08-31 22:48:58

oh, thanks, ill fix that in the morning, its 2 am here… anyway, any scripter who can use the function can probable fix that themselves anyway

nielsie95

2007-09-01 05:20:19


function FindColorPriority(var x, y: Integer; Colors: TIntegerArray; Tolerance, xs, ys, xe, ye: Integer): Integer;
begin
for Result := 1 do Length(Colors) -1 do
if(FindColorTolerance(x, y, Colors[i -1], xs, ys, xe, ye, Tolerance))then
Exit;
Result:=0;
end;

With array you mostly use for to do, tell me if I need to explain it :)

n3ss3s

2007-09-01 05:36:48

Nielsie you screwd up, like everyone uses SetArrayLength and it makes the array from 0 to X, so you do for I := 0 to Length(Array) - 1 do

Go get sum coffee :p =)

Santa_Clause

2007-09-01 07:08:33

(FindColorTolerance(x, y, Colors[Counter], xs, ys, xe, ye, Tolerance)=True)

You don't need =True…it confused the hell out of me because I thought you were trying to make a sad face with the bracket and equals sign :p

Distort

2007-09-01 07:44:46

From: nielsie95

function FindColorPriority(var x, y: Integer; Colors: TIntegerArray; Tolerance, xs, ys, xe, ye: Integer): Integer;
begin
for Result := 1 do Length(Colors) -1 do
if(FindColorTolerance(x, y, Colors[i -1], xs, ys, xe, ye, Tolerance))then
Exit;
Result:=0;
end;

With array you mostly use for to do, tell me if I need to explain it :)


If we only have 2 colors (I know), length(colors)-1 would equal 1. Therefore, as soon as you start, you will only have gone through the loop once, and on the last entry as well. Unless I'm wrong?

Here's how I would have changed it:


function FindColorPriority(var x, y: Integer; Colors: TIntegerArray; Tolerance, xs, ys, xe, ye: Integer): Integer;
begin
for Result := 0 do Length(Colors) -1 do
if(FindColorTolerance(x, y, Colors[result], xs, ys, xe, ye, Tolerance))then
Exit;
Result:=0;
end;

So not much of a change, but it would work in my eyes.

ShowerThoughts

2007-09-01 08:14:00

looks nice i guess.. but there are familiar functions in srl?

nielsie95

2007-09-01 12:21:20

From: Distort
If we only have 2 colors (I know), length(colors)-1 would equal 1. Therefore, as soon as you start, you will only have gone through the loop once, and on the last entry as well. Unless I'm wrong?

Here's how I would have changed it:


function FindColorPriority(var x, y: Integer; Colors: TIntegerArray; Tolerance, xs, ys, xe, ye: Integer): Integer;
begin
for Result := 0 do Length(Colors) -1 do
if(FindColorTolerance(x, y, Colors[result], xs, ys, xe, ye, Tolerance))then
Exit;
Result:=0;
end;

So not much of a change, but it would work in my eyes.


Yes, I know.. But the result would be different from the original function… So I started with Result := 1, but I forgot to take of the -1 ;)

Macrosoft

2007-09-01 12:36:55

whoa!, lots of replys, ill look at them later, im on vacation

ShowerThoughts

2007-09-01 12:41:24

btw i ment simlliar not the word with the F

R0b0t1

2007-09-01 15:57:19

Well… I guess it could have a use, but I like lots of complicated math instead.

Macrosoft

2007-09-01 19:02:06

ok, im guna change the script soon, almost done

WT-Fakawi

2007-09-01 20:07:09

As a matter of fact, I would like to have a function that scans for the unique color of a NPC, a goblin for instance. You scan the color under Uptext Attack Goblin, and compare it to colors in mainscreen. You collect the unique Colors of Goblins. Then you set your General colortolerance for NPC finding to tol = 1. The Mouse wont hoover over anything else but your Goblin now.

nielsie95

2007-09-02 05:06:44

From: WT-Fakawi
As a matter of fact, I would like to have a function that scans for the unique color of a NPC, a goblin for instance. You scan the color under Uptext Attack Goblin, and compare it to colors in mainscreen. You collect the unique Colors of Goblins. Then you set your General colortolerance for NPC finding to tol = 1. The Mouse wont hoover over anything else but your Goblin now.


Boreas has made such a script.. You enter a few small bitmaps of your NPC and the script gets you the best color(s) :) It's in this section + in Auto Color Aid.

The Claw

2007-09-02 06:10:48

From: WT-Fakawi
As a matter of fact, I would like to have a function that scans for the unique color of a NPC, a goblin for instance. You scan the color under Uptext Attack Goblin, and compare it to colors in mainscreen. You collect the unique Colors of Goblins. Then you set your General colortolerance for NPC finding to tol = 1. The Mouse wont hoover over anything else but your Goblin now.


What I did to make my script avoid hovering over muggers in my miner was this - if it finds the colour of the ore, it checks for the unique colour of the mugger in a 20 x 20 box around it, if it finds that colour then we can safely say that its a mugger so we dont move our mouse there. You could do that with an array of colours too, in case there are more colours around on the ground that are similar to goblins. Or you could find 1 colour of the goblin, then search for another colour in 20 x 20, then search for yet another in a 20 x 20. If it finds all three then we know its a goblin. Not as advanced as what you guys are talking about though lol

R0b0t1

2007-09-02 20:50:43

That might be nice. I guess I could try and then find out someone else made one…


@N3ss3s - GetArrayLength() is faster with arrays than Length(), which was originally for strings. (I think it tests if its an array or something… Stupid IF's!).

Macrosoft

2007-09-03 21:30:27

i dont think someone already made it…

bullzeye95

2007-09-03 21:46:19

From: r0b0t1
That might be nice. I guess I could try and then find out someone else made one…


@N3ss3s - GetArrayLength() is faster with arrays than Length(), which was originally for strings. (I think it tests if its an array or something… Stupid IF's!).


Incorrect. I tested the speed of them a few weeks ago, and they (length and getarraylength) came out to exactly the same speed.

Macrosoft

2007-09-13 15:05:41

ill just stay with getarraylength

WOOT, I can actually get on to this forum now lol

TY WT-Fakawai

Sir R. M8gic1an

2007-09-14 19:15:18

lovin the idea, but as already stated before you don't need the =True because the function already returns a boolean when you call it.
if(FindColorTolerance(x, y, Colors[Counter], xs, ys, xe, ye, Tolerance)=True) then

~RMagician

Lalaji

2007-09-16 11:54:57

Pretty nice function. I cant test it tho…

Macrosoft

2007-09-20 17:33:24

thanks