SRL Archive - SRL Archives

TPAFind! - Does a TPA's job in 1 LINE!


BazzBarrett

2008-09-19 15:39:19

Hi =), 2bh i was realy fed up of having 2 write 20 odd lines of code for a tpa.. so i made this an include that doe's it for u!!!!!
This Does Work ive tested it myself and only took 0.76 secs to find it and move the mouse to it!
run thorugh of teh function:

x and y - Were you whant your cords to be stored
color 1 , 2 & 3 - 3 colours of the thing you are whanting to click ;)
TheUpText - the important part of the string at the top eg Oak (Case sensative)

and there u have it we have located our object in 2 lines ;)

edit (lost count of the number of times XD):
this sould work correctly has everything in it and uses TIntegerArray =)

with special thank to Mastaraymond and ProphesyOfWolf For helping alot in the development of this Funciton!
Function TPAFind(Var X, y :integer; colors :TIntegerArray; TheUpText :String):boolean;
var
CTS, Ic : Integer;
TPA: TPointArray;
ATPA: Array of TPointArray;
H, S, L, HueMod, SatMod, tolerance :extended;
midcolor: integer;
I,II : integer;
HSLColor : Array[1..3] of Extended;
HSL: Array[0..1] of Array[1..3] of Extended;
begin
//Work Out some values
For Ic:= 1 to 3 do
begin;
HSL[0][ic] := 255; //Max is 240?
end;
For Ic:= 0 to High(Colors) do
begin;
ColortoHSL(Colors[ic],HSLColor[1],HSLColor[2],HSLColor[3]);
For II:= 1 to 3 do
begin;
HSL[0][II] := MinE(HSLColor[II],HSL[0][II]);
HSL[1][II] := MaxE(HSLColor[II],HSL[1][II]);
end;
end;
For Ic:= 0 to 9 do
begin;
end;
H := HSL[1][1] - HSL[0][1];
S := HSL[1][2] - HSL[0][2];
L := HSL[1][3] - HSL[0][3];
midcolor := HSLToColor((HSL[1][1] + HSL[0][1]) div 2,(HSL[1][2] + HSL[0][2]) div 2,(HSL[1][3] + HSL[0][3]) div 2);
HueMod := (H/L);
SatMod := (S/L);
tolerance := L;

//FIND the TPA!
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Huemod, satmod );
FindColorsSpiralTolerance(MSCX, MSCY, TPA, MidColor, MSX1, MSY1, MSX2, MSY2, round(tolerance+0.5));
ColorToleranceSpeed(CTS);
ATPA := TPAToATPAEx(TPA, 15, 15);
For Ic := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 2, 2);
Wait(50);
If(IsUpTextMultiCustom([TheUpText])) then
begin
Result := True;
GetMousePos(x, y);
Break;
end;
end;
end;

program New;
{.include SRL/SRL.scar}

Function TPAFind(Var X, y :integer; colors :TIntegerArray; TheUpText :String):boolean;
var
CTS, Ic : Integer;
TPA: TPointArray;
ATPA: Array of TPointArray;
H, S, L, HueMod, SatMod, tolerance :extended;
midcolor: integer;
I,II : integer;
HSLColor : Array[1..3] of Extended;
HSL: Array[0..1] of Array[1..3] of Extended;
begin
//Work Out some values
For Ic:= 1 to 3 do
begin;
HSL[0][ic] := 255; //Max is 240?
end;
For Ic:= 0 to High(Colors) do
begin;
ColortoHSL(Colors[ic],HSLColor[1],HSLColor[2],HSLColor[3]);
For II:= 1 to 3 do
begin;
HSL[0][II] := MinE(HSLColor[II],HSL[0][II]);
HSL[1][II] := MaxE(HSLColor[II],HSL[1][II]);
end;
end;
For Ic:= 0 to 9 do
begin;
end;
H := HSL[1][1] - HSL[0][1];
S := HSL[1][2] - HSL[0][2];
L := HSL[1][3] - HSL[0][3];
midcolor := HSLToColor((HSL[1][1] + HSL[0][1]) div 2,(HSL[1][2] + HSL[0][2]) div 2,(HSL[1][3] + HSL[0][3]) div 2);
HueMod := (H/L);
SatMod := (S/L);
tolerance := L;

