SRL Archive - OSR Help

Help FindColorTolerance()


Matterz

2009-09-26 01:29:40

Hello,

I am having an issue with a script I wrote. I've written a few basic SCAR scripts in the past so I'm not completely new to the process.

I am using the ColorPicker to grab the colors for enemy health bars. I save these to a const and then my script uses FindColorTolerance().

Sample Code:

var
x : Integer;
y : Integer;

const
//Color Codes
enemyHealth1 = 7112404;
enemyHealth2 = 5136792;
//Window Scanning
PxTop = 54;
PyTop = 144;
PxBot = 188;
PyBot = 149;
//Tolerance
Tol=100;

If(FindColorTolerance(x,y,enemyHealth1,PxTop,PyTop,PxBot,PyBot,Tol) OR
FindColorTolerance(x,y,enemyHealth2,PxTop,PyTop,PxBot,PyBot,Tol))Then
begin

end

However the script is never able to find the colors I specify. I tried adjusting the tolerance and the size of the scan area, but neither worked. I've also checked the colors immediately after running the script and they haven't changed.

I tried using the following script to get the color codes, but it always returns 0.

var
x : Integer;
x=GetColor(100,145);
Writeln(IntToStr(x));

I figure my problem is one of the three:

  • 1) I screwed up the code.
  • 2) I'm running SCAR on Vista x64 and it has an issue reading the screen?
  • 3) The game I'm attempting to automate is preventing me from reading the colors.


I am able to get SCAR to send key/mouse commands to the game.

Any input as to what is causing my problem would be great.

Thanks!

Mr. Doctor

2009-09-26 02:12:42

Mhmm. So you are saying that you want to use auto color? Or get the colors? What are you planning to do with this? To see if you're in the fight. If so then infight; helps.

Also, you could just put

x,y :integer;
for you x,y integers.

rogeruk

2009-09-26 02:16:35


X := GetColor(100,145);
Writeln(IntToStr(X));

Would work.

Can you post your actual script please as

If(FindColorTolerance(x,y,enemyHealth1,PxTop,PyTop,PxBot,PyBot,Tol) OR
FindColorTolerance(x,y,enemyHealth2,PxTop,PyTop,PxBot,PyBot,Tol))Then
begin

end

Wont do anything anyways..

Try this..

Program New;

Var
x: Integer;
y: Integer;

Const
//Color Codes
enemyHealth1 = 7112404;
enemyHealth2 = 5136792;
//Window Scanning
PxTop = 54;
PyTop = 144;
PxBot = 188;
PyBot = 149;
//Tolerance
Tol = 100;

Procedure Find;
Begin
If (FindColorSpiralTolerance(x, y, enemyHealth1, PxTop, PyTop,
PxBot, PyBot, Tol) Or FindColorSpiralTolerance(x, y, enemyHealth2,
PxTop, PyTop, PxBot, PyBot, Tol)) Then
Begin
Writeln('Found enemy at X: ' + IntToStr(X) + ' Y: ' + IntToStr(Y));
End;

End;

Begin
Find;
End.

Matterz

2009-09-26 02:22:14

From: Junkj
Mhmm. So you are saying that you want to use auto color? Or get the colors? What are you planning to do with this? To see if you're in the fight. If so then infight; helps.


I am checking the enemy health bar to see if my pTarget procedure has picked up an enemy and then again to see when the enemy dies.


repeat
while(enemy=False) Do
begin
pLook;
pTarget;
end;
while (enemy=True) Do
begin
pAttack;
end;
until(quit)

So at the end of the pTarget and pAttack procedure it would use FindColorTolerance() to check whether the enemy healthbar exists.

I am not familiar with an infight procedure. I should mention that this is not for RS.

rogeruk

2009-09-26 02:24:42

Check my edited post.


Program New;

Var
x: Integer;
y: Integer;

Const
//Color Codes
enemyHealth1 = 7112404;
enemyHealth2 = 5136792;
//Window Scanning
PxTop = 54;
PyTop = 144;
PxBot = 188;
PyBot = 149;
//Tolerance
Tol = 100;

