Results 1 to 11 of 11

Thread: Detect Stop Player Movement

  1. #1
    Join Date
    Feb 2009
    Location
    UK
    Posts
    89
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Detect Stop Player Movement

    Here is my function which waits until player stops moving, it helps to overcome if the flags get stuck on the screen.


    SCAR Code:
    {*******************************************************************************
    function WalkEnd: Boolean;
    By: Gearsnare
    Description: Waits until player walking or running stops.
    *******************************************************************************}


    function WalkEnd: Boolean;
    var
      c, c2, H, i, i2: Integer;
      P: array [0..9] of array [0..3] of Integer;
      BadColors: TIntegerArray;

    begin
      BadColors := [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];
      repeat
        i := 0;
        c := 0;
        c2 := 9;
        repeat
          if (not(LoggedIn)) then Exit;
          if (not(GetColor(120, 175) = 0)) then
            P[i][0] := 571 + Random(110);
            P[i][1] := 33 + Random(100);
            P[i][2] := GetColor(P[i][0], P[i][1]);
            H := High(BadColors);
            for i2 := 0 to H do
              if (P[i][2] = BadColors[i2]) then Break;
            i := i + 1;
        until (i = 9);
      Wait(1000);
      i := 0;
      for i := 0 to 9 do
      begin
        P[i][3] := GetColor(P[i][0], P[i][1]);
        for i2 := 0 to H do
            if (P[i][3] = BadColors[i2]) then c2 := c2 - 1;
        if (P[i][2] = P[i][3]) then c := c + 1;
      end;
      if (c = 0) then Break;
      until (c >= c2);
      Result := True;
    end;

    I'm new to scripting, is it correct to post stuff like this into this part of the forum?

    Thanks
    Last edited by Gearsnare; 04-09-2009 at 12:28 PM.

  2. #2
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Won't work all the time, because of the players and npcs moving. There is a better fix for this.

  3. #3
    Join Date
    Feb 2009
    Location
    UK
    Posts
    89
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by mormonman View Post
    Won't work all the time, because of the players and npcs moving. There is a better fix for this.
    What is better fix?
    I will improve by repeating loop if the random points color was that of a NPC, player or drop dot in the morning as it's too late now.

  4. #4
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Hey, nice Though I've already released a piece of coding with the same concept, but a bit more reliable :P Although it is not 100% safe/might be slow if other objects are changing on the screen.

  5. #5
    Join Date
    Mar 2006
    Location
    USA
    Posts
    948
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    It may be best to calculate the percent change in the minimap. You could do this a bit like gas checking works.

  6. #6
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    SCAR Code:
    {*******************************************************************************
    function IsMoving(WaitTime: Integer): Boolean;
    By: Bullzeye95; Edits by Nava2
    Description: Checks if the currently loaded player is moving. Uses Minimap,
                 ignoring all dots which can move without the player moving.
                 Nava2 edit: Added try..finally, also changed to work with SMART,
                 as well added WaitTime Parameter.
    *******************************************************************************}

    function IsMoving(WaitTime: Integer): Boolean;
    var
      BMP, BMP2, I, H, x, y: Integer;
      ReplaceCols: TIntegerArray;
      P: TPointArray;
      DC: HDC;
    begin
      WaitTime := Max(100, WaitTime);
      try
        DC := GetTargetDC;
        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);
        H := High(ReplaceCols);
        for I:= 0 to H do
          FastReplaceColor(BMP, ReplaceCols[i], 0);
        wait(WaitTime);
        SafeCopyCanvas(GetClientCanvas, GetBitmapCanvas(BMP2), MMCX - 50, MMCY - 50, MMCX + 50, MMCY + 50, 0, 0, 100, 100);
        SetTargetDC(GetBitmapDC(BMP2));
        for I:= 0 to H 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);
      finally
        SetTargetDC(DC);
        FreeBitmap(BMP);
        FreeBitmap(BMP2);
      end;
    end;

  7. #7
    Join Date
    Feb 2009
    Location
    UK
    Posts
    89
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I've edited mine a little so it is much more reliable than what it was.
    Yours is too complicated for me, could you please explain how it works?

    Thanks

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

    Default

    Bullzeye and I actually made it. Anyways, its not all that hard.

    All it does is create a bitmap of the minimap. Then, it goes through and sets all of the movable colours to 0.

    Following this, it creates another bitmap and finds the same colours, but replaces them with the colour of the original bitmap, so dots will not effect.

    Finally, it checks if it can find the old bitmap in the new one, if it can then we have stopped, if it cant then we are moving.

    Hope I helped
    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
    Dec 2007
    Location
    192.168.1.73
    Posts
    2,439
    Mentioned
    6 Post(s)
    Quoted
    119 Post(s)

    Default

    Is that in SRL currently? I can't seem to find it (only looked in FlagChat.scar), I'd find it very useful as its usually the reason my clay softner breaks, used to run for hours, now I get about max 2-3 hours a player.

  10. #10
    Join Date
    Feb 2009
    Location
    UK
    Posts
    89
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Richard View Post
    Is that in SRL currently? I can't seem to find it (only looked in FlagChat.scar), I'd find it very useful as its usually the reason my clay softner breaks, used to run for hours, now I get about max 2-3 hours a player.
    Are you on about mine or Bullzeye and Nava2's? Neither are currently in SRL though.

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

    Default

    Mine is in the dev svn currently. It will be in the next public revision.
    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

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
  •