Results 1 to 25 of 25

Thread: Laggy Procedure

  1. #1
    Join Date
    Jun 2007
    Location
    Kentucky, United States of America
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Laggy Procedure

    Alright, I tried to make my own procedure to kill chickens and works somewhat, but it way too laggy. Think someone can tell me who to cut down on it a bit? Any other hints or bits of advice would also be appreciated. Here's the procedure.

    SCAR Code:
    procedure KillChickens;

    var
      Tx, Ty : Integer;

    begin
      If (not(loggedin)) then LoginPlayer
      Tried:= 0
      FindRandoms;
      repeat
       if FindColorRightTol(Tx, Ty, ChickenColor1, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorRightTol(Tx, Ty, ChickenColor2, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorRightTol(Tx, Ty, ChickenColor3, MSX1, MSY1, MSX2, MSY2, 4) Then
          MMouse(Tx,Ty,3,3)
          Tried:= Tried + 1;
          if (Tried>Tries) then
                  begin
                    Writeln('Could not find a chicken')
                    LogOut;
                    NextPlayer(True);
                  end;
          Wait(100+random(100));
       until (IsUpTextMulti('Attack', 'tac', 'Chicken'))
          Mouse(Tx, Ty, 1, 1, True)
          FindRandoms;
          NoBan;
          Wait(1000+random(250));
          if (InFight) then
            begin
              OutFight;
              ChickensKilled:= ChickensKilled + 1;
              ReportVars[0] := ReportVars[0] + 1;
              ReportVars[2] := ReportVars[2] + 12;
            end;

    end;

  2. #2
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Do you absolutely have to use FindColorRightTol? Cause that's what's making it lag so bad. If it's not essential, just use FindColorTolerance. It's about ten times faster and doesn't lag at all for me.

  3. #3
    Join Date
    Jul 2006
    Location
    NY
    Posts
    371
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    And you might want to break out of that loop or even exit the procedure after logging in a different player.
    SCAR Code:
    begin
                    Writeln('Could not find a chicken')
                    //LogOut;    NextPlayer(False) does that for you.
                    NextPlayer(False); //False if you dont want to log current player in anymore.
                    Exit;
                  end;

  4. #4
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    And if FindColorRightTol is necessary, I made a much faster version of it.
    SCAR Code:
    function FindColorRightTol(var cx, cy: Integer; Color, x1, y1, x2, y2, Tolerance: Integer): Boolean;
    var
      Boxes: TBoxArray;
      I: Integer;
      tX1, tY1, tX2, tY2: Integer;
    begin
      SetLength(Boxes, x2 - x1);
      tX1:= x2 - 1;
      tY1:= y1;
      tX2:= x2;
      tY2:= y2;
      for I:= 0 to Length(Boxes) - 1 do
      begin
        tX1:= tX1 - 1;
        tX2:= tX2 - 1;
        Boxes[I]:= IntToBox(tX1, tY1, tX2, tY2);
      end;
      for I:= 0 to Length(Boxes) - 1 do
        if(FindColorTolerance(cx, cy, Color, Boxes[I].x1, Boxes[I].y1, Boxes[I].x2, Boxes[I].y2, Tolerance))then
        begin
          Result:= True;
          exit;
        end;
    end;

  5. #5
    Join Date
    Dec 2006
    Location
    utah
    Posts
    1,427
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    i doubt its much fast

    SCAR Code:
    function FindColorRightTol(var x, y : integer; Color, x1, y1, x2, y2, tol : Integer) : Boolean;
    var
      W, H, i, cx, cy : integer;
    begin
      W := Trunc(Abs(x2 - x1));
      H := Trunc(Abs(y2 - y1));
     for i := (W * H)- 1 downto 0 do
     begin
        cx := i mod W + x1;
        cy := i div W + y1;
        Result := FindColorTolerance(x, y, Color, cx, cy, cx - 1, cy - 1, Tol);
       if (Result) then Exit;
     end;
      Result := FindColorTolerance(x, y, Color, x1, y1, x1 + 1, y1 + 1, Tol);
    end;

  6. #6
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    You could use FindObjMulti to find your chickens instead:

    SCAR Code:
    procedure KillChickens;

    var
      Tx, Ty : Integer;

    begin
      If (not(loggedin)) then LoginPlayer
      Tried:= 0
      FindRandoms;
      repeat
        if FindObjMulti('hick', ChickenColor1, ChickenColor2, ChickenColor3, 4) then
        begin
          GetMousePos(Tx, Ty);
          MMouse(Tx, Ty, 0, 0);
          Tried:= Tried + 1;
          if (Tried>Tries) then
                  begin
                    Writeln('Could not find a chicken')
                    LogOut;
                    NextPlayer(True);
                  end;
          Wait(100+random(100));
        end;
      until (IsUpTextMulti('Attack', 'tac', 'Chicken'))
      Mouse(Tx, Ty, 1, 1, True)
      FindRandoms;
      NoBan;
      Wait(1000+random(250));
      if (InFight) then
      begin
        OutFight;
        ChickensKilled:= ChickensKilled + 1;
        ReportVars[0] := ReportVars[0] + 1;
        ReportVars[2] := ReportVars[2] + 12;
      end;
    end;

  7. #7
    Join Date
    Jun 2007
    Location
    Kentucky, United States of America
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I tried findobjmulti and it didn't work out so hot. The regular findcolortolerance works fine. . .I dunno why I even did it from the right. I think I've seen a procedure that looks too similar to this one before. Guess I tried to change it up.

  8. #8
    Join Date
    Jun 2007
    Location
    Kentucky, United States of America
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Sorry for double posting, but here is my new procedure. I have the 2nd set of the three findcolortolerances, so it could find either the brown or beige chickens. The first set is for the brown chickens and the second is for the beige. It's still a bit laggy, and it doesn't work as well as I had hoped. It will kill a few chickens, but then it'll go to the bags of grain or the fence and just hover there. Here's the updated procedure. Should I decrease the tolerance? Or just scrap the whole procedure and try something else?


    SCAR Code:
    procedure KillChickens;

    var
      Tx, Ty : Integer;

    begin
      If (not(loggedin)) then LoginPlayer
      Tried:= 0
      FindRandoms;
      repeat
       if FindColorTolerance(Tx, Ty, ChickenColor1, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorTolerance(Tx, Ty, ChickenColor2, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorTolerance(Tx, Ty, ChickenColor3, MSX1, MSY1, MSX2, MSY2, 4) or
          FindColorTolerance(Tx, Ty, ChickenColor4, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorTolerance(Tx, Ty, ChickenColor5, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorTolerance(Tx, Ty, ChickenColor6, MSX1, MSY1, MSX2, MSY2, 4) then
          MMouse(Tx,Ty,3,3)
          Tried:= Tried + 1;
          if (Tried>Tries) then
                  begin
                    Writeln('Could not find a chicken')
                    NextPlayer(False);
                  end;
          Wait(100+random(100));
       until (IsUpTextMulti('Attack', 'tac', 'Chicken'))
          Mouse(Tx, Ty, 1, 1, True)
          FindRandoms;
          NoBan;
          Wait(1000+random(250));
          if (InFight) then
            begin
              OutFight;
              ChickensKilled:= ChickensKilled + 1;
              ReportVars[0] := ReportVars[0] + 1;
              ReportVars[2] := ReportVars[2] + 12;
            end;

    end;

  9. #9
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    You should probably try something different. Maybe DTMs at different angles? Or you could always just redo the whole thing to make the color finding different.

  10. #10
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Just a thought... I'm not sure if it will work but you could change the FindColorTolerance to FindColorSpiralTolerance and then make the script set a random set of coords for Tx, and Ty every time its repeats. So then if it finds the colour but not 'Attack' in the top left then it will search again from a different coordinate.

  11. #11
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    That IS a very good suggestion, but he's concerned about lag for it. Maybe take his suggestion, get a list of chicken colors, and make it randomly choose one each time you call on the function/procedure?

  12. #12
    Join Date
    Jun 2007
    Location
    Kentucky, United States of America
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I very well might try that, Zephyr. I'm thinking of making a form so the users can just pick and put in their own colors that they pick. Then make it randomly choose one everytime the procedure or function is called.

    EDIT: Ok, I tried it, and it worked great for about 3 chickens Then my mouse went kinda crazy and just kept moving all around the screen. Off of the RS screen too. Anyone have any idea of what could've caused this? Never seen anything like it before.

  13. #13
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Could you post it?

  14. #14
    Join Date
    Jun 2007
    Location
    Kentucky, United States of America
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    The procedure or like a picture of it?

    Here's the procedure now. I didn't really change anything except FindColorTolerance to FindColorSpiralTolerance.

    SCAR Code:
    procedure KillChickens;

    var
      Tx, Ty : Integer;

    begin
      If (not(loggedin)) then LoginPlayer
      Tried:= 0
      FindRandoms;
      repeat
       if FindColorSpiralTolerance(Tx, Ty, ChickenColor1, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorSpiralTolerance(Tx, Ty, ChickenColor2, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorSpiralTolerance(Tx, Ty, ChickenColor3, MSX1, MSY1, MSX2, MSY2, 4) or
          FindColorSpiralTolerance(Tx, Ty, ChickenColor4, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorSpiralTolerance(Tx, Ty, ChickenColor5, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorSpiralTolerance(Tx, Ty, ChickenColor6, MSX1, MSY1, MSX2, MSY2, 4) then
          MMouse(Tx,Ty,3,3)
          Tried:= Tried + 1;
          if (Tried>Tries) then
                  begin
                    Writeln('Could not find a chicken')
                    NextPlayer(False);
                  end;
          Wait(100+random(100));
       until (IsUpTextMulti('Attack', 'tac', 'Chicken'))
          Mouse(Tx, Ty, 1, 1, True)
          FindRandoms;
          NoBan;
          Wait(1000+random(250));
          if (InFight) then
            begin
              OutFight;
              ChickensKilled:= ChickensKilled + 1;
              ReportVars[0] := ReportVars[0] + 1;
              ReportVars[2] := ReportVars[2] + 12;
            end;

    end;

  15. #15
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Try this
    SCAR Code:
    [procedure KillChickens;
    var
      Tx, Ty, I: Integer;
      TempResult: Boolean;
    begin
      If (not(loggedin)) then LoginPlayer
      Tx:= Random(MSX2);
      Ty:= Random(MSY2);
      Tried:= 0
      FindRandoms;
      repeat
        for I:= 1 to 6 do
          case I of
            1: if FindColorSpiralTolerance(Tx, Ty, ChickenColor1, MSX1, MSY1, MSX2, MSY2, 4)then
               begin
                 TempResult:= True;
                 break;
               end;
            2: if FindColorSpiralTolerance(Tx, Ty, ChickenColor2, MSX1, MSY1, MSX2, MSY2, 4)then
               begin
                 TempResult:= True;
                 break;
               end;
            3: if FindColorSpiralTolerance(Tx, Ty, ChickenColor3, MSX1, MSY1, MSX2, MSY2, 4)then
               begin
                 TempResult:= True;
                 break;
               end;
            4: if FindColorSpiralTolerance(Tx, Ty, ChickenColor4, MSX1, MSY1, MSX2, MSY2, 4)then
               begin
                 TempResult:= True;
                 break;
               end;
            5: if FindColorSpiralTolerance(Tx, Ty, ChickenColor5, MSX1, MSY1, MSX2, MSY2, 4)then
               begin
                 TempResult:= True;
                 break;
               end;
            6: if FindColorSpiralTolerance(Tx, Ty, ChickenColor6, MSX1, MSY1, MSX2, MSY2, 4)then
               begin
                 TempResult:= True;
                 break;
               end;
          end;
        if(TempResult)then
          MMouse(Tx,Ty,3,3)
        Tried:= Tried + 1;
        if (Tried>Tries) then
        begin
          Writeln('Could not find a chicken')
          NextPlayer(False);
        end;
        Wait(100+random(100));
      until (IsUpTextMulti('Attack', 'tac', 'Chicken'))
      if(not(Tried < Tries))then
        Mouse(Tx, Ty, 1, 1, True)
      FindRandoms;
      NoBan;
      Wait(1000+random(250));
      if (InFight) then
      begin
        OutFight;
        ChickensKilled:= ChickensKilled + 1;
        ReportVars[0] := ReportVars[0] + 1;
        ReportVars[2] := ReportVars[2] + 12;
      end;
    end;
    If it works, compare mine to yours and see the changes.

  16. #16
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    SCAR Code:
    if FindColorSpiralTolerance(Tx, Ty, ChickenColor1, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorSpiralTolerance(Tx, Ty, ChickenColor2, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorSpiralTolerance(Tx, Ty, ChickenColor3, MSX1, MSY1, MSX2, MSY2, 4) or
          FindColorSpiralTolerance(Tx, Ty, ChickenColor4, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorSpiralTolerance(Tx, Ty, ChickenColor5, MSX1, MSY1, MSX2, MSY2, 4) and
          FindColorSpiralTolerance(Tx, Ty, ChickenColor6, MSX1, MSY1, MSX2, MSY2, 4) then
    why are these all ands make less ands and more ors.

  17. #17
    Join Date
    Jun 2007
    Location
    Kentucky, United States of America
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nope. It didn't work. All it did was get stuck on the big bags of grain. Which it doesn't with the other procedure. . .I dunno, I'll think of something I guess. I'll work on the bones procedure until I can think of something.

    EDIT: @ Jhildy - It finds the chicken much more constistently this way. Uses three colors instead of one.

  18. #18
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    One of your colors is the color of grain then. I'll try again.
    SCAR Code:
    procedure KillChickens;
    var
      Tx, Ty, Ttx, Tty, I: Integer;
      TempResult: Boolean;
    begin
      If (not(loggedin)) then LoginPlayer
      Tx:= Random(MSX2);
      Ty:= Random(MSY2);
      Tried:= 0
      FindRandoms;
      repeat
        for I:= 1 to 6 do
          case I of
            1: if FindColorSpiralTolerance(Tx, Ty, ChickenColor1, MSX1, MSY1, MSX2, MSY2, 4)then
               begin
                 TempResult:= True;
                 Ttx:= Tx;
                 Tty:= Ty;
                 if(Random(5) = 1)then
                   break;
               end;
            2: if FindColorSpiralTolerance(Tx, Ty, ChickenColor2, MSX1, MSY1, MSX2, MSY2, 4)then
               begin
                 TempResult:= True;
                 Ttx:= Tx;
                 Tty:= Ty;
                 if(Random(5) = 1)then
                   break;
               end;
            3: if FindColorSpiralTolerance(Tx, Ty, ChickenColor3, MSX1, MSY1, MSX2, MSY2, 4)then
               begin
                 TempResult:= True;
                 Ttx:= Tx;
                 Tty:= Ty;
                 if(Random(5) = 1)then
                   break;
               end;
            4: if FindColorSpiralTolerance(Tx, Ty, ChickenColor4, MSX1, MSY1, MSX2, MSY2, 4)then
               begin
                 TempResult:= True;
                 Ttx:= Tx;
                 Tty:= Ty;
                 if(Random(5) = 1)then
                   break;
               end;
            5: if FindColorSpiralTolerance(Tx, Ty, ChickenColor5, MSX1, MSY1, MSX2, MSY2, 4)then
               begin
                 TempResult:= True;
                 Ttx:= Tx;
                 Tty:= Ty;
                 if(Random(5) = 1)then
                   break;
               end;
            6: if FindColorSpiralTolerance(Tx, Ty, ChickenColor6, MSX1, MSY1, MSX2, MSY2, 4)then
               begin
                 TempResult:= True;
                 Ttx:= Tx;
                 Tty:= Ty;
                 if(Random(5) = 1)then
                   break;
               end;
          end;
        if(TempResult)then
          MMouse(Ttx,Tty,3,3)
        Tried:= Tried + 1;
        if (Tried>Tries) then
        begin
          Writeln('Could not find a chicken')
          NextPlayer(False);
        end;
        Wait(100+random(100));
      until (IsUpTextMulti('Attack', 'tac', 'Chicken'))
      if(TempResult)then
        Mouse(Ttx, Tty, 1, 1, True)
      FindRandoms;
      NoBan;
      Wait(1000+random(250));
      if (InFight) then
      begin
        OutFight;
        ChickensKilled:= ChickensKilled + 1;
        ReportVars[0] := ReportVars[0] + 1;
        ReportVars[2] := ReportVars[2] + 12;
      end;
    end;
    Try that. I made it not always break.

  19. #19
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Lol all of this for some (seemingly) simple procedure. Are you FindObj doesn't work? Its designed to do basically what we are trying to do with the FindColorSpiralTolerances and finding objects from the middle out. I'll have a go with it and see if I can make it do what you want.

  20. #20
    Join Date
    Jun 2007
    Location
    Kentucky, United States of America
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Aha. . .I think it's actually SCAR 3.11 that was making the odd mouse error. It works just dandy with SCAR 3.10. Zephyr, I would like to work with you on a script sometime. Llamaman is supposed to be helping out on this one, but he really hasn't done anything so far. It's actually kinda aggravating me. . .

  21. #21
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Yea why not. Once I release my Rune Mysteries Runner I have 2 week (acutally 1.5 week now) to do nothing. I see you've been stuck on 39% for a while. LOL

  22. #22
    Join Date
    Jun 2007
    Location
    Kentucky, United States of America
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ha I'm actually farther than that as I've got what I want down in my head. I just need to fix the chicken procedure. And add the bone burying procedure, but I don't think that will be too extremely tough. Just wondering whether to use bitmaps to pick them up, or DTMs. Or just something like FindObj since I think that it might work on something like that.

  23. #23
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    You could try DTM's and bitmaps but since its on the main screen and people step all over then, it will be hard. FindObj sounds promising.

  24. #24
    Join Date
    Jun 2007
    Location
    NSW, Australia.
    Posts
    541
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You could also use FindObj3 - I use this alot in my scripts, seems it finds the object (in your case a chicken) that is the closest to the player, reducing walking. It works fine for me.

    -Pancakes.
    Quote Originally Posted by RAM View Post
    I sam sofa king wee todd did ! ~RAM
    My SRL Army Blog.


  25. #25
    Join Date
    Jun 2007
    Location
    Kentucky, United States of America
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yeah, I think I'm just gonna go with FindObj for the bones. The chicken thing seems to work decent for now, I'll improve it later.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. computer becoming laggy..
    By sherlockmeister in forum News and General
    Replies: 4
    Last Post: 06-12-2007, 07:06 PM
  2. Laggy Scripts
    By Suyeda in forum News and General
    Replies: 5
    Last Post: 10-30-2006, 01:38 AM

Posting Permissions

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