Results 1 to 22 of 22

Thread: Check Movement- A better version of flag

  1. #1
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Check Movement- A better version of flag

    CheckMovement
    You know how when you click on the other side of a fence, the character walks around it? Most of the time, this means the flag will not be visible! Also, sometimes you can be stuck behind something, but the flag may still be there. This function will check if your character is moving without using the flag.
    UPDATE: This function should now work with SMART

    WaitUntilStop
    Uses CheckMovement to wait until you character stops.

    The Script
    (Last two are the ones that would be used by others. The first two are used in CheckMovement)
    SCAR Code:
    program New;
    {.include SRL/SRL.scar}

    function ColorCheck(Color: Integer; Smart: Boolean): Boolean;
    var
      Dots, W, H, x, y : Integer;
    begin
      Dots := BitmapFromString(17, 15, 'beNpjYPgPAwxEA2pp+W9' +
           'm9o+HB1nkHxjgNASoXkHhDxvbS1T1QPDmzRusWoDmA9V/ZGA4h6oF' +
           'qP7SpUs47GG8ycCwB8yAizx69Ojo0aNIIlh0Ycgy4lVPMmDn5mOgG' +
           'fj3T/jfPz6S1P/5w/T1K8Pdu8RqAaoHordvGc6cId4eRqD5YPUkhS' +
           'RxIQ8AaQdf5g==');
      SetTargetBitmap(Dots);
      GetBitmapSize(Dots, W, H);
      if(FindColorTolerance(x, y, Color, 0, 0, W, H, 10)or(Color=65536))then Result:=False
      else Result:=True;
      FreeBitmap(Dots);
      if(Smart=True)then SetTargetDC(SmartGetDC)
      else ResetDC;
    end;

    function FindGoodPoint(x1, y1, x2, y2: Integer; Smart: Boolean; var Color: Integer):TPoint;  //finds good coords, duh!
    var
      y, x: Integer;
    begin
      y:=y1-1;
      repeat
      begin
        y:=y+1;
        x:=x1;
        repeat
        begin
          x:=x+1;
          Result.x:=x;
          Result.y:=y;
          Color:=GetColor(x, y);
        end;
        until(ColorCheck(GetColor(x, y), Smart)or(x=x2+1));
      end;
      until((ColorCheck(GetColor(x, y), Smart))or((y=y2)and(x=x2+1)));
      if((y=y2)and(x=x2+1))then
      begin
        Result.x:=-1;
        Result.y:=-1;
      end;
    end;
    {*******************************************************************************
    function CheckMovement(Smart: Boolean): Integer;
    By: Macrosoft
    Description: Set whether you are useing SMART or not.
                 Returns 0 if an error occured.
                 Returns 1 if not moving.
                 Returns 2 if moving.
    *******************************************************************************}

    function CheckMovement(Smart: Boolean): Integer;
    var
      RPoint: Tpoint;
      RColor, i, Strikes: Integer;
      NColor: Integer;
    begin
      i:=0;
      RPoint:=FindGoodPoint(570, 33, 683, 135, Smart, RColor);
      if(RPoint.x=-1)then
      begin
        WriteLn('Error: Could not find referance point');
        Result:=0;
        Exit;
      end;
      Strikes:=0;
      repeat
      begin
        Wait(500);
        NColor:=GetColor(RPoint.x, RPoint.y);
        if(ColorCheck(NColor, Smart))and(not(NColor= RColor))then //if color changes
        begin
          i:=i+1;
          Strikes:=0;
          RColor:=NColor;
        end else
        begin
          i:=0;
          Strikes:=Strikes+1;
        end;
      end;
      until(i=3) or (Strikes=3);
      if(i=3)then
      begin
        Result:=2;
        WriteLn('We are moving!');
      end else
      begin
        Result:=1;
        WriteLn('We are not moving!');
      end;
    end;

    {*******************************************************************************
    function WaitUntilStop(Smart: Boolean): Integer;
    By: Macrosoft
    Description: Waits until the character stops moving.
    Set whether you are useing SMART or not.
    Returns 0 if and error occured.
    Returns 1 if you are caught on something and the flag
      remains while you are still
    Returns 2 if stopped.
    *******************************************************************************}


    function WaitUntilStop(Smart: Boolean): Integer;
    var
     i, Strikes: Integer;
    begin
      Strikes:=0;
      i:=0;
      repeat
      begin
        i:=CheckMovement(Smart);
        if(i=0)then Strikes:=Strikes+1 else Strikes:=0;
      end;
      until(i=1) or (Strikes=3);
      if(Strikes=3)then
      begin
        Writeln('Some error has occured');
        Result:=0;
        Exit;
      end;
      if(FlagPresent)then
      begin
        Writeln('You are caught on something!');
        Result:=1;
        Exit;
      end;
      Result:=2;
    end;

    begin
      SetupSRL;
      CheckMovement(False);
    end.

    Your move N1Ke, I told ya so (Were having a little Teacher Student brawl)

  2. #2
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Delete the members section one, or close it and make a link to this one

    Nava2
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

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

    Default

    Quote Originally Posted by Nava2 View Post
    Delete the members section one, or close it and make a link to this one

    Nava2
    Who are you to judge?
    Its Macro's Thread Mate.

  4. #4
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    No its fine. He was just giving advice. I had posted in both sections because I thought that the srl member section was for functions that should go to srl, but now I have found the right section for that.

  5. #5
    Join Date
    Mar 2008
    Posts
    1,492
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Dude this is godly! couldn't you use it for things like fishing?

  6. #6
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Looks great, but does it have any impact on speed?
    Interested in C# and Electrical Engineering? This might interest you.

  7. #7
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    well, not on my computer. It may cause I little lag on really ancient computers. If you think about it, it doesn't do anything too complicated that would cause a lag. Thanks for the feedback.

  8. #8
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by NaumanAkhlaQ View Post
    Who are you to judge?
    Its Macro's Thread Mate.
    He asked for it .

    On topic;

    I think you have some competition; some others are making some better functions than FlagPresent as well.

    Nava2
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  9. #9
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Did I inspire them? lol

    Ill just have to see what they do, and then improve this (Or think of an argument why mine is better).

  10. #10
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    I dunno theirs is damn impressive

    Nava2
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  11. #11
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Do you have a link?

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

    Default

    He's talking about me
    I didn't even know this existed. I just got bored today and decided to make one. I don't want to hijack this thread, but I'll edit this post with the link if you want me to.

  13. #13
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    If anyone sees your link, they are scrolling down and have obviously already read the first post. Go ahead and post the link. Maybe we could combine the ideas to make a master function .

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

    Default

    Too lazy to make a link to it... here it is:
    SCAR Code:
    program New;
    const
      MMX1 = 550;
      MMX2 = 703;
      MMY1 = 8;
      MMY2 = 161;
      MMCX = 627;
      MMCY = 85;
     
    function IsMoving: Boolean;
    var
      BMP, BMP2, I, x, y, Handle: Integer;
      ReplaceCols: TIntegerArray;
      P: TPointArray;
    begin
      Handle:= GetClientWindowHandle;
      ReplaceCols:= [65536, 16711422, 12961221, 14869218, 16777215, 15527148, 195836, 56797, 60909, 52428,
                     13816530, 982782, 1310462, 62965, 2105598, 395004, 789758, 3553023, 217, 188, 241,
                     206, 233, 64768, 58880, 51456, 49152, 44800, 61440, 16215571, 9716750, 13129742];
      BMP:= BitmapFromString(100, 100, '');
      BMP2:= BitmapFromString(100, 100, '');
      SafeCopyCanvas(GetClientCanvas, GetBitmapCanvas(BMP), MMCX - 50, MMCY - 50, MMCX + 50, MMCY + 50, 0, 0, 100, 100);
      for I:= 0 to High(ReplaceCols) do
        FastReplaceColor(BMP, ReplaceCols[I], 0);
      wait(250);
      SafeCopyCanvas(GetClientCanvas, GetBitmapCanvas(BMP2), MMCX - 50, MMCY - 50, MMCX + 50, MMCY + 50, 0, 0, 100, 100);
      SetTargetBitmap(BMP2);
      for I:= 0 to High(ReplaceCols) do
      begin
        FindColorsTolerance(P, ReplaceCols[I], 0, 0, 99, 99, 0);
        for x:= 0 to High(P) do
          FastSetPixel(BMP2, P[x].x, P[x].y, FastGetPixel(BMP, P[x].x, P[x].y));
      end;
      Result:= not FindBitmapIn(BMP, x, y, 0, 0, 100, 100);
      SetClientWindowHandle(Handle);
      FreeBitmap(BMP);
      FreeBitmap(BMP2);
    end;

    procedure WaitWhileMoving;
    begin
      while IsMoving do ;
    end;

    begin
    //  writeln(booltostr(IsMoving));
      WaitWhileMoving;
    end.

  15. #15
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    well, you set target bitmap, but you never resetdc, so im pretty sure that will screw up the script. Im not sure which way is faster. Im too lazy to try and figure out what it does, can you explain?

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

    Default

    I do reset it.
    SCAR Code:
    SetClientWindowHandle(Handle);

  17. #17
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    so whats the difference between that and resetdc?

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

    Default

    Just the fact that I had no clue that ResetDC existed, so I did it old school.
    I just got the handle of the client before doing SetTargetBitmap, then set the handle back to the handle I had previously gotten.

  19. #19
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    when you use settargetbitmap, all the color searching functions are performed on the bitmap. Resetdc undoes this so all the color searching functions are performed on the client. I also have SetTargetDC(SmartGetDC) for those who use smart.

    Can you explain what your function does, im too lazy to translate it into english.

    Mine finds a point that is not the color of any dot (because it will move) and then waits a bit and checks those same coords. If the color is the same within a tol, then you are not moving. If it is different, but not the color of a dot, then you are moving. I also use my "strikes" failsafe just in case your computer lags.

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

    Default

    Mine gets a bitmap of part of the center of the minimap and edits all of the colors of dots to 0, so that it will not look for those colors when finding the bitmap later on. It then waits 250 MS to give time for the player to move, and gets that same part of the minimap again. To make sure that minimap dots don't affect it, it makes all the points that the dots are on the color of the original bitmap (so that the colors match no matter what). If it finds the original bitmap in the second one, it returns false. Else true. Simple, but effective.

  21. #21
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    good idea

    I think im going to edit mine so that the user can input the amount of points used. Then Ill shorten my strike failsafe a bit and the whole thing should be faster.

    Edit: Is it faster to have it check the colors one by one (what you did) or have it search for them on a bitmap (what I did)?

  22. #22
    Join Date
    Jun 2007
    Posts
    1,312
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Macrosoft View Post
    good idea

    I think im going to edit mine so that the user can input the amount of points used. Then Ill shorten my strike failsafe a bit and the whole thing should be faster.

    Edit: Is it faster to have it check the colors one by one (what you did) or have it search for them on a bitmap (what I did)?
    The bitmap should be faster.
    Active only during the Summer...

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Flag
    By Jackrawl in forum OSR Help
    Replies: 13
    Last Post: 11-16-2007, 06:57 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
  •