PDA

View Full Version : [SMART] Adding Paint to your script



bob_dole
06-13-2013, 01:03 AM
Thread Title: "[SMART] Adding Paint to your script"


[SMART] Adding paint to your script!
[Scroll to the bottom if you simply want to see the code. This is a learning community but I do not have any issues with people copy/pasting my code.]


What is paint?
Paint is what adds text, images, and boxes to your SMART window. It can be used to display script status, items/exp gained, events, time running, and anything else. It is really not at all hard to add to your script, and is very convenient for your users. They can see the scripts status right on the smart window, without needing to switch to simba to see the report.

I am surprised at the lack of scripts that use paint. It is really not at all hard to use. Paint makes your script looks professional, and is, once again, not at all difficult to implement. Here is an example of a paint from one of my scripts. In real life I am still drawing stick figures and have zero artistic ability but am still able to create this.

http://imageshack.us/a/img823/6020/lawcrafter.png

This paint shows the script name, what it has done, how long it has been running, recent events, and the current status. Drawing this paint was made in a little under 35 lines. No images or graphics necessary. This entire paint was created all through a series of boxes and texts.

Starting Up

Before anything you need to have the 3 S's. Simba, SRL, and Smart all need to be correctly installed. Along with the SRL and SMART include you need to add another include. This include is the SmartGraphics include. The SmartGraphics include has all of the functions we need to draw onto the client.


program BasicPaint;
{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}
{$I SRL-OSR/SRL/misc/SmartGraphics.Simba}
begin
setupSRL;
end.


To begin, you want to setup SRL as usual. Paint cannot be used without SMART so you will need to load rs in a SMART window. The next step is to create a function to draw the paint. Every time we want our Paint to update, we will need to call this function. It can be called in the main loop, in between certain steps, or maybe just at the end.

In this function we want to clear canvas to let Simba know that we are going to be drawing. In my paint I have added a parameter to indicate if the script is still running. If the script is running properly we want the paint to display that. If the script has stopped for some reason we also want the function to know that. The background of the paint will be green if running properly, and change to red if it has stopped for some reason.


Procedure Paint (Running: boolean);
var
bgColor: integer;
begin

bgColor := clGreen; // The color we want the background to be by default.

if (running) then // Checks our running boolean to see if we need to change colors.
bgColor := clRed; // Change the color to red if the script is not running.

SMART_ClearCanvas; // Clears the SMART canvas every time we call the function.

end;


So far the function clears the SMART canvas and determines what color we want our background to be. Now we will go over the basic functions that SmartGraphics.simba allows us to use.

The Basics

The two main basic functions are Smart_DrawTextEx and Smart_DrawBoxEx. As you may have guessed, Smart_DrawBoxEx adds text to our canvas and Smart_DrawTextEx will draw a box onto our canvas. Lets take a look at the arguments that we need to pass on to these functions.

Smart_DrawTextEx (Clear: Boolean; x, y: Integer; font, Text: String; Color: TColor)

Clear Boolean, will clear the canvas if true. We already cleared the canvas in our function so this will false.
X Integer, (0 to 764) The x coordinate of where our text is going to start. This will be the Horizontal positioning on the SMART window where the left corner of our text will be.
Y Integer, (0 to 502) The y coordinate of where our text is going to start. This will be the Vertical positioning on the SMART window where the left corner of our text will be.
Font String, the font style we want our text to be in. Your choices are those in the fonts folder. From biggest to smallest I tend to choose from BigChars07, SmallChars07, and StatChars07.
Text String, this is the text that we want to print on our smart canvas.
Color TColor, this is the color that want our text to be in. Possible choices are clAqua, clBlack, clBlue, clFuchsia, clGray, clGreen, clLime, clMaroon, clNavy, clOlive, clPurple, clRed, clSilver, clTeal, clWhite (white), clYellow. You can create your own colors using RGBtoColor.

So let's try an example.

Smart_DrawTextEx(false, 250, 310, 'BigChars07', 'My first Paint', clFuchsia);

False This means this will not clear the paint first before printing text.
250 Will print 250 pixels from the left side.
310 Will print 310 pixels from the top of the window.
BigChars07 Will print the text in this font.
My first Paint The text that will be printed.
clFuchsia The color of the text to be printed.

Lastly, we will add a 'wait(5000)' at the end as when the script ends all paint is removed. So far our code should look like this.