Procedure Find;
Begin
If (FindColorSpiralTolerance(x, y, enemyHealth1, PxTop, PyTop,
PxBot, PyBot, Tol) Or FindColorSpiralTolerance(x, y, enemyHealth2,
PxTop, PyTop, PxBot, PyBot, Tol)) Then
Begin
Writeln('Found enemy at X: ' + IntToStr(X) + ' Y: ' + IntToStr(Y));
End;
End;

Begin
Find;
End.

Matterz

2009-09-26 02:38:17

Here is hacked up version of my full code.

The problem is that it never find the enemy health bar. I use the Color Picker to check the color and coordinates right before and after I run the script.


program SFrame;


var
enemy : Boolean;
quit : Boolean;
x : Integer;
y : Integer;
CurrentX : Integer;
CurrentY : Integer;

const
//Color Codes
pethealth1 = 592398;
pethealth2 = 592142;
pethealth3 = 5003500;
pethealth4 = 2368725;
myhealth1 = 3028290;
myhealth2 = 3028547;
myhealth3 = 1645772;
myhealth4 = 1711565;
enemyhealth1 = 2040789;
enemyhealth2 = 2959842;
enemyhealth3 = 3222759;
enemyhealth4 = 1974222;
enemyhealth5 = 5065963;
enemyhealth6 = 1974219;
enemyfound = 4752799;
//Window Scanning
//Position Codes - Assuming resolution of 1280x1024
xt = 10;
yt = 40;
xb = 1276;
yb = 996;
//Health Bar
HxTop = 166;
HyTop = 940;
HxBot = 336;
HyBot = 947;
//Mana Bar
MxTop = 166;
MyTop = 960;
MxBot = 336;
MyBot = 967;
//Enemy Health
xtEC = 580;
ytEC = 50;
xbEC = 780;
ybEC = 90;
//Pet Health
PxTop = 203;
PyTop = 913;
PxBot = 300;
PyBot = 915;
//Tolerance
Tol = 100;

procedure pInitialize;
begin
quit := False;
enemy := False;
Wait(1000);
end;

Procedure pLookAround;
begin
MoveWindMouseEx(700,380,1,1,10);
Wait(20+random(10)-random(10));
GetMousePos(CurrentX,CurrentY);
HoldMouse(CurrentX,CurrentY,false);
Wait(100+random(10)-random(10));
MoveMouse(350+random(10)-random(10),380);
Wait(200+random(10)-random(10));
GetMousePos(CurrentX,CurrentY);
ReleaseMouse(CurrentX,CurrentY,false);
Wait(800+random(50)-random(50));
end;

procedure pTarget;
begin
Wait(10 + random(10));
SendKeysVB('=',false);
Wait(100 + random(50));
If(FindColorTolerance(x,y,enemyhealth1,PxTop,PyTop,PxBot,PyBot,Tol) OR
FindColorTolerance(x,y,enemyhealth2,PxTop,PyTop,PxBot,PyBot,Tol))Then
begin
enemy:=True;
end
end;

procedure pBuff;
begin
Wait(10 + random(50));
KeyDown(17);
Wait(10 + random(10));
SendKeysSilent('1');
Wait(10 + random(10));
KeyUp(17);
Wait(1000 + random(50));
KeyDown(17);
Wait(10 + random(10));
SendKeysSilent('2');
Wait(10 + random(10));
KeyUp(17);
Wait(1000 + random(10));
KeyDown(17);
Wait(10 + random(10));
SendKeysSilent('3');
Wait(10 + random(10));
KeyUp(17);
Wait(1000 + random(10));
KeyDown(16);
Wait(10 + random(10));
SendKeysSilent('5');
Wait(10 + random(10));
KeyUp(16);
Wait(1000 + random(10));
end;

procedure pPetHealing;
begin
Wait(10 + random(10));
KeyDown(16);
Wait(10 + random(10));
SendKeysSilent('3');
Wait(10 + random(10));
KeyUp(16);
Wait(1100 + random(10));
end;

procedure pRest;
begin
SendKeysWait(',',22000,50);
SendKeysWait(',',2000,50);
end;

