View Full Version : Interactive Progress Reports/Scripts

12-14-2013, 03:16 AM
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.


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


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.

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

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.

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

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.

function IsRealMouseInBox(B : TBox): Boolean;
P : TPoint;
GetRealMousePos(P.X, P.Y);
Result := PointInBox(P, B);

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.

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

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.


procedure PopUpReport;
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);

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.

procedure CallProg;
if IsRealMouseInBox(inttobox(397,274,514,336)) then

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:

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!

12-14-2013, 03:18 AM
Nice work elfyy, keep it up.

12-14-2013, 06:24 AM
Nice tutorial.

12-14-2013, 08:31 AM
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.

12-14-2013, 11:55 AM
Very nicely written tutorial. I'm sure we'll see a lot more reports like yours now thanks to this.

12-14-2013, 12:35 PM
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.