program BasicPaint;
{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}
{$I SRL-OSR/SRL/misc/SmartGraphics.Simba}

Procedure Paint (Running: boolean);
var
bgColor: integer;
begin
bgColor := clGreen; // The color we want the background to be by default.

if (not (running)) then // Checks our running boolean to see if we need to change colors.
bgColor := clRed; // Change the color to red if the script is not running.

SMART_ClearCanvas; // Clears the SMART canvas every time we call the function.
Smart_DrawTextEx(false, 250, 310, 'BigChars07', 'My first Paint', clFuchsia);
end;

begin
setupSRL;
Paint(true);
wait(5000);
end.



After compiling and running the script, your SMART window should look like this.

http://img837.imageshack.us/img837/7367/myfirstpaint.png

Smart_DrawBoxEx (Clear, Fill: Boolean; Box: TBox; Color: TColor)
Clear Boolean, will clear the canvas if true. We already cleared the canvas in our function so this will false.
Fill Boolean, Do we want to fill the box with color? Or just draw the outlines of a box.
Box TBox, The coordinates of our box. Must be in the form of a TBox, which is easy enough to create.
Color TColor, this is the same as in our last function. Scroll up for a list of possible choices.

Now let's add a box to our paint. We want to put the line of code for the box before the line for the text. Otherwise the box will overlap the text.

Smart_DrawBoxEx (false, true, IntToBox (235, 295, 489, 355), bgColor);

False We do not want to clear the paint, we already did that at the start of our function.
True We do want to fill our box with color.
TBox The coordinate of our box as a TBox. This followed the format (X1, Y1, X2, Y2). X is horizontal and Y is vertical, exactly the same as the coordinate of our text. X2 and Y2 is the coordinate that we will draw the box to.
bgColor Normally this would be 'bgColor' and paint green or red depending on the script status, but for the sake of this tutorial we will instead be using 'clWhite'.

Also, change the text to 'My second paint'.

So far our code should like this.

program BasicPaint;
{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}
{$I SRL-OSR/SRL/misc/SmartGraphics.Simba}
Procedure Paint (Running: boolean);
var
bgColor: integer;
begin
bgColor := clGreen; // The color we want the background to be by default.

if (not (running)) then // Checks our running boolean to see if we need to change colors.
bgColor := clRed; // Change the color to red if the script is not running.

SMART_ClearCanvas; // Clears the SMART canvas every time we call the function.
Smart_DrawBoxEx (false, true, IntToBox (235, 295, 489, 355), clWhite);
Smart_DrawTextEx(false, 250, 310, 'BigChars07', 'My first Paint', clFuchsia);
end;

begin
setupSRL;
Paint(true);
wait(5000);
end.


Your SMART window should look like this.

http://img5.imageshack.us/img5/8592/mysecondpaint.png

And that is it. Those are the basics of adding paint to your SMART scripts. It may take some practice before you become good at it. Be sure to mess around with these functions as much as possible. The more you mess around with these functions the better you will get with them. The function list is your friend. I can't stress this enough when coding; the function list is your friend. There are so many functions in Simba and SRL and the only way you are going to learn them is by looking them up and trying them out. There are even ways to add bitmap images to your paint.

Advanced Paint

Now that you hopefully got the basics of SmartGraphics, it is time to move on to a bit more advanced stuff. We are going to make a fully functional paint for a script. Since I am not going to include an actual script in this guide, we will be simulating our script progress a bit. We will simulate a mining script that mines iron ore, walks to bank, banks the ore, walks back to the mine and repeats. We will also be adding a possible random event and a paint that updates with every event.

I'll admit the first part of this guide starts off quite slow and is aimed for absolute beginners but I assure you it is about to speed up.

Variables

We are going to start off with the finished product of our last script. We will however be adding some new variables and functions to our script. We want to add a TStringArray so we can store a log of events inside of it. We also want an Integer to store how many ores we have mined, and a status String so we can have the script's current status on our paint.

We need to add the following code to our scripts to add our variables. It goes under the SRL, Smart, and SmartGraphics include.


var
Events: TStringArray;
Ores: Integer;
Status: String;


Misc. Functions

Next we are going to add some of my functions that were created to make things a little easier. You are free to use these in any of your scripts.

ClockReel (value: integer): This function will add an extra '0' before any one digit integer. This is used for our time function.


function ClockReel(digit: integer): string; // Convert 1 digit integer into a clock reel
begin

if (digit < 10) then // Checks if the number is less than 10
begin
result := '0' + inttostr(digit); // Adds the extra zero to the result.
Exit; // Exits function to avoid default result.
end;

result := inttostr(digit); // Default result

end;


Timize(time: integer): This function will convert any amount of seconds into hours, minutes, and seconds. Very useful when logging events or displaying time running.


function Timize(Time: Integer): String; // Converts seconds into HH:MM:SS format
var
seconds, minutes, hours: integer; // Declare our clock variables.
begin

if (time < 60) then // Checks less than 60 for an easy result.
begin
seconds := time;
Result := '0:00:' + clockReel(time); // Returns the result in HH:MM:SS
Exit;
end;

hours := floor(time / 3600); // Finds the amount of hours.
time := time - (hours * 3600); // Subtracts the hours of time.

minutes := floor(time / 60); // Finds the amount of minutes.
time := time - (minutes * 60); // Subtracts the mintues of time.

seconds := time; // Sets the remainder of time as seconds.

Result := (inttostr(hours) + ':' + clockReel(minutes) + ':' + clockReel(seconds)); // Returns the result in HH:MM:SS

end;


Log(event: String; timestamp: boolean): This function is used to change the script's status and record an event. This function has the option to add a timestamp to the event. Will also update the paint and write the line in Simba. This function must go below the others, including our paint function.


Procedure Log (event: String; timestamp: boolean); // WriteLn's/Records an event and updates paint. Adds timestamp if specified.
var
stamp: String; // Declare timestamp
begin

stamp := ''; // Sets default to blank.

status := event; // Changes our script status to the event.

if (timestamp) then // Checks out input
stamp := '[' + timize(round (GetTimeRunning / 1000)) + '] '; // Adds timestamp to event.

setLength (events, Length (events) + 1); // Add blank event to our array
events[Length(events) - 1] := stamp + event; // Changes our blank event to inputted event.

WriteLn (stamp + event); // Prints the event in simba.

Paint(true); // Updates our paint. Script is running ok so true

end;

The Simulator

All of the above functions are included in this simulator. This is what we will start off with to create our paint. Please copy the entire code into your Simba script so we can begin coding the paint. The paint procedure should be the only part of this script you need to edit.


program BasicPaint;
{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}
{$I SRL-OSR/SRL/misc/SmartGraphics.Simba}
var
Events: TStringArray;
Ores: Integer;
Status: String;

function ClockReel(digit: integer): string; // Convert 1 digit integer into a clock reel
begin

if (digit < 10) then // Checks if the number is less than 10
begin
result := '0' + inttostr(digit); // Adds the extra zero to the result.
Exit; // Exits function to avoid default result.
end;

result := inttostr(digit); // Default result

end;
function Timize(Time: Integer): String; // Converts seconds into HH:MM:SS format
var
seconds, minutes, hours: integer; // Declare our clock variables.
begin

if (time < 60) then // Checks less than 60 for an easy result.
begin
seconds := time;
Result := '0:00:' + clockReel(time); // Returns the result in HH:MM:SS
Exit;
end;

hours := floor(time / 3600); // Finds the amount of hours.
time := time - (hours * 3600); // Subtracts the hours of time.

minutes := floor(time / 60); // Finds the amount of minutes.
time := time - (minutes * 60); // Subtracts the mintues of time.

seconds := time; // Sets the remainder of time as seconds.

Result := (inttostr(hours) + ':' + clockReel(minutes) + ':' + clockReel(seconds)); // Returns the result in HH:MM:SS

end;
Procedure Paint (Running: boolean);
var
i, titleBMP, bgColor: integer;
begin
bgColor := clGreen; // The color we want the background to be by default.

titleBMP := BitmapFromString(37, 37, 'meJy9lm1rE0EUhesP8IMfCkUILa' +
'GURUIITSSlNKa4mBgJUimoUIooRYWiIIggCAUR/Ns+6WmPl9lN3Gx' +
'q4bJMNjPz3Jczd7Z3OOldW/fR08XWC5OrzLftDkbJDhUX1sPF5TWW' +
'1GPdpt2mk/WKfmdtTbYirgoayoPBtDN61Z2cmGgHFruxAFeKZqudf' +
't7Oj2Hlb77xc2urw3NjsxuNN2g+2lI4QxWaWMJh6402iPvNvU aWN9' +
'tTBnJjRRw2S9Q1S7h7G9kVa2cIC2PgqJP01sDFuBSaWJut8RU uy/U' +
'X9d0//jB4/Xl48kXEZXEiynlXzWmUweV9s3NAHgA9efd9dPYDNC+r' +
'7JwY78VSKcUCYYMoRSnt4/cX00+/rasFrEarj5Pb3WG2P0YhrcMjO' +
'2nxK42y6BWTwYmFTT7+FK40pTO3s10Er/P1cHq69+KMp86a0nh3vS' +
'kR2hS1/mUhVRNLOFI6L58KTecLSv/5W4rOk7FxaJLQMCvfueInM9n' + // This is out bitmap for our paint.
'/2fkvWDwJM5kTWeQQU2hQCA1XeTI2Dk3OcFk+s0vxxx0kEoISbh 5L' +
'k6kX5tAOXp4/Pv1KgBBjJ4mFk/69A+4hD+Fi4ZIDaBbSchrtKuMiL' +
'jkCgmogqTi0UhwgSdFplJ8YYRqnTAq33TkSTrn1eYkSKu3V6o rIGJ' +
'0oNNKIkzLQ/8TNO6TzcNa/QkNgYjFQO/IZL+LcRX019MrusqQJWyG' +
'UTCAZkUYcFnE6jMbpjdS4AKeSYZRMFKA2J0qpnp2aS5xewlLT dp8p' +
'ZjISmcAmUn4ExYqorMxRKa2HvxfEdRdN+mSRqCODJSB3J7Ooo 0vpf' +
'30ZxUY6D6eKEFcRpN1QrFm++JQurmyLJ7brYjMpBpiAoop0Xa qsci' +
'lWp7i22LiKFSydqcYbcWry8bOEHbx2xU9BqdE4HUaVL/kEupEvT7b' +
'VwVdxYbn3KsAboUScPnV0RmD5Zlk2tCq4XtnXS/Uy1cBFFS0liXq4' +
'uKS2PCriiqD/hCsNahXl/wEFu3Iw');

if (not (running)) then // Checks our running boolean to see if we need to change colors.
bgColor := clRed; // Change the color to red if the script is not running.

SMART_ClearCanvas; // Clears the SMART canvas every time we call the function.

// ================ Begin code for Paint ================



// ================ End code for Paint ================


end;
Procedure Log (event: String; timestamp: boolean); // WriteLn's & Records an event and updates paint. Adds timestamp if specified.
var
stamp: String; // Declare timestamp
begin

stamp := ''; // Sets default to blank.

status := event; // Changes our script status to the event.

if (timestamp) then // Checks out input
stamp := '[' + timize(round (GetTimeRunning / 1000)) + '] '; // Adds timestamp to event.

setLength (events, Length (events) + 1); // Add blank event to our array
events[Length(events) - 1] := stamp + event; // Changes our blank event to inputted event.

WriteLn (stamp + event); // Prints the event in simba.

Paint(true); // Updates our paint. Script is running ok so true

end;

Procedure Fail;
begin

if (randomrange(1,500) = 1) then // Choose a number between 1 and 500
begin // and checks if it is one.
Log ('Unsolvable random found, terminating script...', false); // Randomly terminates script.
Paint (false); // Paints one last time, Running as false.
wait(5000); // Waits 5 seconds.
terminatescript; // Terminates script.
end;

end;
Procedure MainLoop; // The main loop of our script.
var
i, inventory: integer; // Declares variables.
begin

repeat // Repeats forever.

repeat // Repeats until inventory is full.

if (randomrange(1,5) = 1) then // Randomly chooses 1 to 5
begin // and checks if it is 1
Ores := Ores + 1; // We mined an ore!
Inventory := Inventory + 1; // Adding the ore to inventory
Log ('We managed to mine an iron ore!', true); // Logging the event.
end;

wait(100);
Fail;
until (inventory >= 28); // Checks if our inventory is full.

Log ('We have a full inventory, banking...', true); // Logs that we have full inventory.

for i:= 1 to 5 do // Walks to bank in 5 steps.
begin
wait(randomrange(200,400)); // Simulated walking.
Log ('Walking to bank, step ' + inttostr (i) + '/5', true); // Adding our events and changing status.
Fail; // The random chance of failing.
end;

wait(randomrange(200,400)); // Simulates banking time.
Log ('Successfully banked 28 iron ore!', true); // Adds our event and changes status.

inventory := 0; // Resets our inventory to zero.

for i:= 1 to 5 do // Walks back to mine in 5 steps.
begin
wait(randomrange(200,400)); // Simulates walking time taken.
Log ('Walking back to mine, step ' + inttostr (i) + '/5', true); // Adds event and changes status
Fail; // The random chance of failing.
end;

wait(randomrange(200,400)); // Simulating walking back to mine
Log ('Successfully walked back to the mine!', true); // Adds our event and changes status.

until (false);

end;


begin
setupSRL; // Sets up SRL;
MainLoop; // The main loop of the script.
Paint(false); // Paints one last time, this time with Running as false.
end.


Making the Paint

I am getting lazy halfway through this tutorial so I am just going to post the code here and you can follow along with the comments.

The Final Code:


program BasicPaint;
{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}
{$I SRL-OSR/SRL/misc/SmartGraphics.Simba}
var
Events: TStringArray;
Ores: Integer;
Status: String;

function ClockReel(digit: integer): string; // Convert 1 digit integer into a clock reel
begin

if (digit < 10) then // Checks if the number is less than 10
begin
result := '0' + inttostr(digit); // Adds the extra zero to the result.
Exit; // Exits function to avoid default result.
end;

result := inttostr(digit); // Default result

end;
function Timize(Time: Integer): String; // Converts seconds into HH:MM:SS format
var
seconds, minutes, hours: integer; // Declare our clock variables.
begin

if (time < 60) then // Checks less than 60 for an easy result.
begin
seconds := time;
Result := '0:00:' + clockReel(time); // Returns the result in HH:MM:SS
Exit;
end;

hours := floor(time / 3600); // Finds the amount of hours.
time := time - (hours * 3600); // Subtracts the hours of time.

minutes := floor(time / 60); // Finds the amount of minutes.
time := time - (minutes * 60); // Subtracts the mintues of time.

seconds := time; // Sets the remainder of time as seconds.

Result := (inttostr(hours) + ':' + clockReel(minutes) + ':' + clockReel(seconds)); // Returns the result in HH:MM:SS

end;
Procedure Paint (Running: boolean);
var
i, titleBMP, bgColor: integer;
begin
bgColor := clGreen; // The color we want the background to be by default.

titleBMP := BitmapFromString(37, 37, 'meJy9lm1rE0EUhesP8IMfCkUILa' +
'GURUIITSSlNKa4mBgJUimoUIooRYWiIIggCAUR/Ns+6WmPl9lN3Gx' +
'q4bJMNjPz3Jczd7Z3OOldW/fR08XWC5OrzLftDkbJDhUX1sPF5TWW' +
'1GPdpt2mk/WKfmdtTbYirgoayoPBtDN61Z2cmGgHFruxAFeKZqudf' +
't7Oj2Hlb77xc2urw3NjsxuNN2g+2lI4QxWaWMJh6402iPvNvU aWN9' +
'tTBnJjRRw2S9Q1S7h7G9kVa2cIC2PgqJP01sDFuBSaWJut8RU uy/U' +
'X9d0//jB4/Xl48kXEZXEiynlXzWmUweV9s3NAHgA9efd9dPYDNC+r' +
'7JwY78VSKcUCYYMoRSnt4/cX00+/rasFrEarj5Pb3WG2P0YhrcMjO' +
'2nxK42y6BWTwYmFTT7+FK40pTO3s10Er/P1cHq69+KMp86a0nh3vS' +
'kR2hS1/mUhVRNLOFI6L58KTecLSv/5W4rOk7FxaJLQMCvfueInM9n' + // This is out bitmap for our paint.
'/2fkvWDwJM5kTWeQQU2hQCA1XeTI2Dk3OcFk+s0vxxx0kEoISbh 5L' +
'k6kX5tAOXp4/Pv1KgBBjJ4mFk/69A+4hD+Fi4ZIDaBbSchrtKuMiL' +
'jkCgmogqTi0UhwgSdFplJ8YYRqnTAq33TkSTrn1eYkSKu3V6o rIGJ' +
'0oNNKIkzLQ/8TNO6TzcNa/QkNgYjFQO/IZL+LcRX019MrusqQJWyG' +
'UTCAZkUYcFnE6jMbpjdS4AKeSYZRMFKA2J0qpnp2aS5xewlLT dp8p' +
'ZjISmcAmUn4ExYqorMxRKa2HvxfEdRdN+mSRqCODJSB3J7Ooo 0vpf' +
'30ZxUY6D6eKEFcRpN1QrFm++JQurmyLJ7brYjMpBpiAoop0Xa qsci' +
'lWp7i22LiKFSydqcYbcWry8bOEHbx2xU9BqdE4HUaVL/kEupEvT7b' +
'VwVdxYbn3KsAboUScPnV0RmD5Zlk2tCq4XtnXS/Uy1cBFFS0liXq4' +
'uKS2PCriiqD/hCsNahXl/wEFu3Iw');

if (not (running)) then // Checks our running boolean to see if we need to change colors.
bgColor := clRed; // Change the color to red if the script is not running.

SMART_ClearCanvas; // Clears the SMART canvas every time we call the function.

// ================ Begin code for Paint ================


// Print the title text
SMART_DrawTextEx (false, 22, 312, 'BigChars07', 'Iron AutoMiner', 65536);
// Draw the iron ore bitmap
SMARt_DrawBitmap(false, titleBMP, point(260, 310));

// Frees the bitmap
Freebitmap (titleBMP);

// Draw the big, surrounding black box as a border
SMART_DrawBoxEx(false, true, inttobox (7, 345, 512, 475), 65536);

// This draws the main green box, containing stats/events
SMART_DrawBoxEx(false, true, inttobox (17, 355, 502, 428), bgColor);

//Draws another black box to cut the first in half.
SMART_DrawBoxEx(false, true, inttobox (200, 349, 207, 451), 65536);

// Draws a box inside to create the lower green area, for status.
SMART_DrawBoxEx(false, true, inttobox (17, 438, 502, 465), bgcolor);
// Draws the line dividing 'status' and the actual status.
SMART_DrawBoxEx(false, true, inttobox (130, 437, 137, 467), 65536);

// Types 'Status' in large font
SMART_DrawTextEx (false, 27, 435, 'BigChars07', 'Status ', 65536);

// Types the actual status of the script.
SMART_DrawTextEx (false, 220, 445, 'UpChars07', Status, 65536);

// Types out how long the script has been running
SMART_DrawTextEx (false, 416, 328, 'UpChars07', '[' + timize(round (GetTimeRunning / 1000)) + ']', clWhite);

// Types out the ores mined.
SMART_DrawTextEx (false, 25, 371 - 13, 'SmallCharsNS07', 'Ore Mined: ', 65536);
SMART_DrawTextEx (false, 125, 371 - 13, 'SmallCharsNS07', GroupDigits (ores, ','), 65536);

// Types out the profit earned
SMART_DrawTextEx (false, 25, 410, 'SmallCharsNS07', 'Profit: ', 65536);
SMART_DrawTextEx (false, 125, 410, 'SmallCharsNS07', GroupDigits (ores * 95, ','), 65536);

// Types out the profit per hour
SMART_DrawTextEx (false, 25, 384 - 13, 'SmallCharsNS07', 'Profit/hour: ', 65536);
SMART_DrawTextEx (false, 125, 384 - 13, 'SmallCharsNS07', GroupDigits (round(1000 * (strtofloat ((floattostr (3600 * ores * 100))) / (StrToFloat (IntToStr (GetTimeRunning))))), ','), 65536);

// Types out experience
SMART_DrawTextEx (false, 25, 397 - 13, 'SmallCharsNS07', 'EXP: ', 65536);
SMART_DrawTextEx (false, 125, 397 - 13, 'SmallCharsNS07', GroupDigits (ores * 35, ','), 65536);

// Types out experience per hour
SMART_DrawTextEx (false, 25, 397, 'SmallCharsNS07', 'EXP/hour: ', 65536);
SMART_DrawTextEx (false, 125, 397, 'SmallCharsNS07', GroupDigits (Round(1000 * (strtofloat ((floattostr (3600 * 9.5 * ores))) / (StrToFloat (IntToStr (GetTimeRunning))))), ','), 65536);

// Types out events if there are less than five.
if (length(events) < 5) then
begin

for i := 0 to Length (events) - 1 do
begin
SMART_DrawTextEx (false, 220, 358 + (i * 13), 'SmallCharsNS07', events[i], 65536);
end;

end else
// Types out events if there are more than five.
begin


