Results 1 to 2 of 2

Thread: Using arrays to selectively color search.(HELP! with main screen item finding)

  1. #1
    Join Date
    Oct 2006
    Posts
    412
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Using arrays to selectively color search.(HELP! with main screen item finding)

    For my program im having trouble finding bones on the ground. The FindMSColorTol keeps mistaking the chickens and daisy's for bones, and searching them for uptext. I though of an idea to use tpointarrays(but couldnt get it to work) so I tried using regular arrays. The idea was this:

    Find a color
    mouse over the color
    check the up text
    if it is not 'take'
    add the x,y to an array
    find another instance of the color
    if that color is less than 30 pixels away than the coordinates in the array
    search for a different instance.
    else
    check it for its up text
    if the up text is 'take'
    then click on it
    else
    add those x,y to the array.
    search for another instance of the color
    and so on.

    I got the following together, but it only works once. finds the color, adds it to the array, looks for another color, and gives up( but the program is still running)....wait a sec.... is this because of how Find MSColorTol works? what is happening here is that it is continually looking at the same spot(therefore triggering the function that the color is not more than 30 pixels away, so find another instance(but it just continues to find the same instance)...DAMMIT!! 2 hours of work wasted!!!

    Oh well, im not going to give up. If someone could show me how to find items on the ground(in an area where there are similar non item colors such as bones near chickens) it would be GREATLY appreciated and +rep.

    SCAR Code:
    program BoneCollectorAndBurier;
    {.include srl/srl.scar}
    var
    NormalBoneDTM,bone,NoBone,i:Integer;
    NoBoneCoordsX,NoBoneCoordsY:array of Integer;

    const
    BonesToBury=50;

    Procedure LoadDTMs;
    begin
    NormalBoneDTM := DTMFromString('78DA635CC9C4C02007C448E0FCF1E30CFF813' +
           '42310FF0702C6E5407951543510591809A43700E5A551D5182828' +
           'A0AA590394572060CE12A0BC2A0135F380F2B2F8D50000EC180C8' +
           'F');
    end;

    Procedure prepareClient;
    begin
    SetupSRL;
    Cleardebug;
    ActivateClient;
    LoadDTMs;
    MakeCompass('N');
    HighestAngle;
    //SetRun(true);
    NoBone:=0;
    end;

    Procedure NotABoneCoords(nxc,nyc:Integer);
    begin
    writeln('doing bone procedure');
    SetArrayLength(NoBoneCoordsX,NoBone+1)
    SetArrayLength(NoBoneCoordsY,NoBone+1)
    NoBoneCoordsX[NoBone]:=nxc
    NoBoneCoordsY[NoBone]:=nyc
    writeln(inttoStr(NoBoneCoordsX[NoBone]));
    writeln(inttoStr(NoBoneCoordsY[NoBone]));
    end;

    Function IsNotABone(nx,ny,nb:Integer):boolean;
    begin
    i:=0
    writeln('doing bone function');
    while i<nb do
         begin
         writeln('works');
              if ((nx+30<NoBoneCoordsX[i])or
                 (nx-30>NoBoneCoordsX[i]))and
                 ((ny+30<NoBoneCoordsY[i])or
                 (ny-30>NoBoneCoordsY[i])) then
              begin
                 Result:=false
                  writeln('returned false');
              end;
              i:=i+1
         end;
    end;

    Procedure FindBones;
    begin
    repeat
          repeat
          FindMSColorTol(x,y,11316663,5)
          if (not(IsNotABone(x,y,NoBone)))then
          begin
          MMouse(x,y,0,0)
          wait(10+random(10));
          end;
          if (not(isUpText('ake')))then
          begin
          NotABoneCoords(x,y);
          NoBone:=NoBone+1
          end;
          until(isUpText('ake'))
    Mouse(x, y, 2, 2, False);
    Wait(150 + Random(100));
    ChooseOption(x,y,'ones')
    flag;
    Wait(100+Random(150));
    until(InvFull)
    end;

    begin
    prepareClient;
    FindBones;
    end.

  2. #2
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    You need to make your color finding look in other places. Here's something similiar. It finds the yellow banker dots in draynor or port phasmatys bank when called like this findyellows(hx,hy,16,5,590,30,700,120); .
    hx,hy is where to store the answer
    16 is the number of possibilities
    5 is the width of boxes
    the rest is x1,y1,x2,y2 of the minimap

    I am showing you this because you could modifiy it for other things. It works by dividing the box(x1....) into smaller boxes (width wide) and looks for a color (hardcoded for yellow, youll have to change that) in each box, but only once in each box. So you only get 1 hit per box, and if you set the width right that means only 1 hit per daisy/bone/etc. This is similiar to the 30 thing. You can then check the possibilities with uptext.





    Code:
    type ybox = record
    x1,y1,x2,y2,cx,cy:integer;
    active:boolean;
    end;
    
    
    type tehpoint = record
    x,y :integer;
    active : boolean;
    end;
    
    type combo = record
    point1,point2,x1,y1,x2,y2,dist:integer;
    active:boolean;
    end;
    
    
    
    var hx,hy,gx,gy,bankfindtries:integer;
    findyellowdone,foundbooth:boolean;
    
    
    
    procedure findyellows (var fx, fy:integer; PointsToFind,width,basex,basey,endx,endy:integer);
    var
    box :array of ybox;
    ypoint : array of tehpoint;
    com:array [1..300] of combo;
    x,d,e,f,i,g,nob,fyx,fyy,currentpoint,row,prow,col,nor,noc:integer;
    
    begin
      noc:=(( (endx-basex) - (width mod (endx-basex)))/width)+1;
      nor:=(( (endy-basey) - (width mod (endy-basey)))/width)+1;
    
      nob:=nor*noc;
      setarraylength(box, ((nob)+2));
      repeat
        x:=x+1;
        if  ((x+noc) mod noc)>0 then
          col:=((x+noc) mod noc);
        if ((x+noc) mod noc) =0then
          col:=noc;
        prow:=0;
        repeat
          prow:=prow+1;
        until (  x<=(noc*prow));
        row:=prow;
        box[x].x1:=(basex+ ((col-1)*width) );
        box[x].x2:=(basex+(col*width));
        box[x].y1:=(basey+ ((row-1)*width) );
        box[x].y2:=(basey+(row*width));
        box[x].cx:=round((box[x].x2+box[x].x1)/2);
        box[x].cy:=round((box[x].y2+box[x].y1)/2);
        box[x].active:=true;
    
        {
        //draws the boxes on paint
        movemouse(box[x].x1,box[x].y1);
        holdmouse(box[x].x1,box[x].y1,true);
        movemouse(box[x].x2,box[x].y2);
        releasemouse(box[x].x2,box[x].y2,true);
         }
      until x>=nob;
    
      currentpoint:=1;
      d:=0;
      setarraylength(ypoint, pointstofind+1);
      repeat
        d:=d+1;
        if (box[d].active) then
        begin
          if findcolor(fyx,fyy,195836,box[d].x1,box[d].y1,box[d].x2,box[d].y2) then
          begin
            ypoint[currentpoint].x :=fyx;
            ypoint[currentpoint].y :=fyy;
            currentpoint:=currentpoint+1;
            box[d].active:=false;
          end;
        end;
      until ((  currentpoint= pointstofind)or (d=nob));
    {
      e:=0;
      repeat
        e:=e+1;
        writeln(inttostr(ypoint[e].x)+'  '+inttostr(ypoint[e].y));
        if not((ypoint[e].x = 0) and (ypoint[e].y = 0)) then ypoint[e].active:=true;
      until e=16;
    
      writeln('                      all points');}
    
      e:=0;
      repeat
        f:=f+1;
        g:=0;
        repeat
          g:=g+1;
          e:=e+1;
          //writeln(inttostr(f)+'  '+inttostr(g)+'  '+inttostr(e));
          com[e].point1:=f;
          com[e].point2:=g;
          com[e].x1:=ypoint[f].x;
          com[e].y1:=ypoint[f].y;
          com[e].x2:=ypoint[g].x;
          com[e].y2:=ypoint[g].y;
          if not((com[e].x1=0) or (com[e].y1=0) or (com[e].x2=0) or (com[e].y2=0)) then com[e].active:=true;
        until( (g=16) or (e=256));
      until ((f=16) or (e=256));
    
    /////////--------------------analysis------------------------------
      { port phasmatys/draynor banker configuration
    
      port phasmatys:
      x-random people outside bank
    
      x...x......x...x  - bankers
      pair 1     pair 2
    
      first eliminates dots more than 20 away (random people outside)
      then finds 2 dots close (6) together, (pair 1 or 2)
      then finds a dot more than 7 away (a banker in the other pair)
    
      the last step is so that 2 people outside walking close together
      won't be mistaken for a pair of bankers
    
      draynor is the same except that the one pair is a single and
      its vertical, but that doesn't matter
      }
    
      e:=0;
      repeat
        e:=e+1;
        com[e].dist:=Round(Sqrt(Sqr(com[e].x1 - com[e].x2) + Sqr(com[e].y1 - com[e].y2)))
        if ((com[e].dist=0) or (com[e].dist>20)) then com[e].active:=false;
        i:=0;
        repeat
          i:=i+1;
          if ((com[e].active) and (com[i].active))then
          begin
            if ((com[e].point1=com[i].point2)and (com[e].point2=com[i].point1)) then com[i].active:=false;
          end;
        until i=256;
        if com[e].dist=1 then com[e].active:=false;
        //if com[e].active then writeln(inttostr(com[e].point1)+'  '+inttostr(com[e].point2)+'  '+inttostr(com[e].dist));
      until e=256;
      e:=0;
      repeat
        e:=e+1;
        if com[e].active then
        begin
          if (com[e].dist <5 ) then
          begin
            i:=0;
            repeat
            i:=i+1;
            if ((com[i].point1=com[e].point1) or (com[i].point1=com[e].point2)  or (com[i].point2=com[e].point1) or (com[i].point2=com[e].point2))then
            begin
              if com[i].dist>6 then
              begin
                if (((com[e].x1=com[i].x1) and (com[e].y1=com[i].y1)) or ((com[e].x1=com[i].x2) and (com[e].y1=com[i].y2))) then
                begin
                  fx:=com[e].x1;
                  fy:=com[e].y1;
                  findyellowdone:=true;
                end;
                if (((com[e].x2=com[i].x1) and (com[e].y2=com[i].y1)) or ((com[e].x2=com[i].x2) and (com[e].y2=com[i].y2))) then
                begin
                  fx:=com[e].x2;
                  fy:=com[e].y2;
                  findyellowdone:=true;
                end;
              end;
            end;
            until i=256;
          end;
        end;
      until e=256;
    /////////--------------------analysis end--------------------------
    end;

    Or you could do findcolorskipboxtolerance, changing the box with the IsNotBone. Also you may want to experiment this: I'm not sure if finding all the possibles and then checking them all is better or if checking each one after it is found is better.

    I'm working on a feature in MouseHelper where the main script can find colors in boxes or whatever and send the possible points to the MouseHelper script and it will move the mouse over the screen getting near the points while the main script can check the uptext. When I finish this I'll show you how to add it in. Until then, your best best is to mouse over each place the color is found.

    The other option is to use DTMs or bitmaps that are vague enough to work all the time and unique enough to not give false positives. I can't help you there, maybe someone else will.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Finding Main Screen items
    By lVlaverick in forum OSR Help
    Replies: 5
    Last Post: 10-11-2008, 11:25 PM
  2. -Search for item, And right click? Help-
    By *Skiller Feibal* in forum OSR Help
    Replies: 9
    Last Post: 11-26-2007, 12:04 PM

Posting Permissions

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