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:
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)); ).
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)); ).