johnnyfortner Posted September 18, 2012 Share Posted September 18, 2012 (edited) 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 September 18, 2012 by Freddy Quote Link to comment Share on other sites More sharing options...
LordJashin Posted September 18, 2012 Share Posted September 18, 2012 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] Quote Link to comment Share on other sites More sharing options...
johnnyfortner Posted September 18, 2012 Author Share Posted September 18, 2012 Same error, re installing scar. both of our scripts work, thanks. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted September 18, 2012 Share Posted September 18, 2012 I posted that really fast. Here is it with standards [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] Quote Link to comment Share on other sites More sharing options...
johnnyfortner Posted September 18, 2012 Author Share Posted September 18, 2012 (edited) 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 September 18, 2012 by Freddy Quote Link to comment Share on other sites More sharing options...
LordJashin Posted September 18, 2012 Share Posted September 18, 2012 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! Quote Link to comment Share on other sites More sharing options...
johnnyfortner Posted September 18, 2012 Author Share Posted September 18, 2012 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. Quote Link to comment Share on other sites More sharing options...
Bixby Sayz Posted September 18, 2012 Share Posted September 18, 2012 (edited) 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 September 18, 2012 by Bixby Sayz Quote Link to comment Share on other sites More sharing options...
johnnyfortner Posted September 18, 2012 Author Share Posted September 18, 2012 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. Quote Link to comment Share on other sites More sharing options...
Bixby Sayz Posted September 18, 2012 Share Posted September 18, 2012 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] Quote Link to comment Share on other sites More sharing options...
johnnyfortner Posted September 18, 2012 Author Share Posted September 18, 2012 (edited) 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 September 18, 2012 by johnnyfortner Quote Link to comment Share on other sites More sharing options...
Bixby Sayz Posted September 18, 2012 Share Posted September 18, 2012 btw what are you guys doing to make use of that syntax highlighter?You had in on your first post. Check your begin/end SCAR tags in your last post? Quote Link to comment Share on other sites More sharing options...
johnnyfortner Posted September 18, 2012 Author Share Posted September 18, 2012 lol I'm wondering if there's a function for finding a color that is nearest to the mouse, instead of the first one found in scan line. I've searched. Quote Link to comment Share on other sites More sharing options...
Bixby Sayz Posted September 18, 2012 Share Posted September 18, 2012 (edited) lol I'm wondering if there's a function for finding a color that is nearest to the mouse, instead of the first one found in scan line. I've searched. Have a look at FindColorSpiral. Combine that with GetMousePos and you have something. Edited September 18, 2012 by Bixby Sayz Quote Link to comment Share on other sites More sharing options...
johnnyfortner Posted September 18, 2012 Author Share Posted September 18, 2012 [sCAR] GetMousePos(X, Y); if FindColorSpiral(X, Y, YTViewColor, 0, 0, (W - 1), (H - 1)) then[/sCAR] variable expected, even though those variables are initialized. I really don't see a problem with this Quote Link to comment Share on other sites More sharing options...
MarkD Posted September 18, 2012 Share Posted September 18, 2012 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... Quote Link to comment Share on other sites More sharing options...
johnnyfortner Posted September 18, 2012 Author Share Posted September 18, 2012 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] Quote Link to comment Share on other sites More sharing options...
LordJashin Posted September 18, 2012 Share Posted September 18, 2012 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 [/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... Quote Link to comment Share on other sites More sharing options...
johnnyfortner Posted September 19, 2012 Author Share Posted September 19, 2012 (edited) 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 September 19, 2012 by johnnyfortner Quote Link to comment Share on other sites More sharing options...
Bixby Sayz Posted September 19, 2012 Share Posted September 19, 2012 To make it easier you should break each logical section out into it's own function/procedure. Ie: Have a proc named LoadMore that does the load more portion, and so on. Then it becomes much easier to manipulate your logic to get it to do what you want it to do. Quote Link to comment Share on other sites More sharing options...
johnnyfortner Posted September 19, 2012 Author Share Posted September 19, 2012 [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. Quote Link to comment Share on other sites More sharing options...
MarkD Posted September 19, 2012 Share Posted September 19, 2012 You need to find whether the button is actually there? You could do that with if(FindDTM(,,,,,,)). You'll have to load the DTM before, see tutorial section about DTMs. Quote Link to comment Share on other sites More sharing options...
johnnyfortner Posted September 19, 2012 Author Share Posted September 19, 2012 Well it's not necessary, actually It's better without it. But is there any way to simulate key presses? I searched around and could only find functions for when the user presses keys, not the program. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted September 19, 2012 Share Posted September 19, 2012 PressKey // keys using '' KeyDown // char. So 'a' 'b' 'c' KeyUp TypeText('this will type this sentence but watch out some games don't accept simulated keystrokes'); SendKeys PressVKey // virtual keys (google it) VKeyDown VKeyUp Quote Link to comment Share on other sites More sharing options...
johnnyfortner Posted September 19, 2012 Author Share Posted September 19, 2012 Thanks for all the help guys, you really helped my script evolve into what it is right now. Comparing the script in my first post to what I have now is really something. My current script functions exactly how I would like it to, and takes in account for all of the websites random glitches. Quote Link to comment Share on other sites More sharing options...