for i := length(events) - 5 to Length (events) - 1 do
begin
SMART_DrawTextEx (false, 220, 358 + ((Length(events) - i - 1) * 13), 'SmallCharsNS07', events[i], 65536);

end;

end;


// ================ End code for Paint ================


end;
Procedure Log (event: String; timestamp: boolean); // WriteLn's & Records an event and updates paint. Adds timestamp if specified.
var
stamp: String; // Declare timestamp
begin

stamp := ''; // Sets default to blank.

status := event; // Changes our script status to the event.

if (timestamp) then // Checks out input
stamp := '[' + timize(round (GetTimeRunning / 1000)) + '] '; // Adds timestamp to event.

setLength (events, Length (events) + 1); // Add blank event to our array
events[Length(events) - 1] := stamp + event; // Changes our blank event to inputted event.

WriteLn (stamp + event); // Prints the event in simba.

Paint(true); // Updates our paint. Script is running ok so true

end;

Procedure Fail;
begin

if (randomrange(1,500) = 1) then // Choose a number between 1 and 500
begin // and checks if it is one.
Log ('Unsolvable random found, terminating script...', false); // Randomly terminates script.
Paint (false); // Paints one last time, Running as false.
wait(5000); // Waits 5 seconds.
terminatescript; // Terminates script.
end;

end;
Procedure MainLoop; // The main loop of our script.
var
i, inventory: integer; // Declares variables.
begin

repeat // Repeats forever.

repeat // Repeats until inventory is full.

Log ('Attempting to mine an iron ore...', true); // Logging the event.

if (randomrange(1,5) = 1) then // Randomly chooses 1 to 5
begin // and checks if it is 1
Ores := Ores + 1; // We mined an ore!
Inventory := Inventory + 1; // Adding the ore to inventory
Log ('We managed to mine an iron ore!', true); // Logging the event.
end;

wait(100);
Fail;
until (inventory >= 28); // Checks if our inventory is full.

Log ('We have a full inventory, banking...', true); // Logs that we have full inventory.

for i:= 1 to 5 do // Walks to bank in 5 steps.
begin
wait(randomrange(200,400)); // Simulated walking.
Log ('Walking to bank, step ' + inttostr (i) + '/5', true); // Adding our events and changing status.
Fail; // The random chance of failing.
end;

wait(randomrange(200,400)); // Simulates banking time.
Log ('Successfully banked 28 iron ore!', true); // Adds our event and changes status.

inventory := 0; // Resets our inventory to zero.

for i:= 1 to 5 do // Walks back to mine in 5 steps.
begin
wait(randomrange(200,400)); // Simulates walking time taken.
Log ('Walking back to mine, step ' + inttostr (i) + '/5', true); // Adds event and changes status
Fail; // The random chance of failing.
end;

wait(randomrange(200,400)); // Simulating walking back to mine
Log ('Successfully walked back to the mine!', true); // Adds our event and changes status.

until (false);

end;

Procedure Kill; // Procedure to be called when the script terminates for whatever reason.
begin
writeLn ('Script terminated, you must restart.'); // Quick writeLn to inform the user that the script has ended.

Paint(false); // Tells the paint function we are no longer running. Effectively colors background to red.

end;

begin
setupSRL; // Sets up SRL;
AddOnTerminate('kill'); // Will call this function whenever the script is terminated, for any and all reasons.
MainLoop; // The main loop of the script.
Paint(false); // Paints one last time, this time with Running as false.
end.


The Final Product:

http://img838.imageshack.us/img838/6366/mythirdpaint.png

Conclusion

Well that's it. I believe I covered most of what SMART's paint capabilities can do and provided some useful functions that will hopefully produce scripts with paints. It really is quite simple and I can't think of any reason not to have a paint for your script. I kind of rushed the end because I got bored, but it still provides the reader with a good code to learn off of. Any comments, questions, suggestions, etc. please do post below.

Chris!
06-13-2013, 01:19 AM
Nice guide, well explained and easy to follow.

With the time stuff (Timize and ClockReel), I find that using the GetTimeRunning proc with the use of MsToTime suits my needs. With this, you can also change the time format.

- Time_Formal: 2 Hours, 47 Minutes and 28 Seconds
- Time_Short: 02h, 47m, 28s
- Time_Abbrev: 2 hr, 47 min, 28 sec
- Time_Bare: 02:47:28
- Time_FStop: 12.04.40

But that's just me, your method looks like it works quite well!

PM a staff member to get this moved ;).