Jump to content
johnnyfortner

New to scar

Recommended Posts

And not familiar with the syntax.

I'm a programmer but I just can't get this to work out right.

here is my simple script:

[scar]program Simple;

 

var

W, H: Integer;

X, Y: Integer;

const YTViewColor = 1943338;

 

begin

GetBoxSize(GetClient.ImageArea, W, H);

if FindColor(X, Y, YTViewColor, 0, 0, W - 1, H - 1) then

SetMousePos(X, Y);

wait(random(100));

ClickMouse(X, Y, mbLeft);

wait(31000+random(50));

end.[/scar]

It's supposed to just find the color of a button, move the mouse there, click it, wait 30 seconds and then do it again.

any help is appreciated

 

it compiles successively but upon run it says line out of bounds.

Edited by Freddy
Link to comment
Share on other sites

Try this

 

[sCAR]

program Simple;

 

var

W, H: Integer;

X, Y: Integer;

TestBox: TBox;

const YTViewColor = 1943338;

 

begin

TestBox := GetClient.ImageArea;

GetBoxSize(TestBox, W, H); // Don't know if this is correct

// but i remember me and Freddy talking about it in the past

// Select a client with crosshairs

// then activate it like this

TSCARWindowClient(GetClient).Activate;

 

if FindColor(X, Y, YTViewColor, 0, 0, W - 1, H - 1) then

SetMousePos(X, Y); // This is the fastest, but MoveMouse is more human like and not as fast

wait(random(100));

ClickMouse(X, Y, mbLeft);

wait(31000+random(50));

 

// To repeat this indefinetly use REPEAT...UNTIL false; around everything u want to do repeatedly without stopping

 

end.

[/sCAR]

Link to comment
Share on other sites

I posted that really fast. Here is it with standards xD

 

[sCAR]program Simple;

 

var

W, H: Integer;

X, Y: Integer;

TestBox: TBox;

 

const

YTViewColor = 1943338;

 

begin

TestBox := GetClient.ImageArea;

GetBoxSize(TestBox, W, H);

TSCARWindowClient(GetClient).Activate;

if FindColor(X, Y, YTViewColor, 0, 0, W - 1, H - 1) then

SetMousePos(X, Y);

wait(random(100));

ClickMouse(X, Y, mbLeft);

wait(31000+random(50));

end.

[/sCAR]

Link to comment
Share on other sites

Out of curiosity how does this look?

[scar]program YLHProgram;

 

var

W, H: Integer;

X, Y: Integer;

TestBox: TBox;

const YTViewColor = 3322973;

const LoadMore = 61695;

 

begin

TestBox := GetClient.ImageArea;

GetBoxSize(TestBox, W, H);

TSCARWindowClient(GetClient).Activate;

REPEAT

//load more videos

if FindColor(X, Y, LoadMore, 0, 0, W - 1, H - 1) then

MoveMouse(X,Y);

wait(random(1000));

ClickMouse(X, Y, mbLeft);

MoveMouse(random(X),random(Y));

wait(13000+random(7000));

//then watch a video

if FindColor(X, Y, YTViewColor, 0, 0, W - 1, H - 1) then

MoveMouse(X,Y);

wait(random(1000));

ClickMouse(X, Y, mbLeft);

MoveMouse(random(X),random(Y));

wait(35000+random(2000));

until false;

end. [/scar]

 

edit:note when using both this and my old one, it works perfectly until after about 5 repeats then the mouse moves to 0,0 of the window and stops.

^^^ never mind this, the site was lagging and the pixel was gone when scar was looking for it...

Edited by Freddy
Link to comment
Share on other sites

It looks good, but remember. IF that MoveMouse(Random(X)). Decides that random X, is the same as X. That might cause a problem trying to find the color if the mouse is over it. It depends though, maybe your mouse can't cover the entire color.

 

So you could make it random for everything before the color, and after it on the screen.

 

Good job though looks fine!

Link to comment
Share on other sites

I need more help, every once in a while. The mouse will be trying to move to a spot outside the screen, and the only way to bring it back is to restart the script.
I notice it will click the mouse regardless of whether the color is actually found. If FindColor fails to find the color then X and Y could be set to anything (taking you outside the window).

 

[sCAR]program YLHProgram;

 

const

YTViewColor = 3322973;

LoadMore = 61695;

 

var

W, H: Integer;

X, Y: Integer;

TestBox: TBox;

 

begin

TestBox := GetClient.ImageArea;

GetBoxSize(TestBox, W, H);

TSCARWindowClient(GetClient).Activate;

repeat

//load more videos

if FindColor(X, Y, LoadMore, 0, 0, (W - 1), (H - 1)) then

begin

MoveMouse(X, Y);

Wait(Random(1000));

ClickMouse(X, Y, mbLeft);

end;

MoveMouse(Random(X), Random(Y));

Wait(13000 + Random(7000));

