Mysterio Posted November 24, 2012 Share Posted November 24, 2012 Hiya, I'm trying to enhance a script of mine for PRSC that I am working on. Basically what I have is a procedure that detects if I am logged out but at the end of it - it detects if I am doing what I was doing before I logged out. Here is what I need help with: If it detects that I am not doing what I was doing before I logged out, It waits for me to click my mouse, before resuming the other procedures of the script. Basically I don't want it to try and automatically resume the other procedures, I want it to wait for my human input from the mouse (Yes I am aware of the GetKeyState function, but I would prefer it to wait for my mouse action, to make the procedure as seamless as possible). Here is the code for the procedure: procedure logged; begin Wait(100); If FindBitmap(x, y, outt, 0, 0, 511, 343) then begin repeat WriteLn('You are logged out, log back in'); PlaySound('c:\notify.wav'); Wait(10000) until not FindBitmap(x, y, outt, 0, 0, 511, 343); Wait(5000) begin if FindBitmap(x, y, beat, 0, 0, 511, 343) then begin repeat Wait(3000); WriteLn('Waiting for Mouse Click after logout') until GetMouseBtnState(mbLeft); WriteLn('About to resume!'); Wait(100); end; end; end; end; P.S I would appreciate it, if you could help me with the raw code on how to do it (if it can be done) as a priority over using an include and if it is in an include a reference to it would also be nice on top of the raw code. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 24, 2012 Share Posted November 24, 2012 (edited) Okay, this was confusing. It looks like this code already "waits" for your mouse input. But now you want it to Terminate the script when you click your mouse instead of resume the script? Or you just want a better way to do this? You can't pause a script from SCAR but you can have a loop like you did there. You can use TaskMessageDlg. [scar] program test; begin case TaskMessageDlg('Script detected not running the same as b4: ', 'Do you wish to resume the script or terminate?', mtWarning, [mbRetry, mbCancel]) of mrRetry: Exit; mrCancel: TerminateScript; end; end. [/scar] Or maybe you want it to wait some time, so you can move your player back into position. Or wait until your done using the mouse? You could detect if the mouse button was ever pushed down within a 10 second period. And if it isn't then resume the script... Just check every second or so maybe. Edited November 24, 2012 by LordJashin Quote Link to comment Share on other sites More sharing options...
Mysterio Posted November 24, 2012 Author Share Posted November 24, 2012 TaskMessageDlg is a little too complicated for me at the moment. It looks like this code already "waits" for your mouse input. Yes it does look like it waits for it, but the reality is that it doesn't. Here is a test script to show you what I mean: program New;var x, y: integer; Bmp: TSCARBitmap; begin Bmp := TSCARBitmap.Create('deNrtldEJwDAIRF2gk3X/edqvQvBUTjEQiveVg' + 'DV5eja3XPKMWiWfzO2fGNft7uNUJXGN9VeRSuSJCGgm8e5mlouxDeYMuhAssoD' + 'qK6/LGMZ4gCwLdqoMaJJ6Tlgja5ZmAPHn0A7INL0ASBq7HRBzFgD5ifCsElg08' + 'Kp3qPlMBCPgTW5qAFORp704BX+ORkfpBYnyQpU='); begin if FindBitmap(x, y, Bmp, 0, 0, 511, 343) then begin repeat Wait(3000); WriteLn('Waiting for Mouse Click') until (GetMouseBtnState(mbleft) = true); end; end; end. Paste that into scar and target the scar code window with the crosshair. Now based on my understanding, it should wait for my left mouse click before getting out of the loop and ending the script - but it doesn't wait for my mouse click and still gets out of the loop. If I change the true to false and hold down my left button after pressing play, it will wait until I let go of the button to get out of the loop. Or maybe you want it to wait some time, so you can move your player back into position. That's pretty much it. It waits to find a certain bitmap from what I was doing, then once it finds that bitmap, I just want it to loop until I click my mouse, but from my code above, it doesn't wait Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 24, 2012 Share Posted November 24, 2012 The GetMouseBtnState works. But it is kind of finicky. It does wait. BUT if you CLICK the play button to play the script. It actually detects that click in the GetMouseBtnState. So you need to wait a couple seconds so it doesn't get mixed up. Or run it using the F9 key: [scar] program New; var x, y: integer; Bmp: TSCARBitmap; begin Bmp := TSCARBitmap.Create('deNrtldEJwDAIRF2gk3X/edqvQvBUTjEQiveVg' + 'DV5eja3XPKMWiWfzO2fGNft7uNUJXGN9VeRSuSJCGgm8e5mlo uxDeYMuhAssoD' + 'qK6/LGMZ4gCwLdqoMaJJ6Tlgja5ZmAPHn0A7INL0ASBq7HRBzFgD5i fCsElg08' + 'Kp3qPlMBCPgTW5qAFORp704BX+ORkfpBYnyQpU='); wait(5000); if FindBitmap(x, y, Bmp, 0, 0, 511, 343) then begin repeat Wait(3000); WriteLn('Waiting for Mouse Click') until (GetMouseBtnState(mbleft)); end; WriteLn(GetMouseBtnState(mbLeft)); end. [/scar] Quote Link to comment Share on other sites More sharing options...
Mysterio Posted November 24, 2012 Author Share Posted November 24, 2012 Ahhh! Ok thank you for your help, but the problem is, there will be quite a few clicks throughout the running of the script... It seems as if the GetMouseBtnState remembers all clicks that have been done throughout the time the script runs on a Global basis. I tried your script, still didn't work. So I separated the wait time by calling procedures and it still didn't work.. program New; var x, y: integer; Bmp: TSCARBitmap; procedure Mouse; begin Bmp := TSCARBitmap.Create('deNrtldEJwDAIRF2gk3X/edqvQvBUTjEQiveVg' + 'DV5eja3XPKMWiWfzO2fGNft7uNUJXGN9VeRSuSJCGgm8e5mlouxDeYMuhAssoD' + 'qK6/LGMZ4gCwLdqoMaJJ6Tlgja5ZmAPHn0A7INL0ASBq7HRBzFgD5ifCsElg08' + 'Kp3qPlMBCPgTW5qAFORp704BX+ORkfpBYnyQpU='); Wait(15000); begin if FindBitmap(x, y, Bmp, 0, 0, 511, 343) then begin repeat Wait(3000); WriteLn('Waiting for Mouse Click') until (GetMouseBtnState(mbleft) = true); end; end; end; procedure qwait; begin Wait(5000); end; begin qwait; Mouse; end. ^ Doesn't work. Is there a way we can make this work? Or is it something we need Freddy to address in SCAR itself? Quote Link to comment Share on other sites More sharing options...
Janilabo Posted November 24, 2012 Share Posted November 24, 2012 Is it finding the bitmap? It could be that bitmap was not found, try adding some WriteLn()'s to your script to locate the problem part. Have you set Bmp.TranspColor to the color you want to ignore in searching? (This could be 1 of the reasons) Edit: Actually that 1 WriteLn() does the job more than well. Does it get inside the loop? Quote Link to comment Share on other sites More sharing options...
Mysterio Posted November 24, 2012 Author Share Posted November 24, 2012 Yeah Janilabo, the Waiting for Mouse Click comes up, so it is definitely executing off of finding the bitmap. The bitmap in the test script above is just of the Program New; - - - Updated - - - I just tested GetKey state in that latest test script and it works exactly the same.. (on a Global Basis) Quote Link to comment Share on other sites More sharing options...
Janilabo Posted November 24, 2012 Share Posted November 24, 2012 Damn yeah, I see what you mean now. :\ Quote Link to comment Share on other sites More sharing options...
Mysterio Posted November 24, 2012 Author Share Posted November 24, 2012 Yah . I can understand the need for GetKeyState to work on a Global basis, but GetMouseBtnState I hope it is something Freddy can address in the next update, for now I can make a work around in my script, but it would be lovely to be able to make my script seamless in the future with GetMouseBtnState Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 24, 2012 Share Posted November 24, 2012 (edited) What exactly is the problem? EDIT: Janilabo explained the issue to me. GetMouseBtnState will return true if the mouse button was clicked since the last time GetMouseBtnState was called. So if you want to reset it before the loop, just call GetMouseBtnState before looping. GetCurrentKeyState(VK_LBUTTON) in the loop would work as well Edited November 24, 2012 by Freddy Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 24, 2012 Share Posted November 24, 2012 What exactly is the problem? EDIT: Janilabo explained the issue to me. GetMouseBtnState will return true if the mouse button was clicked since the last time GetMouseBtnState was called. So if you want to reset it before the loop, just call GetMouseBtnState before looping. GetCurrentKeyState(VK_LBUTTON) in the loop would work as well Aww, you beat me to that one. I was going to mention that vk constant...arggg lol Quote Link to comment Share on other sites More sharing options...
Mysterio Posted November 24, 2012 Author Share Posted November 24, 2012 What exactly is the problem? EDIT: Janilabo explained the issue to me. GetMouseBtnState will return true if the mouse button was clicked since the last time GetMouseBtnState was called. So if you want to reset it before the loop, just call GetMouseBtnState before looping. GetCurrentKeyState(VK_LBUTTON) in the loop would work as well Thank you very much Freddy! It now works as I wanted Thank you too Jashin and Janilabo. Quote Link to comment Share on other sites More sharing options...