Well I've compiled some of the functions I made which never really got noticed, so I want to give them a second chance at living. Here they are:
SCAR Code:{*******************************************************************************
function PercentProc(Proc : procedure; Percent : Integer) : Boolean;
By: R1ch
Description: Has a Percent/100 chance of calling a procedure (Proc)
Example: PercentProc(@Write, 60);
*******************************************************************************}
function PercentProc(Proc : procedure; Percent : Integer) : Boolean;
begin
if not InRange(Percent, 1, 99) then
begin
srl_Warn('PercentProc', 'Percent should be within 1 and 99 ', warn_AllVersions);
Exit;
end;
Result:= Random(100) <= Percent;
if Result then
Proc();
end;
{*******************************************************************************
function PercentBool(Func : function : Boolean; Percent : Integer) : Boolean;
By: R1ch
Description: Has a Percent/100 chance of calling a Boolean Function (Func)
*******************************************************************************}
function PercentBool(Func : function : Boolean; Percent : Integer) : Boolean;
begin
if not InRange(Percent, 1, 99) then
begin
srl_Warn('PercentBool', 'Percent should be within 1 and 99 ', warn_AllVersions);
Exit;
end;
Result:= Random(100) <= Percent;
if Result then
Func();
end;
{*******************************************************************************
function PercentStr(Func : function : String; Percent : Integer) : Boolean;
By: R1ch
Description: Has a Percent/100 chance of calling a String Function (Func)
*******************************************************************************}
function PercentStr(Func : function : String; Percent : Integer) : Boolean;
begin
if not InRange(Percent, 1, 99) then
begin
srl_Warn('PercentStr', 'Percent should be within 1 and 99 ', warn_AllVersions);
Exit;
end;
Result:= Random(100) <= Percent;
if Result then
Func();
end;
{*******************************************************************************
function PercentInt(Func : function : Integer; Percent : Integer) : Boolean;
By: R1ch
Description: Has a Percent/100 chance of calling an Integer Function (Func)
*******************************************************************************}
function PercentInt(Func : function : Integer; Percent : Integer) : Boolean;
begin
if not InRange(Percent, 1, 99) then
begin
srl_Warn('PercentInt', 'Percent should be within 1 and 99 ', warn_AllVersions);
Exit;
end;
Result:= Random(100) <= Percent;
if Result then
Func();
end;
{*******************************************************************************
function PercentStrEx(Func : function : string; Percent : Integer) : string;
By: R1ch
Description: Has a Percent/100 chance of calling a String Function (Func), and
Result is Result of Func.
*******************************************************************************}
function PercentStrEx(Func : function : string; Percent : Integer) : string;
begin
if not InRange(Percent, 1, 99) then
begin
srl_Warn('PercentStr', 'Percent should be within 1 and 99 ', warn_AllVersions);
Exit;
end;
if Random(100) <= Percent then
Result:= Func();
end;
{*******************************************************************************
function PercentIntEx(Func : function : Integer; Percent : Integer) : Integer;
By: R1ch
Description: Has a Percent/100 chance of calling a Integer Function (Func), and
Result is Result of Func.
*******************************************************************************}
function PercentIntEx(Func : function : Integer; Percent : Integer) : Integer;
begin
if not InRange(Percent, 1, 99) then
begin
srl_Warn('PercentStr', 'Percent should be within 1 and 99 ', warn_AllVersions);
Exit;
end;
if Random(100) <= Percent then
Result:= Func();
end;
{*******************************************************************************
function PercentBoolEx(Func : function : Boolean; Percent : Integer) : Boolean;
By: R1ch
Description: Has a Percent/100 chance of calling a Boolean Function (Func), and
Result is Result of Func.
*******************************************************************************}
function PercentBoolEx(Func : function : Boolean; Percent : Integer) : Boolean;
begin
if not InRange(Percent, 1, 99) then
begin
srl_Warn('PercentStr', 'Percent should be within 1 and 99 ', warn_AllVersions);
Exit;
end;
if Random(100) <= Percent then
Result:= Func();
end;
{*******************************************************************************
procedure function PercentChance(Percent : Integer) : Boolean;
By: R1ch
Description: Has a Percent/100 chance of returning True
*******************************************************************************}
function PercentChance(Percent : Integer) : Boolean;
begin
Result:= Random(100) <= Percent;
end;
{*******************************************************************************
procedure MakeNorth;
By: R1ch
Description: Makes the compass North, with a 70% chance of ClickNorth, else MakeCompass
*******************************************************************************}
procedure MakeNorth;
begin
if not PercentProc(@ClickNorth, 75) then
MakeCompass('N');
end;
//If PercentProc doesn't get committed, then this MakeNorth:
procedure MakeNorth;
begin
if Random(4) = 1 then
MakeCompass('N')
else
ClickNorth
end;
{*******************************************************************************
procedure TypeMistakesExPC(Text : string; PressEnter : Boolean; PC_Chance : Integer);
By: R1ch
Description: Types Text with mistakes, then fixes them. Presses enter depending
on PressEnter. PC_Chance = % of making a mistake.
*******************************************************************************}
procedure TypeMistakesExPC(Text : string; PressEnter : Boolean; PC_Chance : Integer);
var
I, Q : Integer;
L : TStringArray;
begin
L:= ['q','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m','1','2','3','4','5','6','7','8','9','0','[',']',';','#',',','.','/','\'];
I:= Length(Text);
for I:= 1 to (High(Text) - 1) do
begin
case Random(100) of
PC_Chance..100 : TypeSendEx(Text[i], False);
0..(PC_Chance-1) : begin
Q:= Random(High(L));
if (L[Q] <> Text[i]) then
begin
TypeSendEx(L[Q], False);
Wait(250 + Random(1000));
TypeByte(VK_BACK);
Wait(RandomRange(250, 850));
end;
TypeSendEx(Text[i], False);
end;
end;
end;
TypeSendEx(Text[i], PressEnter);
end;
{*******************************************************************************
procedure TypeMistakesEx(Text : string; PressEnter : Boolean);
By: R1ch
Description: Types Text with mistakes and fixes them.
Presses enter depending on PressEnter
*******************************************************************************}
procedure TypeMistakesEx(Text : string; PressEnter : Boolean);
begin
TypeMistakesExPC(Text, PressEnter, RandomRange(4, 16));
end;
{*******************************************************************************
procedure TypeMistakesPC(Text : string; Chance : Integer);
By: R1ch
Description: Types Text with mistakes and fixes them. Presses enter.
Chance = % of making a mistake.
*******************************************************************************}
procedure TypeMistakesPC(Text : string; Chance : Integer);
begin
TypeMistakesExPC(Text, True, Chance);
end;
{*******************************************************************************
procedure TypeMistakes(Text : string);
By: R1ch
Description: Types Text with mistakes and fixes them. Presses enter.
*******************************************************************************}
procedure TypeMistakes(Text : string);
begin
TypeMistakesEx(Text, True);
end;
Thanks,
Richard