//FIND the TPA!
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Huemod, satmod );
FindColorsSpiralTolerance(MSCX, MSCY, TPA, MidColor, MSX1, MSY1, MSX2, MSY2, round(tolerance+0.5));
ColorToleranceSpeed(CTS);
ATPA := TPAToATPAEx(TPA, 15, 15);
For Ic := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 2, 2);
Wait(50);
If(IsUpTextMultiCustom([TheUpText])) then
begin
Result := True;
GetMousePos(x, y);
Break;
end;
end;
end;
var
OakColors :TIntegerArray;
x, y, T :integer;

begin
SetUpSRL;
marktime(t);
//Change the below ;)
OakColors := [2582619, 2185550, 2384468]// or your own colors
TpaFind(x, y, OakColors, 'Oak');// or your TPA values
//Injoy =)
mouse(x, y, 2, 2, true);
writeln('Took '+inttostr(TimeFromMark(t))+'To Find Your Object!');
end.

noidea

2008-09-19 15:42:41

Wow, all's you are doing is pumping out the scripts man! Your going to have SRL members in no time! I looked at the actual function. Do you program aany other language? It seems like you have been doing this a long time. Good job!!!!

BazzBarrett

2008-09-19 15:44:50

lolz thz =) only basic javascript and html i just realy like scar an ammasing laguage 2 script in ;) and im making a script for members i just had this though half way through XD

dorkythedork

2008-09-19 15:51:28

I dit this and get this error

Line 132: [Error] (17650:9): Unknown identifier 'x' in script C:\Program Files\SCAR 3.15c\Scripts\Guild miner.scar

line132
TPAFind(x, y, 3433856, 3297377, 4155003, 'Ladder');

BazzBarrett

2008-09-19 15:55:37

umm have u declered x and y as a var?
have u include it as an include eg {.include SRL/TpaFind.scar}
and that just returns teh x and y if u whant 2 click remember mouse(x,y,2,2,true);

dorkythedork

2008-09-19 16:09:49

If have just copyd youre function putted in my script and than just used it at line 132

———
Or do i need to add mouse(x,y,2,2,true); at function or where ?

MylesMadness

2008-09-19 16:24:29

What if I have 2 colors? Ten?
function TPAFind(Var X, y :integer; colors:TintegerArray; TheUpText :String):boolean;
var
CTS, Ic : Integer;
TPA: TPointArray;
ATPA: Array of TPointArray;
H, S, L, HueMod, SatMod, tolerance :extended;
midcolor: integer;
HueString, SatString:string;
I,II : integer;
HSLColor : Array[1..3] of Extended;
HSL: Array[0..1] of Array[1..3] of Extended;
begin
//Work Out some values
For Ic:= 1 to 3 do
begin;
HSL[0][ic] := 255; //Max is 240?
end;
For Ic:= 0 to High(Colors) do
begin;
ColortoHSL(Colors[ic],HSLColor[1],HSLColor[2],HSLColor[3]);
For II:= 1 to 3 do
begin;
HSL[0][II] := MinE(HSLColor[II],HSL[0][II]);
HSL[1][II] := MaxE(HSLColor[II],HSL[1][II]);
end;
end;
For Ic:= 0 to 9 do
begin;
end;
H := HSL[1][1] - HSL[0][1];
S := HSL[1][2] - HSL[0][2];
L := HSL[1][3] - HSL[0][3];
midcolor := HSLToColor((HSL[1][1] + HSL[0][1]) div 2,(HSL[1][2] + HSL[0][2]) div 2,(HSL[1][3] + HSL[0][3]) div 2);
HueMod := (H/L);
SatMod := (S/L);
tolerance := L;
Huestring := floattostr(HueMod);
SatString := floattostr(SatMod);
setlength(HueString,4);
setlength(SatString,4);
//FIND the TPA!
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(StrToFloat(HueString), StrToFloat(SatString));
FindColorsSpiralTolerance(MSCX, MSCY, TPA, MidColor, MSX1, MSY1, MSX2, MSY2, round(tolerance+0.5));
ColorToleranceSpeed(CTS);
ATPA := TPAToATPAEx(TPA, 15, 15);
For Ic := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 2, 2);
Wait(50);
If(IsUpTextMultiCustom([TheUpText])) then
begin
Result := True;
GetMousePos(x, y);
Break;
end;
end;
end;
Shorter and better.

BazzBarrett

2008-09-19 16:32:35

i was thinking of somthing aloung thoughs lines but u ahve declear all the values b4 hand.. =\ altough i suppose u could just put:
OakTPAColors := [908921, 988273, 1872632]
in the setup and then call
TPAFind(x, y, OakTpaColors, 'Oak');

EDIT: changed it to a TIntegerArray injoy secounds not 10 mins of happy coding ;)

MylesMadness

2008-09-19 16:37:45

Nope you don't

TPAFind(x, y, [908921, 988273, 1872632], 'Oak');

dorkythedork

2008-09-19 17:08:15

can't you make a const of it

of:
OakColors := [908921, 988273, 1872632]

——————-
I get a error when he try to do FindTPA

[Runtime Error] : Exception: Invalid float in line 104 in script C:\Program Files\SCAR 3.15c\Scripts\Guild miner.scar


@104

SetColorSpeed2Modifiers(StrToFloat(HueString), StrToFloat(SatString));

BazzBarrett

2008-09-19 17:25:02

umm yer both ways work very well =)
or u can use things like:
case treetype of
'Oak': colors := [143512,2522454,396523]

TViYH

2008-09-19 17:25:26

Double post is phail.

And. Just make it use a TIntegerArray;, with the user setting up the Color array in the Players[] setup.

BazzBarrett

2008-09-19 17:30:50

yer gud enough and i think i may know y that error has appreared do 1 of 2 things
1. use difrent colors
2.use this script insted:
function TPAFind(Var X, y :integer; colors :TIntegerArray; TheUpText :String):boolean;
var
CTS, Ic : Integer;
TPA: TPointArray;
ATPA: Array of TPointArray;
H, S, L, HueMod, SatMod, tolerance :extended;
midcolor: integer;
HueString, SatString:string;
I,II : integer;
HSLColor : Array[1..3] of Extended;
HSL: Array[0..1] of Array[1..3] of Extended;
begin
//Work Out some values
For Ic:= 1 to 3 do
begin;
HSL[0][ic] := 255; //Max is 240?
end;
For Ic:= 0 to High(Colors) do
begin;
ColortoHSL(Colors[ic],HSLColor[1],HSLColor[2],HSLColor[3]);
For II:= 1 to 3 do
begin;
HSL[0][II] := MinE(HSLColor[II],HSL[0][II]);
HSL[1][II] := MaxE(HSLColor[II],HSL[1][II]);
end;
end;
For Ic:= 0 to 9 do
begin;
end;
H := HSL[1][1] - HSL[0][1];
S := HSL[1][2] - HSL[0][2];
L := HSL[1][3] - HSL[0][3];
midcolor := HSLToColor((HSL[1][1] + HSL[0][1]) div 2,(HSL[1][2] + HSL[0][2]) div 2,(HSL[1][3] + HSL[0][3]) div 2);
HueMod := (H/L);
SatMod := (S/L);
tolerance := L;

//FIND the TPA!
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Huemod, satmod );
FindColorsSpiralTolerance(MSCX, MSCY, TPA, MidColor, MSX1, MSY1, MSX2, MSY2, round(tolerance+0.5));
ColorToleranceSpeed(CTS);
ATPA := TPAToATPAEx(TPA, 15, 15);
For Ic := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 2, 2);
Wait(50);
If(IsUpTextMultiCustom([TheUpText])) then
begin
Result := True;
GetMousePos(x, y);
Break;
end;
end;
end;

dorkythedork

2008-09-20 07:10:55

Can you add the example back when you wanna quick test it

randy marsh

2008-09-20 07:20:49

if i use thisin my members appiclation il get bitched at for using a to simple script!

PvH

2008-09-20 07:21:42

I made this also:p
Your not the first one;)
A lot could be shortened, but overall, good job!

PvH

BazzBarrett

2008-09-20 17:31:31

There was 1 befor? dang XD ill take a look in a sec and yer ill add the test bak