Results 1 to 10 of 10

Thread: "Muddle" an array

  1. #1
    Join Date
    Jul 2007
    Location
    UK
    Posts
    307
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default "Muddle" an array

    I'm making a Chicken Finder that uses TPA's but I need help because when it Finds all the objects the script will mouse over a "object" (could be a chicken) and check for text but I want it to check objects random not just the nearest first.

    I came up with two solutions:
    1 - To make an array of Booleans, the same size of the TPointArray which stores if the objects have been checked yet and for randomly getting a Point I just use Random(<Blah Blah>); and it checks if the point has already been checked if so then it will try again until it actually gets one that isn't and once the whole array of Booleans are true then we break from the loop or whatever has to be done. But time is wasted calling Random(<Blah Blah>); and for all I know it could call same number 100000 times which is highly unlikely but...still.

    2 - To "pre-randomize" the calling of the array, but I have no idea, I've stopped here because I need someone to fill in the space
    but if that can happen then it means I don't need to use solution one and this one would be much faster.

    Anybody who wants to see the unfinished function:
    SCAR Code:
    function FindAndClickChicken: Boolean;
    var
      GetPoints, ChickenTPoint, Chickens: TPointArray;
      ObjectPoints: T2DPointArray;
      ObjectCords: TPoint;
      SpeedSwitch, FastLength: Integer;
    begin
      repeat
        SwitchSpeed := GetColorToleranceSpeed;
        if (SwitchSpeed <> 2) then
          ColorToleranceSpeed(2);
        SetColorSpeed2Modifiers(0.03, 0.14);
        if FindColorsTolerance(GetPoints, 990082, MSX1, MSY1, MSX2, MSY2, 11) then
        begin
          ObjectPoints := SplitTPA(GetPoints, 10);
          FastLength := High(ChickenPoints);
          SetColorSpeed2Modifiers(0.07, 0.94);
          for I := 0 to FastLength do
          begin
            try
              ObjectCords := MiddleTPA(ObjectPoints[I]);
            except
            begin
              Writeln('Warning: Could not find Middle point of TPA, runtime error avoided. Using first point.');
              ObjectCords := ObjectPoints[I][0];
            end;
            if FindColorsTolerance(ChickenTPoint, 4357017, ObjectCords.X - 5, ObjectCords.Y - 5, ObjectCords.X - 20, ObjectCords.Y - 20, 22) then
            begin
              try
                ObjectCords := MiddleTPA(ObjectPoints[I]);
              except
              begin
                Writeln('Warning: Could not find Middle point of TPA, runtime error avoided. Using first point.');
                ObjectCords := ChickenTPoint[0];
              end;
              SetArrayLength(Chickens, Length(Chickens) + 1);
              try
                Chickens[High(Chickens)] := ObjectCords;
              except
              begin
                Writeln('Warning: Could not assign ObjectCords to Chickens array, runtime error avoided.');
                Writeln('This is a weird error and a very serious one, please post this error with your progress report.');
                SetArrayLength(Chickens, Length(Chickens) - 1);
                ErrorTPointChickens := True;
              end;
            end;
          end;
          if (Length(Chickens) < 1) then
            Continue;
          FastLength := High(Chickens);
          for I := 0 to FastLength do
          begin

          end;
        end;
      until()
    end;
    begin
    end.
    Suggestions are welcome, but please keep in mind this code hasn't been tested and is a "rough sketch".
    Last edited by cathering_; 04-20-2009 at 12:27 PM.

  2. #2
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Hehe, your first solution you have I just tried. It works :0. You could try using that but as I don't really script for RuneScape I don't really use TPAs much. But I know there's a function that did this but really you should use the one function that groups near ones together so that it will find the points as a single chicken and only use one.

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

    Default

    From an autotalker to a TPA chicken killer. Not Bad!

    SCAR Code:
    FastLength := High(Chickens);
    for I := 0 to FastLength do
    begin
      Swap(Chickens[i], Chickens[Random(FastLength)]);
    end;

    that'll randomize them; might give a compiling error, if so just do
    r := Random(FastLenght);
    Swap(Chickens[i], Chickens[r]);

    you won't know just how random it'll be, but will be random enough.

    nice to have you back
    ~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
    Jul 2007
    Location
    UK
    Posts
    307
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by Da 0wner View Post
    Hehe, your first solution you have I just tried. It works :0. You could try using that but as I don't really script for RuneScape I don't really use TPAs much. But I know there's a function that did this but really you should use the one function that groups near ones together so that it will find the points as a single chicken and only use one.
    The ChickenFinder basically does this
    1. Searches for the red
    2. Searches for the brown in the Vicinity of the red
    3. It now is a 70% chance that the point is a chicken
    4. MovesMouse over the "object" to check if it is really a chicken using IsTextUp;

    It only should search and click on one, I need the "random" thing to look for a chicken that's not the nearest to the top-left of the screen to make it less bot like.

    Sorry if I misunderstood if I did then please explain, in more detail on what you mean.

    Quote Originally Posted by Rasta Magician View Post
    From an autotalker to a TPA chicken killer. Not Bad!

    SCAR Code:
    FastLength := High(Chickens);
    for I := 0 to FastLength do
    begin
      Swap(Chickens[i], Chickens[Random(FastLength)]);
    end;

    that'll randomize them; might give a compiling error, if so just do
    r := Random(FastLenght);
    Swap(Chickens[i], Chickens[r]);

    you won't know just how random it'll be, but will be random enough.

    nice to have you back
    ~RM
    I'll try to study this more.
    Oh, are you saying you could actually swap the values inside the arrays and then put them in another one?
    EDIT: I think I know what you mean, that it will just swap all of the TPoints around, the actual values then blah blah, and yeah I think it will be random enough too, thanks.

    EDIT: Another question Rasta Magician if it tries to swap lets say Chickens[1] with Chickens[1] will this create an error? No?
    also, is it not Length()?
    Last edited by cathering_; 04-20-2009 at 01:43 PM.

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

    Default

    i think you might have been looking for SortTpaFrom(MSCX, MSCY); - that'll search the closest chickens first.

    about the error, i'm not sure.

    and no, it's High(), if it you used length itwould reach a time where it'd look for index 10 when the highest index is 9 - error;


    ~RM

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

  6. #6
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    could you do like (going off of what RM said)

    SCAR Code:
    x := Chickens[i];
    y := Chickens[r];
    //other stuff
    if(x <> y)then
      Swap(x, y);

    that should make it so it won't swap the same ones

    RM, he wants to NOT get the closest chickens.. I thought he did too.. haha :]

  7. #7
    Join Date
    Jul 2007
    Location
    UK
    Posts
    307
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by Rasta Magician View Post
    i think you might have been looking for SortTpaFrom(MSCX, MSCY); - that'll search the closest chickens first.

    about the error, i'm not sure.

    and no, it's High(), if it you used length itwould reach a time where it'd look for index 10 when the highest index is 9 - error;


    ~RM
    I don't want to find nearest chicken because I think it's very botish (being exact all the time).
    Read this:
    function Random(Range: Integer): Integer;
    Returns random 0 <= number < Range. Random(5) will return any of values 0, 1, 2, 3, 4. Random(5) + 1 will return values 1..5.


    Quote Originally Posted by 99_ View Post
    could you do like (going off of what RM said)

    SCAR Code:
    x := Chickens[i];
    y := Chickens[r];
    //other stuff
    if(x <> y)then
      Swap(x, y);

    that should make it so it won't swap the same ones

    RM, he wants to NOT get the closest chickens.. I thought he did too.. haha :]
    I'm confused why are you using x, y? or do you simply mean compare points?
    to be honest, I don't think it will return any error because it's simply replacing something with the same value but, thanks.

  8. #8
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    x and y because I couldn't think of something..

    or actually you don't need to do that.. the main point was if then..

    if it gives you an error for swapping the same thing then add the if(Chickens[i] <> Chickens[r])then Swap(Chickens[i], Chickens[r]);

  9. #9
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    procedure Randomize(var TPA : TPointArray);
    var
      i : integer;
    begin
      for i := 0 to high(TPA) do
        Swap(TPA[i], TPA[random(high(TPA))]);
    end;

    Lol, it works.

  10. #10
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    SCAR Code:
    procedure Randomize(var TPA : TPointArray);
    var
      i : integer;
    begin
      for i := 0 to high(TPA) do
        Swap(TPA[i], TPA[random(high(TPA))]);
    end;
    You'll need Random(Length(TPA)) instead of High there. This is how I would do it:
    SCAR Code:
    procedure Randomize(var TPA : TPointArray);
    var
      i : integer;
    begin
      for i := 0 to high(TPA) do
        Swap(TPA[Random(Length(TPA))], TPA[Random(Length(TPA))]);
    end;

    Also, cathering_, you don't need that many try excepts.

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
  •