SRL Archive - SRL Archives

A few waiting functions


Frt

2009-05-10 03:27:49

I was kinda extremely bored and had half an hour with nothing to do so I thought that these function might be handy for someone when scripting:

var
FS, FSC: Integer;

{*******************************************************************************
function Randomize(x, P: Integer): Integer;
By: Frt
Description: Randomizes x by a percentage (P)
*******************************************************************************}
function Randomize(x, P: Integer): Integer;
var
T: Integer;
begin
T := Round(x / 100 * P);
Result := RandomRange(x - T, x + T);
end;

{*******************************************************************************
procedure W(a, b: Integer);
By: Frt
Description: Waits an amount of time specified by a. Also randomizes the number
*******************************************************************************}
procedure W(a: Integer);
begin
Wait(Randomize(a, 15));
end;

{*******************************************************************************
function FailSafe(a, TimeOut: Integer): Boolean;
By: Frt
Description: A failsafe function.
a = Tries
TimeOut = If time from last try is greater than TimeOut, the counter is reset.
*******************************************************************************}
function FailSafe(a, TimeOut: Integer): Boolean;
begin
if (TimeFromMark(FS) > TimeOut) then
DecEx(FSC, FSC);
Inc(FSC);
MarkTime(FS);
Result := (FSC <= a);
end;

It's nothing impressive really, it's really basic.
But it's handy for neating up your code and then RandomRange is faster than what some people do ( Wait(100 + Random(100)); ).

malotthouse

2009-05-10 08:07:56

Hmm, It may be basic but it also saves time for some things like simple failsafes, etc. Is it already implemented into srl or do i need to copy it into a new scar document to call upon?

Floor66

2009-05-10 09:53:20

You need to copy it in to your script ;)

malotthouse

2009-05-11 02:52:19

thanks :)