Results 1 to 6 of 6

Thread: Interactive Progress Reports/Scripts

  1. #1
    Join Date
    Oct 2006
    Posts
    6,752
    Mentioned
    95 Post(s)
    Quoted
    532 Post(s)

    Default Interactive Progress Reports/Scripts

    Welcome To elfyyy's First Tutorial!

    So guys, I will try and keep this tutorial fairly short as it is mostly basic information but I will hopefully be able to show some people how to do some neat tricks to make simba scripts more interactive like some of the Reflection/injection bots out there.

    When working on my Pest Control script and some private one's I was always having to choose when doing an on screen progress report, whether to make it take up a large part of the screen to fit a lot of info on the script, or keep it small without much info. Well I was curious if there was anyway in which to get the location of you mouse within smart in order to expand a part of paint. Well luckily I was able to stumble on this "old" thread:http://villavu.com/forum/showthread.php?t=56774 As such, ALL of the credit for the mouse position finding functions and procedures are with the members who contributed on that thread, I just modified them and applied them in actual scripts.





    Now Before I go any further, I would like to Discuss some Pros/Cons with using this type of systems with Simba which by nature, doesn't have any multithreading support.
    Pro's

    • Able to provide the user a lot of information with a small footprint
    • Make it more user friendly
    • Looks quite impressive & Difficult



    Con's

    • Time consuming to implement
    • Since there is no Multithreading, it must be called constantly in script
    • Can possible slow the script down



    Well Now if you are still interested in learning more about this type of progress report system:



    On To The Fun Part!:

    So, In order to be able to get the mouse position of your physical mouse you must use 3 function:


    The first is "FindAndSetTarget"
    What this basically does is determine which client window you want, and will "set" it to it
    so any of the local coordinates will be within the specified window and not relied upon by your desktop.

    Simba Code:
    function FindAndSetTarget(TitlePrefix: String; SetAsTarget: Boolean): Boolean;
    var
      T : TSysProcArr;
      I : Integer;
    begin
      T := GetProcesses;
      for I := High(T) downto 0 do
        if StartsWith(TitlePrefix, T[I].Title) then
        begin
          Result := True;
          if SetAsTarget then SetTarget(T[I]);
          Exit;
        end;
    end;


    Next One is GetRealMousPos
    Now this one is pretty self explainitory, It sets the active window to smart by using the previous function,
    and gets the current coordinates of your mouse within the Smart window.

    Simba Code:
    procedure GetRealMousePos(var X, Y : Integer);
    var
      KMTarget, ITarget : Integer;
    begin
      KMTarget := GetKeyMouseTarget;
      ITarget := GetImageTarget;
      FindAndSetTarget('SMARTv8.3', True);
      GetTClient.IOManager.GetMousePos(X, Y);
      FreeTarget(GetImageTarget);
      SetKeyMouseTarget(KMTarget);
      SetImageTarget(ITarget);
      x := x - 8;
      y := y - 25;
    end;


    The final one is real basic as well. It is IsRealMouseInBox
    All this does is allow you to call this function within your script and it will determine if your mouse
    is within the area given within the Tbox specified.



    Simba Code:
    function IsRealMouseInBox(B : TBox): Boolean;
    var
      P : TPoint;
    begin
      GetRealMousePos(P.X, P.Y);
      Result := PointInBox(P, B);
    end;



    Now, I believe that some of those functions are within the official SRL 5, but I only have SRL-OSR and since this section is now the OSR tutorial section I will assume that you don't have access to them. Now I understand that you could combine the first and the second functions, but due to my laziness and keeping it easy to edit/explain I will keep them separate. So what you are going to want to do first of course is put those functions somewhere in your script, preferably at the top so you can reference them whenever you want throughout the script.

    The first part of your actual progress report that you are going to add is what I like to call your "base report." This is going to be your small paint section that will always be visible and contains very little information about your script. With my PC script it just says the name and the time running:


    For this function, it is done exactly like a normal progress report. So just add the paint bitmap you wish to use and all the text associated with it and place it where you think is appropriate.

    Simba Code:
    procedure BaseReport;
    begin
      SMART_DrawBitmap(True, ProgBMP, Point(396, 273));
      SMART_DrawTextMulti(False, False, [MsToTime(GetTimeRunning, Time_Short)], Point(411, 314), UpChars, 1);
    end;

    The next procedure that will be added is your "Popup Report." Similarly to your base report, it is written excactly as would be a normal progress report. With this one in contrast to your base, will be larger and should contain much more info related to your script. You will want to place this one right by you base report, in my case it was above it.





    Simba Code:
    procedure PopUpReport;
    begin
      TimeGone := (GetTimeRunning / 1000);
      Zeal := GamesWon * 2;
      ZealPH := (3600 * (Zeal)) / ((TimeGone));
      SMART_DrawBitmap(False, Prog2BMP, Point(392, 135));
      SMART_DrawTextMulti(False, False, [IntToStr(GamesWon + GamesLost)], Point(450, 147), UPChars, 1);
      SMART_DrawTextMulti(False, False, [IntToStr(GamesWon)], Point(450, 168), UPChars, 1);
      SMART_DrawTextMulti(False, False, [IntToStr(GamesLost)], Point(450, 191), UPChars, 1);
      SMART_DrawTextMulti(False, False, [IntToStr(Zeal)], Point(450, 215), UPChars, 1);
      SMART_DrawTextMulti(False, False, [IntToStr(Bought)], Point(450, 240), UPChars, 1);
    end;



    So, at this point you should have all of the mouse functions and your two progress reports in your script and you are now ready for the final one that ties all of this together!
    I call this procedure "Call Prog." What this does, is calls your Base Report and if your mouse is within the box specified, will then call your PopupReport.

    Simba Code:
    procedure CallProg;
    begin
      BaseReport;
      if IsRealMouseInBox(inttobox(397,274,514,336)) then
      begin
        PopUpReport;
        wait(100);
      end;
    end;

    I added a short wait after it to allow the user some time to read it until it flashes to go to the next procedure in the script.
    So at this point everything has been quite straight forward, and as long as you know the basics of using paint within smart, should not have been very difficult at all. The next part and I believe to be the most difficult in the sense of deciding where to place the "CallProg" procedure.
    Early in the tutorial I mentioned how this type of progress report is limited because simba doesn't support multithreading, and this is what makes this more challenging. Multithreading would allow multiple scripts to be run simultaneously within each other, so "CallProg" could be running at all times to pickup the users mouse location. Since simba doesn't support this, we must place CallProg throughout the script at ideal times in which there is a natural wait time or where the script is taking a pause.

    The most important item to keep in mind when doing this, is to not place it in the middle of a time related function that involves movement. For example you won't want to add it in the middle of the clicking part of a monster attacking loop, as this will cause that function to stop, as it will display the PopupReport and Wait. This would make the script miss the monster, and could potentially go out of range.

    Here is a quick example of my PC script using this Proggy:
    http://www.screenr.com/qBVH


    Other More Interesting Uses Of This:

    (To Be Continued)



    So I hope you guys can find some use out of this as it has some very cool possibilities!
    Make sure to let me know what you think and if I should ass anything to this or if it helped you in any way!
    Also, if you want to see how I put in in my script and where I called it at the various times, just let me know as I haven't released this version yet. Of course if you have any questions just feel free to ask!
    Last edited by Kyle; 10-16-2014 at 01:17 PM.
    “The long-lived and those who will die soonest lose the same thing. The present is all that they can give up, since that is all you have, and what you do not have, you cannot lose.” - Marcus Aurelius

  2. #2
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Nice work elfyy, keep it up.

    Forum account issues? Please send me a PM

  3. #3
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Nice tutorial.

  4. #4
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    This is actually a feature I plan to implant into AL but much more diverse. You did a great job with this tutorial, even explaining how the procedures work and why they work. Nicely done pal.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  5. #5
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Very nicely written tutorial. I'm sure we'll see a lot more reports like yours now thanks to this.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  6. #6
    Join Date
    Oct 2006
    Posts
    6,752
    Mentioned
    95 Post(s)
    Quoted
    532 Post(s)

    Default

    Thanks a lot guys! Yeah it definitely seems to be a neat way to add more customization to scripts. I think the real potential with this idea is to be able to change settings on your script in real time. You could add debuging your tpa's by clicking on that part of your proggy, or you could make a AutoMiner go from powermine to bank mining. I'm currently testing some similar stuff and will edit my tut after a bit.
    “The long-lived and those who will die soonest lose the same thing. The present is all that they can give up, since that is all you have, and what you do not have, you cannot lose.” - Marcus Aurelius

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •