PDA

View Full Version : [TUT] EngageTheRage’s User Interaction Tutorial (SMART8)



EngageTheRage
04-24-2013, 10:16 PM
Posted Here As I Do Not Have Permission To Create A Thread In The Help & Guides Section :(

Ok, so to start hi there! I’m fairly new round here but would like to say thank you to the chat members who have answered a lot of my questions, and to all the guys that have written great tutorials.

I haven’t seen any tutorials for anything like this so I thought I would post my own :)

REQUIREMENTS:
You NEED to be comfortable with creating onscreen text and pictures. Also TPA’s and ATPA’s are used (but you can get away with just copying)



Now then, onto the reason you have clicked on this thread!

User Interaction

I am going to show you how to allow your users to manipulate your script once it is already running (without disabling smart or pausing the script).

Firstly though, some of the uses of this:
I wanted my users to be able to change the combat skill that was being trained without ending the script.
I wanted them to be able to toggle the bone collection/burial in my script without ending it.
I wanted them to be able to see all the data I had collected, but there was too much of it to show in a small onscreen progress report.

The first problem we need to tackle is how can the user interact with SMART?

Just before trying out user interaction, I had just written a method to check if anyone started talking to me or if a random spoke to me. To do this I checked with a certain area (the chatbox) for blue text of players talking, and checked the main screen for yellow text and then using TPA’s/ATPA’s checked that text for the characters name.



function AreNoobsTalking: Boolean;
var
xc, yc, n: Integer;
gameText: String;
TPA: TPointArray;
ATPA: T2DPointArray;
textBox: TBox;
begin
MyDeBug('checking for nooblets .... ');
Result := False;
if FindColor(xc, yc, 16711680, 6, 345, 494, 457) then
begin
MyDeBug('Noobs be Talking!');
PlaySound('C:\Simba\noobsTalking.wav');
Result := True;
end;

if FindColorsTolerance(TPA, 65535, MSX1, MSY1, MSX2, MSY2, 0) then
begin
ATPA := SplitTPAEx(TPA, 10, 10);

for n := 0 to length(ATPA)-1 do
begin
textBox := GetTPABounds(TPA);
SMART_DrawBox(textBox);
gameText := GetTextAtExWrap(textBox.x1, textBox.y1, textBox.x2, textBox.y2, 0, 6, 2, 65535, 10, 'UpChars07');
MyDeBug(gameText);
if (ExecRegExpr('.*'+Players[0].Nick+'.*', gameText)) then
begin
MyDeBug('Did someone say my name?!?!');
PlaySound('C:\Simba\whoSaidMyName.wav');
wait(1000);
end;
end;
end;
end;


so having just done that my idea was to use the area in which a user can type.

This is what my onscreen progress report looked like:

20907

as you can see it says press ‘0’

in my script I had this little piece of code being checked all the time:



gameText := GetTextAtExWrap(6, 457, 494, 472, 0, 6, 2, 16711680, 10, 'SmallChars07');
MyDeBug('gametext is: ' + gameText);
if (ExecRegExpr('.*'+'0'+'.*', gameText)) then
begin
BringUpStatistics;
end;


so if a blue 0 appears in the area a user types, a statistics screen is bought up!

20906

(the area I mentioned early that checks for other people talking, doesn’t cover the entire chatbox so you typing wont ring alarm bells)

So that’s about as difficult as it gets, next you just have to set the procedure to create your onscreen statistics report!

Just to mention, to start this off i get SMART to press backspace so as to clear the area we are searching so that the next time you get text the 0 isnt still there.



procedure BringUpStatistics;
var
gameText: String;
xc, yc, timeToNextLvl, hrs, mins: Integer;
begin
MyDeBug('bringing up stats ...');
PressKey(8);
KeyUp(8);
xc := 15;
yc := 15;
currentXp := MyGetXp(True, cbSkill);
xpToGo := MyGetXp(false, cbSkill) - currentXp;
xpPerHour := ((currentXp-startXp) * 3600) / (GetTimeRunning / 1000);
timeToNextLvl := (xpToGo*100) / (xpPerHour);
while (timeToNextLvl >= 100) do
begin
inc(hrs);
timeToNextLvl := timeToNextLvl - 1;
end;
mins := timeToNextLvl * 60 / 100;
SMART_ClearCanvas;
SMART_DrawBitmap(false, statisticsMenu, Point(xc, yc));
SMART_DrawTextEx(false, xc+141, yc+73, 'UpChars07', MyGetTimeRunning, 255);
SMART_DrawTextEx(false, xc+80, yc+99, 'UpChars07', IntToStr(xpPerHour), 255);
SMART_DrawTextEx(false, xc+182, yc+123, 'UpChars07', cbSkill, 255);
SMART_DrawTextEx(false, xc+112, yc+152, 'UpChars07', IntToStr(startLvl), 255);
SMART_DrawTextEx(false, xc+116, yc+177, 'UpChars07', IntToStr(GetSkillLevel(cbSkill)), 255);
SMART_DrawTextEx(false, xc+91, yc+204, 'UpChars07', IntToStr(startXp), 255);
SMART_DrawTextEx(false, xc+116, yc+230, 'UpChars07', IntToStr(currentXp), 255);
SMART_DrawTextEx(false, xc+149, yc+254, 'UpChars07', IntToStr(xpToGo), 255);
SMART_DrawTextEx(false, xc+190, yc+283, 'UpChars07', IntToStr(hrs) + 'hrs ' + IntToStr(mins) +'mins', 255);

for n := 0 to length(lootCounter)-1 do
begin
SMART_DrawTextEx(false, xc+300, yc+73, 'UpChars07', namedLoot[n] + ': ' + IntToStr(lootCounter[n]), 255);
yc := yc + 27;
end;

repeat
gameText := GetTextAtExWrap(6, 457, 494, 472, 0, 6, 2, 16711680, 10, 'SmallChars07');
if (ExecRegExpr('.*'+'9'+'.*', gameText)) then
begin
MyDeBug('9 pressed ... exiting ...');
PressKey(8);
KeyUp(8);
break;
end;
if (ExecRegExpr('.*'+'1'+'.*', gameText)) then
begin
MyDeBug('1 pressed ... bringing up options ...');
end;
until(false)
SMART_ClearCanvas;
ProduceProgressReport;
end;


what this here does is place my statistcs picture and then calculates all the requires information and then places it onto the picture.


Im sorry if this is a little vague, but if you can understand it then you can see that there is a lot that you can do with this.

20908

^^ thats another screen i have, there are loads of thing you can do and allow the user to change variables mid script!

if you have any feedback on how to improve the guide and/or script please, fire away ... just try not to hurt my feeling too much :p

Thanks For Reading!

Chris!
04-24-2013, 10:20 PM
Nice guide, I did not know about this!

Maybe you could remove some of the spacing in the thread to compress it. :)

Olly
04-24-2013, 10:28 PM
heh, i did something like this once but I did it via if the users real mouse was over a area for 5 seconds it would change :p

EngageTheRage
04-24-2013, 10:41 PM
Nice guide, I did not know about this!

Maybe you could remove some of the spacing in the thread to compress it. :)

yeah have done ... thanks :)


heh, i did something like this once but I did it via if the users real mouse was over a area for 5 seconds it would change :p

its quite cool i think :) i just like being able to show all the stats ive calculated and show what loot has been collected :)