SCAR Code:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- » AutoRespond Routines --//
//-----------------------------------------------------------------//
// * Procedure SetResponseChance(Chance: Integer); // * by N1ke!
// * Procedure SetDicArrays; // * by N1ke!
// * Function SplitName(Name: String):String; // * by N1ke!
// * Procedure RenewTrigger(var Text : TStringArray); // * by N1ke!
// * Procedure RenewAllTriggers; // * by N1ke!
// * Procedure DebugDicArrays; // * by N1ke!
// * Procedure DebugDictionary; // * by N1ke!
// * Function ReplaceSign(Text : String): string; // * by N1ke!
// * Function ChatText(Text: TStringArray): Boolean; // * by N1ke!
// * Procedure DeleteIndex(Index : Integer; var Arr : TStringArray); // * by N1ke!
// * procedure SetupSRLAutoResponder(ChanceResponse: Integer); // * by N1ke!
// * Function Responder: Boolean; // * by N1ke!
Type
RowType = Record
Trigger, Response: TStringArray;
UsedResponse: Integer;
end;
PlayerDictionary = Record
Row: Array of RowType;
end;
var
PlayerDic: Array of PlayerDictionary;
SQAA, UseAutoResponder: Boolean;
ResponseArrays: TStringArray;
ChanceResponding, ResponsesMade: Integer;
{*******************************************************************************
Procedure SetResponseChance(Chance: Integer);
By: N1ke!
Description: Sets response chance.
Example SetResponseChance(75); would set the response chance to 75%.
Reason it's a Procedure instead of just the var is the following:
Vars can be hard to remember, and is annoying to find out!
Also, you can simply find it by Clicking CTRL + Space then typing SetRes ect.
*******************************************************************************}
Procedure SetResponseChance(Chance: Integer);
begin
ChanceResponding := Chance;
end;
{*******************************************************************************
Procedure SetDicArrays;
By: N1ke!
Description: Loads the length of the arrays using the Dictionary.ini.
*******************************************************************************}
Procedure SetDicArrays;
var
i, ii : integer;
begin
SetArrayLength(PlayerDic, HowManyPlayers);
// add H vars instead
For i:= 0 to High(PlayerDic) do
begin
SetArrayLength(PlayerDic[i].Row, StrToInt(ReadIni('General', 'Rows', AppPath + 'includes\SRL\Dictionary.ini')) + 1);
For ii:= 1 to High(PlayerDic[i].Row) do
begin
SetArrayLength(PlayerDic[i].Row[ii].Trigger, StrToInt(ReadINI('Row' + IntToStr(ii), 'TriggerCount', AppPath + 'includes\SRL\Dictionary.ini'))+ 1);
SetArrayLength(PlayerDic[i].Row[ii].Response, StrToInt(ReadINI('Row' + IntToStr(ii), 'ResponseCount', AppPath + 'includes\SRL\Dictionary.ini'))+ 1);
end;
end;
end;
{*******************************************************************************
Function SplitName(Name: String):String;
By: N1ke!
Description: Makes a name into a human like nick.
Example, Input = 1 w0nt l0se output = w0nt
If a name got many spaces it will delete them and result in the 3
first letters. Example, Input = N 1 k e e Output = N1k
*******************************************************************************}
Function SplitName(Name: String):String;
var I : integer;
begin
If Length(GetOthers(Name)) < 3 then
If Pos(' ', Name) > 0 then
begin
Result := Copy(Name, Pos(' ', Name), Length(Name));
Delete(Result, Pos(' ', Result), 1);
If Pos(' ', Name) > 0 then
Delete(Result, Pos(' ', Result), Length(Result));
If Not Length(Result) <= 2 then
Exit;
end;
// add H vars instead
For I:=0 to Length(GetOthers(Name))+1do
Delete(Name, Pos(' ', Name), 1);
Result := Left(Name, 3);
end;
{*******************************************************************************
Procedure RenewTrigger(var Text : TStringArray);
By: N1ke!
Description: Renews a trigger to match the currentplayer.
*******************************************************************************}
Procedure RenewTrigger(var Text : TStringArray; Player: Integer);
var
TStrP: TStringArray;
Temp: String;
I, II, L: integer;
begin
// add H vars instead even 0..1 here
L := GetArrayLength(Text);
TStrP:= ['$name', '$namesplit'];
For I:=0 to High(Text) do
For ii:=0 to High(TStrP) do
begin
if Pos( LowerCase(TStrP[II]), LowerCase(Text[I])) > 0 then
begin
Case Lowercase(TStrP[I]) of
'$name' : Temp := Players[Player].Name;
'$namesplit' : Temp := SplitName(Players[Player].Name);
end;
Text[i] := Replace(Text[i], LowerCase(TStrP[I]), Temp);
end else Text[i] := Text[i];
end;
SetArrayLength(Text, L);
end;
{*******************************************************************************
Procedure RenewAllTriggers;
By: N1ke!
Description: Renews all triggers to match the currentplayer.
*******************************************************************************}
Procedure RenewAllTriggers;
var
i, ii: integer;
begin
// add H vars instead
For i:=0 to High(PlayerDic)do
For ii:=1 to High(PlayerDic[i].Row)do
RenewTrigger(PlayerDic[I].Row[ii].Trigger, I);
end;
{*******************************************************************************
Procedure DebugDicArrays;
By: N1ke!
Description: Debugs the length of the triggers and responses.
*******************************************************************************}
Procedure DebugDicArrays;
var
I, II : Integer;
begin
// add H vars instead
If GetArrayLength(PlayerDic) = 0 Then Exit;
For I:=0 To High(PlayerDic)do
For II:=1 to High(PlayerDic[I].Row)do
Writeln('[' + IntToStr(i) + '] Row: ' + IntToStr(II) + ' | Triggers: ' + IntToStr(High(PlayerDic[I].Row[II].Trigger)) + ' | Responses: ' + IntToStr(High(PlayerDic[I].Row[II].Response)));
end;
{*******************************************************************************
Procedure DebugDictionary;
By: N1ke!
Description: Debugs the hole dictionary.
*******************************************************************************}
Procedure DebugDictionary;
var
I, II, III: Integer;
begin
// Add Highs please.
If GetArrayLength(PlayerDic) = 0 Then Exit;
For I:=0 To High(PlayerDic)do
For II:=1 to High(PlayerDic[I].Row)do
begin
Writeln('[' + IntToStr(i) + ']Row: ' + IntToStr(II));
For III:=0 to High(PlayerDic[I].Row[II].Trigger) - 1 do
Writeln('Trigger[' + IntToStr(III) + '] = ' + PlayerDic[I].Row[II].Trigger[III]);
For III:=0 to High(PlayerDic[I].Row[II].Response) - 1 do
Writeln('Response[' + IntToStr(IIII) + '] = ' + PlayerDic[I].Row[II].Response[IIII]);
end;
end;
{*******************************************************************************
Function ReplaceResponseSign(Text : String): string;
By: N1ke!
Description: Checks if players have been switched.
*******************************************************************************}
Function ReplaceResponseSign(Text : String): string;
var
TStrP: TStringArray;
I, H: integer;
begin
TStrP:= ['$attack', '$strength', '$defence', '$range', '$prayer',
'$magic', '$runecrafting', '$hitpoints', '$agility', '$herblore',
'$thieving', '$crafting', '$fletching', '$slayer', '$mining', '$smithing', '$fishing', '$cooking',
'$firemaking', '$woodcutting', '$farming', '$construction', '$hunter', '$summoning'];
H := High(TStrP);
Text := LowerCase(Text);
for I:= 0 to H do
begin
if Pos( LowerCase(TStrP[I]), text) > 0 then //
begin
Result := TStrP[I];
Delete(TStrP[I], Pos('$', TStrP[I]), 1);
If Players[CurrentPlayer].Level[i+1] = 0 then
Players[CurrentPlayer].Level[i+1] := GetSkillInfo(TStrP[I], False);
Result := Replace(Text, LowerCase(Result), IntToStr(Players[CurrentPlayer].Level[i+1]));
Exit;
end;
end;
end;
{*******************************************************************************
Function ChatText(Text: TStringArray): Boolean;
By: N1ke!
Description: Tries to find a match between a trigger array and the last
typed message. If the message is from the current player it will exit.
*******************************************************************************}
Function ChatText(Text: TStringArray; var Sresult: String): Boolean;
var
I, II: integer;
S, Name : string;
begin
LastChatter(Name);
if (not (GetLastChatText(S))) then Exit;
II := High(Text);
S := LowerCase(S);
for I := 0 to II do
begin
if Pos(LowerCase(Text[i]), S) = 1 then // Shouldnt this be <> 0
begin
SResult := Name + ': ' + Text[i];
Result := True;
Exit;
end;
end;
end;
{*******************************************************************************
Procedure DeleteIndex(Index: Integer; var Arr: TStringArray);
By: N1ke!
Description: Deletes a index in a TStringArray.
*******************************************************************************}
Procedure DeleteIndex(Index: Integer; var Arr: TStringArray);
var
i, h: integer;
Begin
H := High(Arr) - 1;
for i:= Index to H do
Swap(Arr[i], Arr[i+1]);
SetArrayLength(Arr, H + 1);
end;
{*******************************************************************************
procedure SetupSRLAutoResponder(ChanceResponse: Integer);
By: N1ke!
Description: Loads dictionary and sets up the responder.
*******************************************************************************}
procedure SetupAutoResponder(ChanceOfResponding: Integer; SaveQuestions: Boolean);
var
I, II, III, H, HH, HHH: Integer;
Begin
SetDicArrays;
SetResponseChance(ChanceOfResponding);
SQAA := SaveQuestions;
H := High(PlayerDic);
For I := 0 to H do
begin
HH := High(PlayerDic[i].Row);
For II := 1 to HH do
begin
HHH := High(PlayerDic[i].Row[II].Trigger);
For III := 0 to HHH do
PlayerDic[i].Row[II].Trigger[III] := ReadINI('Row' + IntToStr(II), 'Trigger' + IntToStr(III), AppPath + 'includes\SRL\Dictionary.ini');
HHH := High(PlayerDic[i].Row[II].Response);
For III := 0 to HHH do
PlayerDic[i].Row[II].Response[III] := ReadINI('Row' + IntToStr(II), 'Response' + IntToStr(III), AppPath + 'includes\SRL\Dictionary.ini');
end;
end;
RenewAllTriggers;
UseAutoResponder := True;
MarkTime(PlayerDic[CurrentPlayer].Row[i].UsedResponse);
end;
{*******************************************************************************
Function Respond: Boolean;
By: N1ke!
Description: Responds to triggers which is set in the Dictionary.ini file.
Also add small mistakes and deletes the response after.
*******************************************************************************}
Function Respond: Boolean;
var
I, N, H: Integer;
Msg, GBCM: String;
Begin
If Not UseAutoResponder Then Exit;
GBCM := GetBlackChatMessage;
If (Pos(Lowercase(Players[CurrentPlayer].Name) , Lowercase(GBCM)) <> 0) then Exit;
If GBCM = 'Welcome to RuneScape.' then Exit;
H := High(PlayerDic[CurrentPlayer].Row);
For I :=0 to H do
begin
If Not ChatText(PlayerDic[CurrentPlayer].Row[i].Trigger, Msg)then Continue;
If TimeFromMark(PlayerDic[CurrentPlayer].Row[i].UsedResponse) < 1000*30+Random(60)then Exit;
If GetArrayLength(PlayerDic[CurrentPlayer].Row[i].Response) = 0 then Exit;
If ChanceResponding < Random(100) then Exit;
N := RandomRange(0, High(PlayerDic[CurrentPlayer].Row[i].Response));
PlayerDic[CurrentPlayer].Row[i].Response[N] := ReplaceResponseSign(PlayerDic[CurrentPlayer].Row[i].Response[N]);
case Random(4) of
0..2: TypeSend(PlayerDic[CurrentPlayer].Row[i].Response[N]);
3: TypeSend(AddMistakes(PlayerDic[CurrentPlayer].Row[i].Response[N], 10+Random(20)));
end;
Writeln(Msg);
Writeln(Players[CurrentPlayer].Name + ': ' + PlayerDic[CurrentPlayer].Row[i].Response[N]);
MarkTime(PlayerDic[CurrentPlayer].Row[i].UsedResponse)
Result := True;
If SQAA then
begin
AddToSRLLog('Trigger: ' + Msg + ' | Response: ' + Players[CurrentPlayer].Name + ': ' + PlayerDic[CurrentPlayer].Row[i].Response[N]);
ResponseArrays[ResponsesMade] := TheTime + ' | Trigger: ' + Msg + ' | Response: ' + Players[CurrentPlayer].Name + ': ' + PlayerDic[CurrentPlayer].Row[i].Response[N];
end;
Inc(ResponsesMade);
DeleteIndex(N, PlayerDic[CurrentPlayer].Row[i].Response);
Exit;
end;
end;
Procedure SetupSRLAutoResponder; // To avoid errors.
begin
end;