Results 1 to 5 of 5

Thread: ChatCheck

  1. #1
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

    Default ChatCheck

    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:
    ChatCheck;

    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;
    Last edited by Shatterhand; 07-02-2013 at 06:44 PM. Reason: updated, added TradeChecks

  2. #2
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    This is good stuff bud, I'm going to use it. Thanks Shatterhand!

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  3. #3
    Join Date
    Sep 2008
    Posts
    754
    Mentioned
    8 Post(s)
    Quoted
    275 Post(s)

    Default

    very nice, diffidently comes in handy

  4. #4
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

  5. #5
    Join Date
    Apr 2015
    Posts
    20
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Love it, thanks =)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •