SRL Archive - OSR Help

NPC Finding [Struggling hard]


Sk1nyNerd

2013-05-02 01:18:10

so for almost two weeks now ive been trying to rewrite my function to talk to an NPC (the competition judge at the range guild) that has the exact same colors as nearby guards (which i do not want to click on AT ALL) but for what ever function i use the script will eventually ignore the check up text and click on a guard. ive been told to try ATPA's and TPA's so i did but it still clicks on the guards and its really slowed down my script. Not sure if i called everything right or if im missing some important things? im still relatively new hence all the selfcomments and this is my first ATPA/TPA attempt at finding something. need some real help and suggestions! *starting to pull my hair out*

procedure Start_Comp;

Var
JudgeHeadTPA: TPointArray;
JudgeHeadATPA, JudgeBodyATPA: T2DPointArray;
tempCTS, i, jx, jy, judgefindtimer: Integer;

begin
writeln('searching');
tempCTS := GetColorToleranceSpeed; //normal CTS
SetColorToleranceSpeed(2); //new CTS
SetToleranceSpeed2Modifiers(0.00,0.11); //enter hue and sat mods found with ACA

FindColorsTolerance(JudgeHeadTPA, 6774623, MSX1, MSY1, MSX2, MSY2, 12); //enter the color and tolerance ACA found. Make appropriate parameters

SetColorToleranceSpeed(tempCTS); //change back to normal
SetToleranceSpeed2Modifiers(0.02, 0.02); //change back to normal
//JudgeHeadATPA := TPAToATPAEx(JudgeHeadTPA, 7, 5);
JudgeHeadATPA := SplitTPAEx(JudgeHeadTPA, 7,5); //width and height searching bounds
SortATPASize(JudgeHeadATPA, True);
SortATPAFromFirstPoint(JudgeHeadATPA, Point(MSCX, MSCY));

for i := 0 To High(JudgeHeadATPA) do
begin
marktime(judgefindtimer);
SMART_DrawDotsEx(True, JudgeHeadATPA[i], clLime);
MiddleTPAEx(JudgeHeadATPA[i], jx, jy);
MMouse(jx, jy, 3, 3);
if (IsUpTextMultiCustom(['-', 'omp'])) then
begin
ClickMouse2(mouse_left);
break;
end;
if(timefrommark(judgefindtimer) > 10000) then
begin
writeln('negatory');
Logout;
TerminateScript;
end;
end;
end;

Le Jingle

2013-05-02 03:10:12

Not sure if this is the end-goal you're looking for or not, but from mustering up some code on the tired/sluggish brain of mine (at the moment), I think this may help point you (at minimum) in the right direction.
I spaced the code out into somewhat repetitive format, yet it shouldn't affect your script immensely, but should also help show the flow of code calls being done. It can get tricky sorting out false-positives, so even more checks couldn't hurt (ex. superuser has a nice surface object / small guide on what I'm talking about).

Nonetheless

function TalkToNPC(): Boolean; // result in a boolean type, because it is useful to know if we talked to the NPC or not
var
i, t, TempCTS: Integer;
OldHue, OldSat: Extended;
Pt: TPoint;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
Result := False;

// Save old CTS 2 stuffs, then setup the new stuffs to seach with
TempCTS := GetColorToleranceSpeed();
GetColorspeed2Modifiers(OldHue, OldSat);
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.00, 0.11);

// tpa search + length check for inadequate results
FindColorsTolerance(TPA, 6774623, MSX1, MSY1, MSX2, MSY2, 12);
if (Length(TPA) < 1) then
begin
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(OldHue, OldSat);
end;

// atpa split + length check for inadequate results
SplitTPAExWrap(TPA, 7, 5, ATPA);
if (Length(ATPA) < 1) then
begin
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(OldHue, OldSat);
end;

// atpa sorting
SortATPASize(ATPA, True);
SortATPAFromFirstPoint(ATPA, Point(MSCX, MSCY));

// remove tpa's in the atpa that exceed a large-ish distances (in terms of searching for a NPC's head)
for i := 0 to high(ATPA) do
if (Distance(ATPA[i][Low(ATPA[i])].x, ATPA[i][Low(ATPA[i])].y,
ATPA[i][High(ATPA[i])].x, ATPA[i][High(ATPA[i])].y) > 2 shl 4) then
DeleteValueInATPA(ATPA, i);
// atpa length check for inadequate results
if (Length(ATPA) < 1) then
begin
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(OldHue, OldSat);
end;

// remove tpa's in the atpa that don't match at least 10 points/pixels and are under 100 too
for i := 0 to high(ATPA) do
if not ((Length(ATPA[i]) < 100) and (Length(ATPA[i]) > 10)) then
DeleteValueInATPA(ATPA, i);
// atpa length check for inadequate results
if (Length(ATPA) < 1) then
begin
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(OldHue, OldSat);
end;

// Mark time marker, used potentially later if we exceed 10 seconds
MarkTime(t);
for i := 0 to high(ATPA) do
begin
MiddleTPAEx(ATPA[i], Pt.x, Pt.y);
MMouse(Pt.x, Pt.y, 3, 3);
if (IsUpTextMultiCustom(['-', 'omp'])) then
begin
Result := True; // reached objective
ClickMouse2(Mouse_Left);
Break;
end;
if (TimeFromMark(t) > 10000) then
begin
LogOut;
Break;
end;
end;
end;

Cheers,
LJ

Sk1nyNerd

2013-05-02 15:02:36

cool ill try this in a bit and let you know. and ya, I had a failsafe ready, the judgebodyatpa, but I wanted to make sure that wasnt screwing it up. I have a pending question in that section aswell :P

thanks Lj!

Shatterhand

2013-05-02 15:39:09

I had the same problem. Uptext reading is sometimes buggy and one mistake can kill you easily (if you dont check for combat).
This is why I switched to right clicking to find the Judge. Also you should sort the ATPA from the point where you found the ranger last time (global variable) so it finds the ranger faster.

Sk1nyNerd

2013-05-02 16:54:27

From: Shatterhand
I had the same problem. Uptext reading is sometimes buggy and one mistake can kill you easily (if you dont check for combat).
This is why I switched to right clicking to find the Judge. Also you should sort the ATPA from the point where you found the ranger last time (global variable) so it finds the ranger faster.


Mine too I had right click but as I started learning more I thought I could prevent the guard clicking and could use the left click. You dont think right clicking the Judge hours on end wont get flagged for bot-like? its looking like my only solution to not attacking a guard. and by archer did you mean judge? its good to know im not doing something wrong then and it is sometimes buggy lol been pulling my hair out for over two weeks. thanks

Sk1nyNerd

2013-05-02 17:12:37

From: Le Jingle
Not sure if this is the end-goal you're looking for or not, but from mustering up some code on the tired/sluggish brain of mine (at the moment), I think this may help point you (at minimum)


so it found the judge but it would never click him, it would mouse over him then go to my inv tab and keep hovering around the tab. definetly helpful though. how do know what size or length of a ATPA you are looking for?? like 'if (Length(ATPA) < 1) then' what does that mean?

function Start_Comp(): Boolean; // result in a boolean type, because it is useful to know if we talked to the NPC or not
var
i, t, TempCTS: Integer;
OldHue, OldSat: Extended;
Pt: TPoint;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
Result := False;

// Save old CTS 2 stuffs, then setup the new stuffs to seach with
TempCTS := GetColorToleranceSpeed();
GetColorspeed2Modifiers(OldHue, OldSat);
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.00, 0.11);

// tpa search + length check for inadequate results
FindColorsTolerance(TPA, 6774623, MSX1, MSY1, MSX2, MSY2, 12);
if (Length(TPA) < 1) then
begin
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(OldHue, OldSat);
end;

// atpa split + length check for inadequate results
SplitTPAExWrap(TPA, 7, 5, ATPA);
if (Length(ATPA) < 1) then
begin
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(OldHue, OldSat);
end;

// atpa sorting
SortATPASize(ATPA, True);
SortATPAFromFirstPoint(ATPA, Point(MSCX, MSCY));

// remove tpa's in the atpa that exceed a large-ish distances (in terms of searching for a NPC's head)
for i := 0 to high(ATPA) do
if (Distance(ATPA[i][Low(ATPA[i])].x, ATPA[i][Low(ATPA[i])].y,
ATPA[i][High(ATPA[i])].x, ATPA[i][High(ATPA[i])].y) > 2 shl 4) then
DeleteValueInATPA(ATPA, i);
// atpa length check for inadequate results
if (Length(ATPA) < 1) then
begin
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(OldHue, OldSat);
end;

// remove tpa's in the atpa that don't match at least 10 points/pixels and are under 100 too
for i := 0 to high(ATPA) do
if not ((Length(ATPA[i]) < 100) and (Length(ATPA[i]) > 10)) then
DeleteValueInATPA(ATPA, i);
// atpa length check for inadequate results
if (Length(ATPA) < 1) then
begin
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(OldHue, OldSat);
end;

// Mark time marker, used potentially later if we exceed 10 seconds
MarkTime(t);
for i := 0 to high(ATPA) do
begin
writeln('found');
MiddleTPAEx(ATPA[i], Pt.x, Pt.y);
SMART_DebugATPA(False, ATPA);
MMouse(Pt.x, Pt.y, 3, 3);
if (IsUpTextMultiCustom(['omp', 'tition'])) then
begin
writeln('found again');
Result := True; // reached objective
ClickMouse2(Mouse_Left);
writeln('did click');
Break;
end;
if (TimeFromMark(t) > 10000) then
begin
LogOut;
Break;
end;
end;
end;

Kevin

2013-05-02 17:19:09

From: ibot_dung11
so it found the judge but it would never click him, it would mouse over him then go to my inv tab and keep hovering around the tab. definetly helpful though. how do know what size or length of a ATPA you are looking for?? like 'if (Length(ATPA) < 1) then' what does that mean?

