Town
2007-09-02 18:04:32
Repost because Fawki deleted the Snippets section 'accidentally'.
Records all usernames of people who have talked in the chatbox in an array.
Records the name of the person talking in a single line as a string.
If it finds chat by "Name" then it records the most recent line he said as "Chat".
Small script:
Makes a separate record of chat for each player who talks. If it recognizes the chat that a player says then it replys with chat coorsponding with what that player said without saying the same thing multiple times in a row.
function AllChatter: Array of String;
var
i, p: Integer;
textP: TPoint;
Name: String;
begin
SetArrayLength(Result, 8);
for p := 0 to 7 do
begin
TextP := TextCoords(p + 1);
Name := LowerCase(Trim(GetTextAtEx(textP.x - 2, textP.y - 2, 0, SmallChars, False, False, 0, 3,
0, 60, False, tr_allChars)))
i := Pos(':', name)
if (i <> 0) then
begin
Delete(name, i, i);
Result[p] := Name;
end;
end;
end;Records all usernames of people who have talked in the chatbox in an array.
function GetLineChatter(LineNum: Integer): String;
var
i: Integer;
textP: TPoint;
Name: String;
begin
TextP := TextCoords(LineNum + 1);
name := LowerCase(Trim(GetTextAtEx(textP.x - 2, textP.y - 2, 0, SmallChars, False, False, 0, 3,
0, 60, False, tr_allChars)))
i := Pos(':', name)
if (i <> 0) then
begin
Delete(name, i, i);
Result := Name;
end;
end;Records the name of the person talking in a single line as a string.
function GetLastChatMessageBy(Name: String; var Chat: String): Boolean;
var
i, x, y: Integer;
TextP: TPoint;
Names: Array of String;
begin
Names := AllChatter;
for i := 0 to 7 do
begin
if (Names[i] = Name) then
begin
Result := True;
textP := TextCoords(i);
if (IsTextInAreaEx(textP.x, textP.y, textP.x + 100, textP.y + 14,
x, y, ':', 0, smallchars, False, True, 0, 0, 0)) then
Chat := LowerCase(Trim(GetTextAtEx(x + 6, y, 0, SmallChars, False,
False, 0, 2, 16711680, 60, False, tr_allChars)));
end;
end;
end;If it finds chat by "Name" then it records the most recent line he said as "Chat".
Small script:
program New;
type
TTalker = Record
Name: String;
LastChat: String;
UsedResp: Array of String;
end;
var
Convo: Array of TTalker;
KeyWords: Array[0..10] of String;
Function TextCoords(textn: Integer): TPoint;
Begin
textn := textn - 1;
Result.X := 12;
Result.Y := 347 + (14 * textn);
End;
procedure DeclareWords;
begin
KeyWords[1] := 'noob';
KeyWords[2] := 'noob';
KeyWords[3] := 'noob';
KeyWords[4] := 'noob';
KeyWords[5] := 'noob';
KeyWords[6] := 'noob';
KeyWords[7] := 'noob';
KeyWords[8] := 'noob';
KeyWords[9] := 'noob';
KeyWords[10] := 'noob';
end;
function AllChatter: Array of String;
var
i, p: Integer;
textP: TPoint;
Name: String;
begin
SetArrayLength(Result, 8);
for p := 0 to 7 do
begin
TextP := TextCoords(p + 1);
Name := LowerCase(Trim(GetTextAtEx(textP.x - 2, textP.y - 2, 0, SmallChars, False, False, 0, 3,
0, 60, False, tr_allChars)))
i := Pos(':', name)
if (i <> 0) then
begin
Delete(name, i, i);
Result[p] := Name;
end;
end;
end;
function GetLineChatter(LineNum: Integer): String;
var
i: Integer;
textP: TPoint;
Name: String;
begin
TextP := TextCoords(LineNum + 1);
name := LowerCase(Trim(GetTextAtEx(textP.x - 2, textP.y - 2, 0, SmallChars, False, False, 0, 3,
0, 60, False, tr_allChars)))
i := Pos(':', name)
if (i <> 0) then
begin
Delete(name, i, i);
Result := Name;
end;
end;
function GetLastChatMessageBy(Name: String; var Chat: String): Boolean;
var
i, x, y: Integer;
TextP: TPoint;
Names: Array of String;
begin
Names := AllChatter;
for i := 0 to 7 do
begin
if (Names[i] = Name) then
begin
Result := True;
textP := TextCoords(i);
if (IsTextInAreaEx(textP.x, textP.y, textP.x + 100, textP.y + 14,
x, y, ':', 0, smallchars, False, True, 0, 0, 0)) then
Chat := LowerCase(Trim(GetTextAtEx(x + 6, y, 0, SmallChars, False,
False, 0, 2, 16711680, 60, False, tr_allChars)));
end;
end;
end;
function NarrowNames(CurrentNum: Integer): Integer;
var
Chat: String;
begin
Result := 0;
for CurrentNum := CurrentNum to GetArrayLength(Convo) - 1 do
begin
if (GetLastChatMessageBy(Convo[CurrentNum].Name, Chat)) then
begin
Result := CurrentNum;
Exit;
end;
end;
end;
function FindCurrentConvo(var Which: Array of Integer): Boolean;
var
z, q, p: Integer;
Chat: String;
Names: Array of String;
begin
Names := AllChatter;
if (GetArrayLength(Names) = 0) then Exit;
for z := 0 to 7 do
begin
for p := 0 to GetArrayLength(Convo) - 1 do
if (Names[z] = Convo[p].Name) then Break;
if (z = 0) and (p = GetArrayLength(Convo) - 1) then Exit;
end;
Result := True;
for p := 0 to GetArrayLength(Convo) - 1 do
begin
if (not (NarrowNames(p) = 0)) then p := NarrowNames(p);
GetLastChatMessageBy(Convo[p].Name, Chat);
if (not (Chat = Convo[p].LastChat)) then
begin
SetArrayLength(Which, GetArrayLength(Which) + 1);
Which[q] := p;
q := q + 1;
end;
end;
end;
function RecognizeChat(Chat: String): Integer;
var
i: Integer;
begin
for i := 0 to 10 do
if (Pos(Lowercase(Chat), Lowercase(KeyWords[i])) <> 0) then
begin
Result := i;
Exit;
end else Result := -1;
end;
function GetResponce: String;
begin
case RecognizeChat of
0: Result := 'kay';
end;
end;
function StartConvo: Boolean;
var
Names: Array of String;
Chat: String;
z, i: Integer;
begin
Names := AllChatter;
for z := 7 downto 0 do
for i := 7 downto 0 do
if (Names[z] = Names[i]) and (not (i = z)) then Names[i] := '';
for z := 7 downto 0 do
begin
if (not (Names[z] = '')) then
begin
GetLastChatMessageBy(Names[z], Chat);
// WriteLN(Names[z] + ' ' + Chat);
Result := True;
SetArrayLength(Convo, GetArrayLength(Convo) + 1);
Convo[GetArrayLength(Convo) - 1].Name := GetLineChatter(z);
end;
end;
end;
procedure Reply;
var
Which: Array of Integer;
Chat, f: String;
i, OldResp: Integer;
begin
StartConvo;
if (FindCurrentConvo(Which)) then
begin
for i := 0 to GetArrayLength(Which) do
begin
GetLastChatMessageBy(Convo[i].Name, Chat);
repeat
f := GetResponce;
if (GetArrayLength(Convo[i].UsedResp) < 2) then
begin
if (not (GetArrayLength(Convo[i].UsedResp) = 0)) then
if (not (f = Convo[i].UsedResp[GetArrayLength(Convo[i].UsedResp) - 1])) then Break;
end else
begin
for OldResp := GetArrayLength(Convo[i].UsedResp) downto GetArrayLength(Convo[i].UsedResp) - 2 do
if (not (f = Convo[i].UsedResp[OldResp])) then Break;
end;
until (false);
// SendKeys(f);
SetArrayLength(Convo[i].UsedResp, GetArrayLength(Convo[i].UsedResp) + 1);
Convo[i].UsedResp[GetArrayLength(Convo[i].UsedResp)] := f;
end;
end;
end;
begin
DeclareWords;
SetArrayLength(Convo, 1);
Reply;
end.Makes a separate record of chat for each player who talks. If it recognizes the chat that a player says then it replys with chat coorsponding with what that player said without saying the same thing multiple times in a row.