SRL Archive - Reflection Development

Reflection - Timing


vilon

2009-07-10 12:43:24

Hello everyone, felt like the quite recent changes in SRL to Timing.scar should be added to reflection as well.
Here's my outcome:

//------------------------------------------------------------------\\
//-- Scar Non-Standard Resource Library --||
//-- ยป Reflection Routines - Timing --||
//------------------------------------------------------------------//
// * function R_WaitOptionMulti(S: TStringArray; Time: Integer): Boolean; // * by Marpis, N1ke! & vilon
// * function R_WaitOption(S: string; Time: Integer): Boolean; // * by Marpis, N1ke! & vilon
// * function R_WaitActionMulti(S: TStringArray; Time: Integer): Boolean; // * by vilon
// * function R_WaitAction(S: string; Time: Integer): Boolean; // * by vilon
// * function R_WaitUpTextMulti(S: TStringArray; Time: Integer): Boolean; // * by Marpis, N1ke! & vilon
// * function R_WaitUpText(S: string; Time: Integer): Boolean; // * by Marpis, N1ke! & vilon
// * function WaitAnimation(Time: Integer): Integer; // * by lordsaturn & vilon
// * function WaitAnimationBool(Time: Integer): Boolean; // * by vilon
// * function WaitMenu(Time: Integer): Boolean; // * by Drags111 & vilon
// * function WaitToMove(Time: Integer): Boolean; // * by lordsaturn & vilon

function R_ChooseOptionMulti(Options: TStringArray): Boolean; forward;
function R_ChooseActionMulti(Actions: TStringArray): Boolean; forward;
function R_IsUpTextMulti(UpText: TStringArray): Boolean; forward;
function GetAnimation: Integer; forward;
function IsOptionMenuOpen: Boolean; forward;

{*******************************************************************************
function R_WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
By: Marpis, N1ke! & vilon
Description: Waits for a TStringArray of Options and selects one of them.
*******************************************************************************}
function R_WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
var
T: Integer;
begin
Result := False;
T := GetSystemTime + Time;
repeat
Result := R_ChooseOptionMulti(S);
Wait(20 + Random(10));
until(Result or (GetSystemTime > T));
end;

{*******************************************************************************
function R_WaitOption(S: string; Time: Integer): Boolean;
By: Marpis, N1ke! & vilon
Description: Waits for an Option and selects it.
*******************************************************************************}
function R_WaitOption(S: string; Time: Integer): Boolean;
begin
Result := R_WaitOptionMulti([S], Time);
end;

{*******************************************************************************
function R_WaitActionMulti(S: TStringArray; Time: Integer): Boolean;
By: vilon
Description: Waits for a TStringArray of Actions and selects one of them.
*******************************************************************************}
function R_WaitActionMulti(S: TStringArray; Time: Integer): Boolean;
var
T: Integer;
begin
Result := False;
T := GetSystemTime + Time;
repeat
Result := R_ChooseActionMulti(S);
Wait(10 + Random(20));
until(Result or (GetSystemTime > T));
end;

{*******************************************************************************
function R_WaitAction(S: string; Time: Integer): Boolean;
By: vilon
Description: Waits for an Action and selects it.
*******************************************************************************}
function R_WaitAction(S: string; Time: Integer): Boolean;
begin
Result := R_WaitActionMulti([S], Time);
end;

{*******************************************************************************
function R_WaitUpTextMulti(S: TStringArray; Time: Integer): Boolean;
By: Marpis, N1ke! & vilon
Description: Waits for a TStringArray of UpText, returns true if found.
*******************************************************************************}
function R_WaitUpTextMulti(S: TStringArray; Time: Integer): Boolean;
var
T: Integer;
begin
Result := False;
T := GetSystemTime + Time;
repeat
Result := R_IsUpTextMulti([S]);
Wait(20 + Random(20));
until(Result or (GetSystemTime > T));
end;

