Results 1 to 4 of 4

Thread: Enhancement - Setting compass to North

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

    Default Enhancement - Setting compass to North

    I had problems with perfectnorth, and makecompass('n'), so i decided to make my own. It doesn't necessarilary give you exactly perfect north, but its close enough for me (close enough for radialroadwalk and all those goodies to work just fine).


    Edit: Updated 11/14/06
    SCAR Code:
    program New;
    {.Include SRL\SRL\Extended\xColor.Scar}
    {.Include SRL\SRL.Scar}
     
    Function ArrayDifference(one, two:Array of Integer):Integer;
    Var mylength, c, different:integer;
      Begin
      different:= 0;
      mylength:= Min(GetArrayLength(one), GetArrayLength(two));
      For c:=0 to (mylength - 1) Do
        Begin
          If(One[c] <> Two[c])Then
             different:= different + 1;
        End;
      Result:= different;
      End;

    Function CameraMoving:Boolean;
    Var
      c, v:Integer;
      SColor, FColor: Array [0..30] of Integer;
      Begin
        v:= 0;
        For c:= 13 to 43 Do
            Begin
              SColor[v]:= GetColor(593, c);
              v:= v + 1;
            End;
        Wait(100);
        v:= 0;
        For c:= 13 to 43 Do
            Begin
              FColor[v]:= GetColor(593, c);
              v:= v + 1;
            End;
        If(ArrayDifference(SColor, FColor) > 5)Then
          Begin
            Result:= true;
          End Else
            Begin
              v:= 0;
                For c:= 13 to 43 Do
                  Begin
                    SColor[v]:= GetColor(686, c);
                    v:= v + 1;
                  End;
              Wait(100);
              v:= 0;
              For c:= 13 to 43 Do
                  Begin
                    FColor[v]:= GetColor(686, c);
                    v:= v + 1;
                  End;
              If(ArrayDifference(SColor, FColor) > 5)Then
                Result:= true;
            End;
      End;
         
    Function ShortWay(Direction:String):Boolean;
    Var
      QuadOne, QuadTwo, QuadThree, QuadFour:TPointArray;
      GetMax: Integer;
      Begin
        FindColorsTolerance(QuadTwo, 920735, 552, 7, 566, 19, 80);
        FindColorsTolerance(QuadOne, 920735, 566, 7, 579, 19, 80);
        FindColorsTolerance(QuadThree, 920735, 552, 19, 566, 31, 80);
        FindColorsTolerance(QuadFour, 920735, 566, 19, 579, 31, 80);//4341941}
        {FindColorsTolerance(QuadTwo, 4341941, 552, 7, 566, 19, 80);
        FindColorsTolerance(QuadOne, 4341941, 566, 7, 579, 19, 80);
        FindColorsTolerance(QuadThree, 4341941, 552, 19, 566, 31, 80);
        FindColorsTolerance(QuadFour, 4341941, 566, 19, 579, 31, 80);//4341941  }

        GetMax := Max(Max(GetArrayLength(QuadOne), GetArrayLength(QuadTwo)),Max(GetArrayLength(QuadThree), GetArrayLength(QuadFour)));
        Writeln('');
        Writeln('Max: '+IntToStr(GetMax));
        Writeln('One: '+IntToStr(GetArrayLength(QuadOne)));
        Writeln('Two: '+IntToStr(GetArrayLength(QuadTwo)));
        Writeln('Three :'+IntToStr(GetArrayLength(QuadThree)));
        Writeln('Four: '+IntToStr(GetArrayLength(QuadFour)));
         If(StrGet(Direction, 1) = 'n')Then
            Begin
              //Result:= ((GetArrayLength(QuadTwo) + GetArrayLength(QuadThree)) > (GetArrayLength(QuadOne) + GetArrayLength(QuadFour)));
              If((GetMax = GetArrayLength(QuadTwo)) or (GetMax = GetArrayLength(QuadThree)))Then
                Result:= true;
            End Else
          If(StrGet(Direction, 1) = 'e')Then
            Begin
              //Result:= ((GetArrayLength(QuadThree) + GetArrayLength(QuadFour)) < (GetArrayLength(QuadOne) + GetArrayLength(QuadTwo)));
              If((GetMax = GetArrayLength(QuadThree)) or (GetMax = GetArrayLength(QuadFour)))Then
                Result:= true;
            End Else
          If(StrGet(Direction, 1) = 'w')Then
            Begin
              //Result:= ((GetArrayLength(QuadOne) + GetArrayLength(QuadTwo)) < (GetArrayLength(QuadThree) + GetArrayLength(QuadFour)));
              If((GetMax = GetArrayLength(QuadOne)) or (GetMax = GetArrayLength(QuadTwo)))Then
                Result:= true;
            End Else
          If(StrGet(Direction, 1) = 's')Then
            Begin
              //Result:= ((GetArrayLength(QuadFour) + GetArrayLength(QuadOne)) > (GetArrayLength(QuadTwo) + GetArrayLength(QuadThree)));
              If((GetMax = GetArrayLength(QuadOne)) or (GetMax = GetArrayLength(QuadFour)))Then
                Result:= true;
            End Else
          Begin
            Writeln('Compass direction must start with first letter "n", "e", "s", "w"');
            Exit;
            Result:= false;
          End;
      End;
     
     
    Function FindCompassDirectionColors(Direction: String):Boolean;
    Var c:integer;
      Begin
        If(StrGet(Direction, 1) = 'n')Then
          Begin                        //bottom                                       //west                                 //east
            If(FindColor(x, y, 920735, 564, 30, 569, 36) and FindColor(x, y, 920735, 546, 16, 556, 22) and FindColor(x, y, 920735, 576, 16, 584, 23))Then
              Result:= True;
          End Else
        If(StrGet(Direction, 1) = 'w')Then
          Begin
            If(FindColor(x, y, 920735, 564, 30, 569, 36) and FindColor(x, y, 920735, 546, 16, 556, 22) and (Not (FindColor(x, y, 920735, 576, 16, 584, 23))))Then
              Result:= True;
          End Else
        If(StrGet(Direction, 1) = 'e')Then
          Begin
            If(FindColor(x, y, 920735, 564, 30, 569, 36) and (Not (FindColor(x, y, 920735, 546, 16, 556, 25))) and FindColor(x, y, 920735, 576, 16, 584, 23))Then
              Result:= True;
          End Else
        If(StrGet(Direction, 1) = 's')Then
          Begin
            If((Not (FindColor(x, y, 920735, 564, 30, 569, 36))) and FindColor(x, y, 920735, 546, 16, 556, 22) and FindColor(x, y, 920735, 576, 16, 584, 23))Then
              Result:= True;
          End;
      End;

    Function Compass(Direction: String):Boolean;
    var
    TheKey:Boolean;
      Begin
      Direction:= Lowercase(Direction);
      TheKey:= ShortWay(Direction);
      If(Not (FindCompassDirectionColors(Direction)))Then
        Begin
        If(TheKey)Then
          Begin
            KeyDown(VK_Right);
          End
        Else
          Begin
            KeyDown(VK_Left);
          End;
        Repeat
          If( (Not (CameraMoving)) {and (Random(10) < 2)} and (Not (FindCompassDirectionColors(Direction))) )Then
            Begin
              ActivateClient;
              TheKey:= ShortWay(Direction);
              If(TheKey)Then
                Begin
                  KeyDown(VK_Right);
                End
              Else
                Begin
                   KeyDown(VK_Left);
                End;
            End;
          Wait(1);
        Until(FindCompassDirectionColors(Direction));
        If(TheKey)Then
          Begin
            KeyUp(VK_Right);
          End
        Else
          Begin
            KeyUp(VK_Left);
          End;
        End;
      End;
     
    begin
    SetupSRL;
    ActivateClient;
    Compass('n');
    end.

    Works with N, E, S, and W now

  2. #2
    Join Date
    Feb 2006
    Posts
    406
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    i had to change countcolor to

    Code:
      findcolorstolerance(arr,color,x1,y1,x2,y2,0);
      Result := getarraylength(arr);
    (freddy took countcolor out of his dll in the dev version?)

    but this works awesomely
    i believe the current makecompass relies on checking one pixel, so it misses on some comps
    this however, always works, and it rotates in the shortest direction
    my only challenge is to make it work in all 4 directions

    off topic:
    why arent you a member yet?
    havent you applied?
    i could seriously see you becoming a dev somewhere down the road with all these "enhancements" to srl

  3. #3
    Join Date
    Oct 2006
    Posts
    119
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by masquerader View Post
    i had to change countcolor to

    Code:
      findcolorstolerance(arr,color,x1,y1,x2,y2,0);
      Result := getarraylength(arr);
    (freddy took countcolor out of his dll in the dev version?)

    but this works awesomely
    i believe the current makecompass relies on checking one pixel, so it misses on some comps
    this however, always works, and it rotates in the shortest direction
    my only challenge is to make it work in all 4 directions

    off topic:
    why arent you a member yet?
    havent you applied?
    i could seriously see you becoming a dev somewhere down the road with all these "enhancements" to srl
    I'll answer you're questions through numbering :-p.
    1. I'm not a member yet, because from what i heard you need to generally release one script or more to get a membership status. My football team is in the playoffs right now, 1 game away from playing in the state championship, and my little brother likes to hog the computer. So I haven't had as much time as i would like to finish my first script (miner/banker). Once footballs over, you'll see more out of me i think and I hope to become a member then, if not in earlier.
    2. No I haven't applied yet because you generally need a script from what I've heard. I'm not sure if my enhancements are good enough to pull the whole weight to get me in.

    Thanks for the compliments . I tend to overdo things with RS, but what the heck. I find something i enjoy doing (scripting n such) and i do as best i can at it. First it was SCAR for RSC, then STS for RSC, and now SCAR for RS2.

  4. #4
    Join Date
    Oct 2006
    Posts
    119
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ooo yea another good thing to do would change the Repeat Until to a while/do because that way it won't move the camera because sometimes it'll bring back one half of the colors picked greater than the other half that it takes them from so it might move the camera out of north even once it's already there.

    If that doesn't make sense then ask. It'd be simple to make it work for East, West, and/or South... Just have it look for those red dots in the right places for it.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Setting compass to north
    By Mars in forum OSR Help
    Replies: 16
    Last Post: 04-20-2008, 08:36 PM
  2. Havign trouble setting compass
    By knassyl in forum OSR Help
    Replies: 16
    Last Post: 10-21-2007, 06:38 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
  •