Results 1 to 4 of 4

Thread: best way to approach this

  1. #1
    Join Date
    May 2007
    Location
    in the forest
    Posts
    190
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default best way to approach this

    im currently making a script that requires me to search for 2 different random strings from npc chat, it needs to search until it finds the string, then search another list till both are found in the right combination... Ive considered using cases or arrays but im just not sure on how I would start it. I need toi head to work so I was hoping I could get some help while Im out so I can get started when I get home.

    thanks guys
    At sea with the navy - not very active

  2. #2
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    You need to use an array for this

  3. #3
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    SCAR Code:
    type
      MyChat = record
      Chatter: TStringArray;
      Said: TStringArray;
      LastResponded: integer;
    end;
    var
      Trigger: Array of Array[0..1] of TStringArray; //questions, could make more triggers... if i
      Answers: Array of TStringArray;                //find i need them
      RMTalks: MyChat;


    procedure SetupRespond;
    var FishType:string;
    begin

      SetLength(RMTalks.Chatter, 8);
      SetLength(RMTalks.Said, 8);

      SetLength(Trigger, 5); //how many questions
      SetLength(Answers, Length(Trigger));
      //you can have as many trigger words and rows as you want
      //you can have as many answers as you want


      Trigger[0][0]:= ['fish', 'fishing', '><>', '<><'];     // trigger words 1
      Trigger[0][1]:= ['lvl', 'level', 'levl', 'lvel'];          // trigger words 2
    //Trigger[0][2]:= ['','','','','',''];       // trigger words 3
      Answers[0]:= [
                     'My Fishing Level is: '+IntToStr(Players[CurrentPlayer].Level[17]), //answer 1
                     'Fishing: '+IntToStr(Players[CurrentPlayer].Level[17]),                      //answer 2
                     IntToStr(Players[CurrentPlayer].Level[17])+' '+chr(62)+chr(60)+chr(62)+' lvl',                   //answer 3
                     'my '+chr(62)+chr(60)+chr(62)+' lvl is '+IntToStr(Players[CurrentPlayer].Level[17])           //answer 4
                   ]

      Trigger[1][0] := ['fish', '><>'];
      Trigger[1][1] := ['which', 'what'];

      case lowercase(Players[CurrentPlayer].Strings[0]) of
        'harpoon': FishType := 'tuna';
        'cage': FishType := 'lobby';
        'fly': FishType := 'trout';
        'rod': FishType := 'pike';
        'net': FishType := 'shrimp';
      end;

      Answers[1] := [
                      'I''m fishing '+FishType,
                      FishType,
                      +chr(62)+chr(60)+chr(62)+': '+FishType
                    ]

      Trigger[2][0]:= ['place', 'train'];
      Trigger[2][1]:= ['fishing', '><>', 'fish'];
      Answers[2] := [
                      'Try Training fishing at Draynor',
                      'Draynor', 'Edgy', 'Al-Kharid', 'Karamja',
                      'Try Training fishing at Edgeville',
                      'Try Training fishing at Al-Kharid, close to bank',
                      'Try Training fishing at lumbridge'
                    ]

      Trigger[3][0]:= ['hi','hey', 'hello', 'sup?'];     // trigger words 1
      Trigger[3][1]:= [''];          // trigger words 2
      Answers[3]:= ['hi','hey', 'hello', 'sup?', 'how do you do?']

    end;

    //from srl, modded ofr any line
    function GetChatTextLine(var chat: string; line:integer): Boolean;
    var
      x, y: Integer;
      textP: TPoint;
    begin
      if not LoggedIn then exit;
      textP := TextCoords(line);
      if findcolor(x, y, 16711680, textp.x, textp.y, textp.x + 200, textp.y + 14) then
      begin
        chat := LowerCase(Trim(GetTextAtEx(x - 3, textp.y - 2, 0, SmallChars, False,

          False, -1, 1, 16711680, 60, False, tr_allChars)));
        Result := True;
      end;
    end;

    //from srl, modded for any line
    function GetChatterLine(var name: string; line:integer): Boolean;
    var
      i: Integer;
      textP: TPoint;
    begin
      if not LoggedIn then exit;
      textP := TextCoords(line);
      name := LowerCase(Trim(GetTextAtEx(textP.x - 2, textP.y - 2, 0, SmallChars, False, False, 0, 1,
        0, 60, False, tr_allChars)))
      i := Pos(':', name)
      if (i <> 0) then
      begin
        Delete(name, i, i);
        Result := True;
      end;
    end;

    procedure RMRespond;
    var
      str: string;
      i, h, t, k, triggered:integer;
      TSA:TStringArray;
    begin
      if not LoggedIn then exit;
      if (TimeFromMark(RMTalks.LastResponded) < 60000+Random(30000)) then exit;


      SetLength(TSA, 8)
      str:='';
      TSA:=['', '', '', '', '', '', '', ''];
      RMTalks.said := ['', '', '', '', '', '', '', ''];
      triggered := 0;

      // Getting text on all the lines
      for i:= 7 DownTo 0 do
      begin
        GetChatterLine(RMTalks.Chatter[i], i+1);
        if Pos(Lowercase(Players[CurrentPlayer].Nick), Lowercase(RMTalks.Chatter[i])) > 0 then
          break;     //if we already answered, it means we already checked further up.
        GetChatTextLine(RMTalks.said[i], i+1);
        TSA[i] := RMTalks.said[i];
      end;

        for i:=High(TSA) DownTo 0 do  //all text lines
          for h:= 0 to High(Trigger) do  //questions
          begin
            triggered:= 0;
            for t:=0 to High(Trigger[h]) do  //How many triggers

              for k:=0 to High(Trigger[h][t]) do //specific trigger

                if Pos(Trigger[h][t][k], TSA[i]) > 0 then
                begin
                  Inc(triggered);
                  if triggered >= 2 then
                  begin

                    Inc(Responses);
                    str:=(Answers[h][Random(Length(Answers[h]))]);

                    TypeSend(AddMistakes(str, RandomRange(10, 30)));

                    RMDebug('Question: '+Trigger[h][0][0]+ ' ' + Trigger[h][t][k]);
                    RMDebug('Responding: ' + str);

                    str := '';
                    MarkTime(RMTalks.LastResponded);
                    triggered := 0;
                    SetupRespond;

                    exit;
                  end;  //end if
                  break;
                end;  //end if
                //end k loop
          end; //end h loop
        //end of i loop
    end;

    i used the same approach that you're mentioning for my autoresponder. Hope it helps

    ~RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  4. #4
    Join Date
    May 2007
    Location
    in the forest
    Posts
    190
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thnkas guys
    At sea with the navy - not very active

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
  •