{*******************************************************************************
function R_WaitUpText(S: string; Time: Integer): Boolean;
By: Marpis, N1ke! & vilon
Description: Waits for an UpText, returns true if found.
*******************************************************************************}
function R_WaitUpText(S: string; Time: Integer): Boolean;
begin
Result := R_WaitUpTextMulti([S], Time);
end;

{*******************************************************************************
function WaitAnimation(Time: Integer): Integer;
By: lordsaturn & vilon
Description: Waits for an animation with a timeout. If an animation occurs, the
value will be returned, else returns -1.
*******************************************************************************}
function WaitAnimation(Time: Integer): Integer;
var
T: Integer;
begin
Result := -1;
T := GetSystemTime + Time;
repeat
Result := GetAnimation;
Wait(100);
until((Result <> -1) or (GetSystemTime > T));
end;

{*******************************************************************************
function WaitAnimationBool(Time: Integer): Boolean;
By: vilon
Description: Waits for an animation with a timeout. Returns true on animation.
*******************************************************************************}
function WaitAnimationBool(Time: Integer): Boolean;
begin
Result := (WaitAnimation(Time) <> -1);
end;

{*******************************************************************************
function WaitMenu(Time: Integer): Boolean;
By: Drags111 & vilon
Description: Waits until the menu is open or times out.
*******************************************************************************}
function WaitMenu(Time: Integer): Boolean;
var
T: Integer;
begin
Result := False;
T := GetSystemTime + Time;
repeat
Result := IsOptionMenuOpen;
Wait(10 + Random(20));
until(Result or (GetSystemTime > T));
end;

{*******************************************************************************
function WaitToMove(Time: Integer): Boolean;
By: lordsaturn & vilon
Description: Waits for the local player to move with a timeout. Returns true if
moved, false if timed out.
*******************************************************************************}
function WaitToMove(Time: Integer): Boolean;
var
T, Player: Integer;
begin
Result := False;
T := GetSystemTime + Time;
repeat
Player := SmartGetFieldObject(0, MyPlayer);
Result := (SmartGetFieldInt(Player, CharMotion) > 0);
SmartFreeObject(Player);
Wait(100);
until(Result or (GetSystemTime > T));
end;

I tried to keep the same layout for every waiting function, as I belive it's better. Also, I wasn't sure if it would be better to include other similar waiting functions, which already are in the reflection include, but decided to do so.

WaitAnimation is \Characters.scar\function WaitForAnim
WaitAnimationBool is \Characters.scar\function CharAnimBool
WaitToMove is \MMWalk.scar\function WaitToMove

Original credit is kept for the functions I merely slightly changed and/or changed into reflection, which is basicly all of them.

Thoughts/ideas on this?

marpis

2009-07-10 14:38:51

I think these should be added to Reflection :)
Nice job

mormonman

2009-07-10 15:20:00

I think n1ke is already doing this.

Gu3st...

2009-07-12 02:14:00

Yeah, why not? Add it!
And welcome back vilon :D
2 years or so since last time I saw you around :)

Naike

2009-07-12 03:20:20

From: mormonman
I think n1ke is already doing this.


I kept it inside my script instead, was to lazy to commit and so on.

Baked0420

2009-07-12 04:50:43

I think it should be added, it can only help reflection scripters, and Zytex, he joined Sept. 2007, that wasn't two years ago yet :p

Gu3st...

2009-07-13 00:53:21

From: Baked0420
I think it should be added, it can only help reflection scripters, and Zytex, he joined Sept. 2007, that wasn't two years ago yet :p

Yes, I noticed xD
Replace the "2" with "1" then :P

Naike

2009-07-13 05:39:44

I've committed it to Dev SVN.

vilon

2009-07-13 14:21:07

From: Zyt3x
Yeah, why not? Add it!
And welcome back vilon :D
2 years or so since last time I saw you around :)


Thanks :). Yeah, it's been a while.

From: N1ke!
I've committed it to Dev SVN.


Looks great!

ShowerThoughts

2009-07-13 14:25:18

Scar 3.21 is not working for me I better post this on Freddy's thread, but I have to check my post count soo….