function Start_Comp(): Boolean; // result in a boolean type, because it is useful to know if we talked to the NPC or not
var
i, t, TempCTS: Integer;
OldHue, OldSat: Extended;
Pt: TPoint;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
Result := False;

// Save old CTS 2 stuffs, then setup the new stuffs to seach with
TempCTS := GetColorToleranceSpeed();
GetColorspeed2Modifiers(OldHue, OldSat);
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.00, 0.11);

// tpa search + length check for inadequate results
FindColorsTolerance(TPA, 6774623, MSX1, MSY1, MSX2, MSY2, 12);
if (Length(TPA) < 1) then
begin
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(OldHue, OldSat);
end;

// atpa split + length check for inadequate results
SplitTPAExWrap(TPA, 7, 5, ATPA);
if (Length(ATPA) < 1) then
begin
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(OldHue, OldSat);
end;

// atpa sorting
SortATPASize(ATPA, True);
SortATPAFromFirstPoint(ATPA, Point(MSCX, MSCY));

// remove tpa's in the atpa that exceed a large-ish distances (in terms of searching for a NPC's head)
for i := 0 to high(ATPA) do
if (Distance(ATPA[i][Low(ATPA[i])].x, ATPA[i][Low(ATPA[i])].y,
ATPA[i][High(ATPA[i])].x, ATPA[i][High(ATPA[i])].y) > 2 shl 4) then
DeleteValueInATPA(ATPA, i);
// atpa length check for inadequate results
if (Length(ATPA) < 1) then
begin
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(OldHue, OldSat);
end;

// remove tpa's in the atpa that don't match at least 10 points/pixels and are under 100 too
for i := 0 to high(ATPA) do
if not ((Length(ATPA[i]) < 100) and (Length(ATPA[i]) > 10)) then
DeleteValueInATPA(ATPA, i);
// atpa length check for inadequate results
if (Length(ATPA) < 1) then
begin
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(OldHue, OldSat);
end;

// Mark time marker, used potentially later if we exceed 10 seconds
MarkTime(t);
for i := 0 to high(ATPA) do
begin
writeln('found');
MiddleTPAEx(ATPA[i], Pt.x, Pt.y);
SMART_DebugATPA(False, ATPA);
MMouse(Pt.x, Pt.y, 3, 3);
if (WaitUpTextMultiCustom(['omp', 'tition'], 600)) then
begin
writeln('found again');
Result := True; // reached objective
ClickMouse2(Mouse_Left);
writeln('did click');
Break;
end else begin
writeLn('Uptext is actually: ' + GetUpText);
end;
if (TimeFromMark(t) > 10000) then
begin
LogOut;
Break;
end;
end;
end;


I edited the code in my code to something I think should help (basically added a wait to your highlight of the judge and if it fails, prints out the uptext it's grabbing so you can debug your TStringArray you're passing it). Try that?

Le Jingle

2013-05-02 18:06:54

From: Kevin
I edited the code in my code to something I think should help (basically added a wait to your highlight of the judge and if it fails, prints out the uptext it's grabbing so you can debug your TStringArray you're passing it). Try that?


This could indeed be a cause to the explained error. Waiting may help increase your success in clicking the NPC, as well as possibly trying to right click him and using a wait choose option function (this could be one of a multitude of other approaches) to check the options text for your desired result.

Sk1nyNerd

2013-05-02 19:02:49

ill give that a try, seems like it will help quite a bit!

what about surfaces? how do i decide what surface part or colors to use? do i litteraly need to use every color on the judge or can i pick certain colors/parts as i do with ATPA and FindObj

Le Jingle

2013-05-02 19:14:08

From: ibot_dung11
ill give that a try, seems like it will help quite a bit!

what about surfaces? how do i decide what surface part or colors to use? do i litteraly need to use every color on the judge or can i pick certain colors/parts as i do with ATPA and FindObj


Well, iirc, there are many properties to be used to help narrow your specific surface object in question. If parts of the surface are confusing, then asking on superuser's thread as well as reading tutorials about object finding via colors in the tutorial section may help in the process of defining what colors and what to set up in your code for precise and accurate searches/locating.
-Lj

Sk1nyNerd

2013-05-04 16:20:07

it appears the waituptext has fixed it, didnt know that function exhisted. thanks guys :)
what would you say is a human like time between moving the mouse to a position x,y then clicking? i think theres a function for it but idk the name

Shatterhand

2013-05-04 16:27:49

From: ibot_dung11
what would you say is a human like time between moving the mouse to a position x,y then clicking? i think theres a function for it but idk the name

What do you mean? You cant decide if its the judge without moving the mouse on it.

Sk1nyNerd

2013-05-05 01:44:11

From: Shatterhand
What do you mean? You cant decide if its the judge without moving the mouse on it.


the mouse is already on the judge. becase when u move your mouse to a postion you dont instantly click when you get there, there's a lag time. nah mean? lol