procedure pAttack;
begin
//Set Pet to Attack
Wait(10 + random(10));
KeyDown(18);
Wait(10 + random(10));
SendKeysSilent('1');
Wait(10 + random(10));
KeyUp(18);
Wait(2000 + random(50));
//Run and Attack
SendKeysWait('c',2000,100);
//Start Casting
KeyDown(16);
Wait(10 + random(10));
SendKeysSilent('2');
Wait(10 + random(10));
KeyUp(16);
Wait(2200 + random(50));
SendKeysWait('1',2000,100);
KeyDown(16);
Wait(10 + random(10));
SendKeysSilent('1');
Wait(10 + random(10));
KeyUp(16);
Wait(2000 + random(50));
KeyDown(16);
Wait(10 + random(10));
SendKeysSilent('4');
Wait(10 + random(10));
KeyUp(16);
Wait(1600 + random(10));
SendKeysWait('2',2000,100);
SendKeysWait('3',3000,100);
SendKeysWait('4',2000,100);
SendKeysWait('4',2000,100);
Wait(3000 + random(50));
KeyDown(16);
Wait(10 + random(10));
SendKeysSilent('2');
Wait(10 + random(10));
KeyUp(16);
Wait(2000 + random(50));
KeyDown(16);
Wait(10 + random(10));
SendKeysSilent('1');
Wait(10 + random(10));
KeyUp(16);
Wait(1000 + random(50));
SendKeysWait('c',2000,100);
SendKeysWait('2',2000,100);
If((FindColorTolerance(x,y,enemyhealth1,PxTop,PyTop,PxBot,PyBot,Tol) OR
FindColorTolerance(x,y,enemyhealth2,PxTop,PyTop,PxBot,PyBot,Tol))=False)Then
begin
enemy:=False;
end
end;

procedure pLoot;
begin
SendKeysWait('-',1000,50);
ClickWindMouse(321,457,2,2,True);
Wait(1000);
end;


begin
pInitialize;
repeat
pBuff;
while(enemy=False) Do
begin
pLookAround;
pTarget;
end;
while(enemy=True) Do
begin
pAttack;
end;
pLoot;
pPetHealing;
pRest;
until(quit)
end.

rogeruk

2009-09-26 02:43:13

What game is this for? WoW by any chance?

Can you get a screenshot?.

Have you tried FindColorSpiralTolerance?

If you run a simple test of


X := GetColor(100,200);
Writeln(IntToStr(X));

Replace co-ords with where the HP bar is and see what it returns.

Matterz

2009-09-26 02:50:37

It's not for WoW. It's for a game in China.

It's my understanding that FindColorSpiralTolerance() functions like FindColorTolerance() except that the search pattern is a spiral?


X := GetColor(100,200);
Writeln(IntToStr(X));

I've done this and it always returns 0. That was my original question. Is it returning 0 because:

A) I screwed up my code.
B) I have an issue running SCAR on Vista x64.
C) The game blocks SCAR's ability to get colors.

rogeruk

2009-09-26 02:52:10

Im running SCAR on Win 7 x64. Doubt game is stopping it.

Are you targeting the game correctly?.

Matterz

2009-09-26 02:55:36

From: rogeruk
Im running SCAR on Win 7 x64. Doubt game is stopping it.

Are you targeting the game correctly?.


I believe so. I am dragging the Crosshairs to the game window. I get the message 'New client targeted'. I then click on the game and hit Ctrl+Alt+R.

All of the mouse and key commands go through. It is only the GetColor/FindColor that seems to be failing.

rogeruk

2009-09-26 03:04:22

program New;

var
x,y:Integer;

begin
If(FindColorSpiralTolerance(x,y,7112404,54,144,188,149,50))Then
begin
writeln(x);
writeln(y);
end;
end.

Try that. Target the game and run.

Screenshot of game?

IRON

2011-01-05 19:19:37

I have the same problem on my Windows Vista 32-bit
GetColor function returns 0 in every point of the selected window.

Gu3st...

2011-01-05 19:23:48

From: IRON
I have the same problem on my Windows Vista 32-bit
GetColor function returns 0 in every point of the selected window.
Some games somehow block Simba/SCAR. The only solution is to auto/macro on it without selecting the window.

And by the way, this thread is old, and not active and it's generally frown upon to post in such threads (It's called "to gravedig")