//then watch a video

if FindColor(X, Y, YTViewColor, 0, 0, (W - 1), (H - 1)) then

begin

MoveMouse(X, Y);

Wait(Random(1000));

ClickMouse(X, Y, mbLeft);

end;

MoveMouse(Random(X), Random(Y));

Wait(35000 + Random(2000));

until False;

end.[/sCAR]

 

Proper indenting helps a lot when trying to read your own code and figure out where things are going wrong.

Edited by Bixby Sayz
Link to comment
Share on other sites

I was wondering about that, thanks.

Also for the watch video function, would there be a way to wait until the pixel or image is found on the page and then click it. instead of waiting for a set amount of seconds and if it isn't found return 0,0. I ask this because sometimes the site lags and scar is searching for the pixel way too soon, or way too late, I need to click it as soon as it loads.

Link to comment
Share on other sites

You could do something like

[sCAR] //load more videos

repeat

Wait(Random(1000));

until FindColor(X, Y, LoadMore, 0, 0, (W - 1), (H - 1));

MoveMouse(X, Y);

Wait(Random(1000));

ClickMouse(X, Y, mbLeft);

MoveMouse(Random(X), Random(Y));

Wait(13000 + Random(7000));

[/sCAR]

Be aware this has the potential to be an infinite loop if the color is never found. I usually like to build in a fail safe so if x amount of time has passed then something has obviously gone horribly wrong so quit.

[sCAR]var

T: Integer;

 

//load more videos

T := GetSystemTime + 300000; // (5 min * 60 sec/min * 1000 ms/sec)

repeat

Wait(Random(1000));

if (GetSystemTime > T) then

Exit;

until FindColor(X, Y, LoadMore, 0, 0, (W - 1), (H - 1));

MoveMouse(X, Y);

Wait(Random(1000));

ClickMouse(X, Y, mbLeft);

MoveMouse(Random(X), Random(Y));

Wait(13000 + Random(7000)); //then watch a video

[/sCAR]

Link to comment
Share on other sites

Thanks, I was trying to write that myself but I'm still not used to the syntax. I was only slightly off ;)

This is what it looks like now:

[sCAR]

program YLHProgram;

 

const

YTViewColor = 3322973;

LoadMore = 61695;

 

var

W, H: Integer;

X, Y: Integer;

T: Integer;

TestBox: TBox;

 

begin

TestBox := GetClient.ImageArea;

GetBoxSize(TestBox, W, H);

TSCARWindowClient(GetClient).Activate;

repeat

//load more videos

if FindColor(X, Y, LoadMore, 0, 0, (W - 1), (H - 1)) then

begin

MoveMouse(X, Y);

Wait(Random(1000));

ClickMouse(X, Y, mbLeft);

end;

MoveMouse(Random(X), Random(Y));

T := GetSystemTime + 300000;

//wait until the videos are done loading

repeat

Wait(Random(1000));

if (GetSystemTime > T) then

Exit;

until FindColor(X, Y, LoadMore, 0, 0, (W - 1), (H - 1));

//then watch a video

if FindColor(X, Y, YTViewColor, 0, 0, (W - 1), (H - 1)) then

begin

MoveMouse(X, Y);

Wait(Random(1000));

ClickMouse(X, Y, mbLeft);

end;

MoveMouse(Random(X), Random(Y));

Wait(35000 + Random(2000));

until False;

end.[/sCAR]

btw what are you guys doing to make use of that syntax highlighter?

Edited by johnnyfortner
Link to comment
Share on other sites

To avoid the colorfinding getting messed up with a hovering mouse over it, first check the color and then move the mouse. If the mouse is already on the box when you want to check it, get it out of the way, check it and place the mouse back.

 

Found it out the hard way...

Link to comment
Share on other sites

After looking at the change log I found that the wiki is out of date for a lot of things, updated working script with clicking button nearest mouse:

[sCAR]program YLHProgram;

 

const

YTViewColor = 3322973;

LoadMore = 61695;

 

var

W, H: Integer;

X, Y: Integer;

T: Integer;

TestBox: TBox;

 

begin

TestBox := GetClient.ImageArea;

GetBoxSize(TestBox, W, H);

TSCARWindowClient(GetClient).Activate;

repeat

//load more videos

if FindColor(X, Y, LoadMore, 0, 0, (W - 1), (H - 1)) then

begin

MoveMouse(X, Y);

Wait(Random(1000));

ClickMouse(X, Y, mbLeft);

end;

Wait(Random(2000));

MoveMouse(Random(X), Random(Y));

T := GetSystemTime + 300000;

//wait until the videos are done loading

repeat

Wait(Random(2000));

if (GetSystemTime > T) then

Exit;

until FindColor(X, Y, YTViewColor, 0, 0, (W - 1), (H - 1));

//then watch a video

GetMousePos(X, Y);

if FindColorSpiral(X, Y, X, Y, YTViewColor, 0, 0, (W - 1), (H - 1)) then

begin

Wait(Random(1500));

MoveMouse(X, Y);

Wait(Random(750));

ClickMouse(X, Y, mbLeft);

end;

Wait(Random(2000));

MoveMouse(Random(X), Random(Y));

Wait(34000 + Random(2000));

until False;

end.[/sCAR]

Link to comment
Share on other sites

After looking at the change log I found that the wiki is out of date for a lot of things, updated working script with clicking button nearest mouse:

 

0. Tutorial section

 

1. Learn SCAR Standards

 

[sCAR]

program ScarStandards;

 

var

X, Y, W: Boolean; // Global variables

 

procedure WriteIt(Text: String);

var

a: Integer; // Local variable

begin

a := RandomRange(0, 10000);

WriteLn(IntToStr(a) + ': ' + Text);

 

// Use camelcase IntToStr not inttostr

 

end;

 

begin

 

if X then //Use TAB key or Ctrl+Shift+i to indent

X := True // No semi-colon, if it is just one statement

else // This means if X is not true then execute this

X := False; // Also one statement make sure this has a semi-colon

 

if Y then

begin

Y := True;

Y := True;

end

else

begin

Y := False;

Y := False; // Multiple statements

Y := False;

end;

 

// Nested: Things get tricky here, I doubt you will ever need to do this

// most of the time you will use begin end; because you need multiple statements

// The rule is if using "if then" "else" without begin end no semi-colon until

// the last one which in this case is: WriteLn('W, X and Y are not true');

 

if Y then

if X then

if W then

WriteLn('All of these have to be true for this to be written')

else

WriteLn('W is not True')

else

WriteLn('W and X are not true')

else

WriteLn('W, X and Y are not true');

 

end.

 

Dug up the script i made using the standards xD

[/sCAR]

 

2. Practice, read, search, explore the functions.

 

Then things should be more clear.

The wiki will be updated eventually. We can always help you, but ask the right/ or just any questions if you need help. But if you contradict yourself then you need to give it more thought lols.

 

Try to split things into smaller functions, instead of garbling it all up in the main loop. You could make a function just for finding the colors/w/e and do it repeatedly try to find em for like x time. Etc.

 

Then you don't have to repeat and nest as much...

Link to comment
Share on other sites

Ok, So what I'm trying to do now is, click YTViewColor, wait, click it again then click LoadMore. But I also want if it can't find any YTViewColor then click LoadMore again. This is what I have, and it clicks YTViewColor, waits, clicks it again, clicks LoadMore then completely stops searching(haven't been able to test if it clicks loadmore if there are no ytviewcolor) any ideas?

[sCAR]program YLHProgram;

 

const

YTViewColor = 3322973;

LoadMore = 61695;

 

var

W, H: Integer;

X, Y: Integer;

T: Integer;

TestBox: TBox;

Int: Integer;

 

procedure FindLoadButton;

begin

GetMousePos(X, Y);

if FindColorSpiral(X, Y, X, Y, LoadMore, 0, 0, (W - 1), (H - 1)) then

begin

MoveMouse(X, Y);

Wait(Random(1000));

ClickMouse(X, Y, mbLeft);

end;

Wait(Random(2000));

MoveMouse(Random(X), Random(Y));

T := GetSystemTime + 300000;

repeat

Wait(Random(1000));

if (GetSystemTime > T) then

Exit;

until FindColor(X, Y, YTViewColor, 0, 0, (W - 1), (H - 1))

end;

 

function PixelCondition: Boolean;

begin

GetMousePos(X, Y);

result := FindColorSpiral(X, Y, X, Y, YTViewColor, 0, 0, (W - 1), (H - 1))

if (result) then

begin

Wait(Random(1500));

MoveMouse(X, Y);

Wait(Random(750));

ClickMouse(X, Y, mbLeft);

Wait(Random(2000));

MoveMouse(Random(X), Random(Y));

Wait(34000 + RandomRange(750,2500));

end;

end;

 

procedure MainLoop;

begin

TestBox := GetClient.ImageArea;

GetBoxSize(TestBox, W, H);

TSCARWindowClient(GetClient).Activate;

Int := 0;

repeat

Inc(Int)

if (PixelCondition) then

continue

else

FindLoadButton;

until Int = 2;

FindLoadButton;

end;

 

begin

MainLoop;

end.[/sCAR]

Edited by johnnyfortner
Link to comment
Share on other sites

[sCAR]

repeat

Inc(Int)

if (PixelCondition) then

continue

else

FindLoadButton;

until Int = 2;

FindLoadButton;[/sCAR]

this is the section I'm asking about, if the YTViewButton is there, click it repeat twice, if its not there or the loop is out of bounds find the loadbutton. How do I get it to do exactly that? What I've written works for the most part, but it equally doesn't work as well.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...