Here is a function for checking public/private/trade messages.
It reads the chatbox and filters duplicates (stores them in a "list"). Plays sound file on new message.
For private messages you have to turn off that chat settings to put it into the chat box.
Note that OCR isnt 100% accurate, the goal is to detect incoming message, not to get the exact text.
Usage: call it in bigger loops.
Simba Code:
const
PublicCheck = True;
PrivateCheck = True;
NameCheck = False; //filters public chat messages, using Players[CurrentPlayer].Nick
TradeCheck = True;
var
PublicTexts : Array[1..8] of String;
PrivateTexts : Array[1..8] of String;
TradeTexts : Array[1..2] of String;
procedure ChatCheck;
var
TempTexts : Array[1..8] of String;
text, name : String;
i,j : Integer;
bool : Boolean;
begin
for i:=1 to 8 do
begin
if PublicCheck then
begin
text := GetChatBoxText(i,ClBlue);
if not (text = '') then
begin
if NameCheck then
begin
if (Pos(Players[CurrentPlayer].Nick, text) > 0) then
begin
name := GetChatBoxText(i,ClBlack);
if (not (Pos('[', name) > 0)) and (not (Pos(']', name) > 0)) then
begin
name := Replace(name,'.','');
name := name + ':';
bool := False;
for j:=1 to 8 do
if (text = PublicTexts[j]) then
bool := True;
if (bool = False) then
begin
Writeln('Chat: ' + name + ' ' + text);
PlaySound('C:\Simba\sound_alert.wav');
for j:=Low(PublicTexts) to High(PublicTexts) do
TempTexts[j] := PublicTexts[j];
for j:=Low(PublicTexts)+1 to High(PublicTexts) do
PublicTexts[j-1] := TempTexts[j];
PublicTexts[High(PublicTexts)] := text;
end;
end;
end;
end else
begin
name := GetChatBoxText(i,ClBlack);
if (not (Pos('[', name) > 0)) and (not (Pos(']', name) > 0)) then
begin
name := Replace(name,'.','');
name := name + ':';
bool := False;
for j:=1 to 8 do
if (text = PublicTexts[j]) then
bool := True;
if (bool = False) then
begin
Writeln('Chat: ' + name + ' ' + text);
PlaySound('C:\Simba\sound_alert.wav');
for j:=Low(PublicTexts) to High(PublicTexts) do
TempTexts[j] := PublicTexts[j];
for j:=Low(PublicTexts)+1 to High(PublicTexts) do
PublicTexts[j-1] := TempTexts[j];
PublicTexts[High(PublicTexts)] := text;
end;
end;
end;
end;
end;
if PrivateCheck then
begin
name := GetChatBoxText(i,ClBlack);
if not (name = '') then
if (Pos('From',name) > 0) then
begin
name := Replace(name,'From','');
name := Replace(name,'.','');
name := name + ':';
text := GetChatBoxText(i,128);
if not (text = '') then
begin
bool := False;
for j:=Low(PrivateTexts) to High(PrivateTexts) do
if (text = PrivateTexts[j]) then
bool := True;
if (bool = False) then
begin
Writeln('Private:' + name + ' ' + text);
PlaySound('C:\Simba\sound_alert.wav');
for j:=Low(PrivateTexts) to High(PrivateTexts) do
TempTexts[j] := PrivateTexts[j];
for j:=Low(PrivateTexts)+1 to High(PrivateTexts) do
PrivateTexts[j-1] := TempTexts[j];
PrivateTexts[High(PrivateTexts)] := text;
end;
end;
end;
end;
if TradeCheck then
begin
text := GetChatBoxText(i,clPurple);
if not (text = '') then
begin
bool := False;
for j:=Low(TradeTexts) to High(TradeTexts) do
if (text = TradeTexts[j]) then
bool := True;
if (bool = False) then
begin
Writeln('Trade: ' + text);
PlaySound('C:\Simba\sound_alert.wav');
for j:=Low(TradeTexts) to High(TradeTexts) do
TempTexts[j] := TradeTexts[j];
for j:=Low(TradeTexts)+1 to High(TradeTexts) do
TradeTexts[j-1] := TempTexts[j];
TradeTexts[High(TradeTexts)] := text;
end;
end;
end;
end;
end;