Results 1 to 22 of 22

Thread: Saturn's function compilation!

  1. #1
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default Saturn's function compilation!

    Functions!

    Contents
    ChangeLog:
    (8/29)
    Initial release of functions.
    Minor changes.
    (8/30)
    Core->Text.scar
    Edited FindArrayTextTPAEx.
    Edited TrimString to be more versatile.
    Added function ChooseOptionText.
    Core->GameTab.scar
    Edited CheckQuest due to changes in TrimString.
    (11/28)
    Core->Text.scar
    Improved FindTextArrayTPA(Ex)
    Changed ChooseOptionText to ChooseOptionTPA and improved.
    Core->GameTab.scar
    Improved CheckQuest.
    Added function GetQP.
    (12/18)
    Reflection->Interfaces.scar
    Added function GetQP.
    (2/1)
    Skill->WoodCutting.scar
    Added functions IsEnt and IsEntText.
    (2/15)
    Core->MapWalk.scar
    Added function GetWalls.

  2. #2
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Core:





    Colors.scar
    SCAR Code:
    {*******************************************************************************
    procedure CaptureCTS(var CTS: integer);
    By: lordsaturn
    Description: Captures the ColorToleranceSpeed and stores to variable 'CTS'.
    *******************************************************************************}

    procedure CaptureCTS(var CTS: integer);
    begin
      CTS := GetColorToleranceSpeed;
    end;


    {*******************************************************************************
    procedure RestoreCTS(CTS: integer);
    By: lordsaturn
    Description: Restores ColorToleranceSpeed 'CTS' and default ColorSpeed2Modifiers.
    *******************************************************************************}

    procedure RestoreCTS(CTS: integer);
    begin
      if GetColorToleranceSpeed = 2 then
        SetColorSpeed2Modifiers(0.2, 0.2);
      ColorToleranceSpeed(CTS);
    end;
    SCAR Code:
    {*******************************************************************************
    function FindColorsArrayTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
    By: lordsaturn
    Description: Finds all colors of TIntegerArray 'Colors' in the area specified by
    xs, ys, xe, ye and returns their coordinates in T2DPA 'ResultTPA'. Will return
    True if all colors are found.
    *******************************************************************************}

    function FindColorsArrayTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
    var
      i, LTIA: integer;

    begin
      if Length(Colors) = 0 then Exit;
      Result := True;
      LTIA := Length(Colors) - 1;
      for i := 0 to LTIA do
        if not FindColorsTolerance(ResultTPA[i], Colors[i], xs, ys, xe, ye, Tol) then
          Result := False;
    end;


    {*******************************************************************************
    function FindColorsArraySpiralTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
    By: lordsaturn
    Description: Same as FindColorsArrayTolerance, but uses spiral technique.
    *******************************************************************************}

    function FindColorsArraySpiralTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
    var
      i, LTIA: integer;
      MP: TPoint;
     
    begin
      if Length(Colors) = 0 then Exit;
      Result := True;
      LTIA := Length(Colors) - 1;
      MP := MidPoint(xs, ys, xe, ye);
      for i := 0 to LTIA do
      begin
        FindColorsSpiralTolerance(MP.x, MP.y, ResultTPA[i], Colors[i], xs, ys, xe, ye, Tol);
        if Length(ResultTPA[i]) = 0 then
          Result := False;
      end;
    end;





    GameTab.scar
    SCAR Code:
    {*******************************************************************************
    function CheckQuest(Quest: string): Boolean;
    By: lordsaturn
    Description: Will return true if the quest 'Quest' is completed, and perform the
    action declared in 'Action'.
    *******************************************************************************}

    function CheckQuest(Quest: string; Action: fnct_ActionOptions): Boolean;
    var
      arS: TStringArray;
      arI: TIntegerArray;
      x, y, fx, fy, i, c, fColor, WT, L: Integer;
      UltiBool: Boolean;
    begin
      arS := TrimString(Quest);
      L := Length(arS) - 1;
      for i := 0 to L do
      begin
        if arS[i] = 'i' then arS[i] := 'II';
        if arS[i] = 'okt' then arS[i] := 'ok';
      end;
      arI := [65280, 65535, 255];
      GameTab(3);
      while not UltiBool do
      begin
        c := c + 1;
        if c = 2 then
          if GetColor(728, 245) <> 1316634 then
            Mouse(728, 250, 4, 4, True);
        if c = 3 then
        begin
          MMouse(728, 446, 5, 5);
          GetMousePos(x, y);
          HoldMouse(x, y, True);
        end;
        if GetColor(728, 419) = 1316634 then
        begin
          Writeln('We could not find the quest name.');
          Result := False;
          Exit;
        end;
        for i := 0 to 2 do
        begin
          UltiBool := FindTextArrayTPAEx(arI[i], 0, 547, 227, 720, 454, fx, fy, arS, StatChars, 140, 13);
          if UltiBool then
          begin
            arI[i] := fColor;
            Break;
          end;
        end;
      end;
      if UltiBool then
      begin
        if c > 2 then
        begin
          WT := 100+Random(700);
          Wait(WT);  //for randomization
          ReleaseMouse(x, y, True);
        end;
        if fColor = arI[0] then
          Result := True;
        if Action = Nothing then Exit;
        if WT > 0 then fy := fy - (WT/5) - 11;
        MMouse(fx, fy, 4, 4);
        if not FindTextArrayTPA(16777215, 0, 547, 227, 720, 454, arS, StatChars) then
        begin
          for i := 0 to 2 do
            if FindTextArrayTPAEx(arI[i], 0, 547, 227, 720, 454, fx, fy, arS, StatChars, 140, 13) then
              Break;
          if i = 3 then Exit;
          MMouse(fx, fy, 4, 4);
        end;
        if Action = Move then Exit;
        GetMousePos(fx, fy);
        case Action of
          ClickLeft: Mouse(fx, fy, 0, 0, True);
          ClickRight: begin
                        Mouse(fx, fy, 0, 0, False);
                        ChooseOption('ead');
                      end;
        end;
        MouseBox(455, 66, 474, 84, 1);
        //CloseWindows;
      end;
    end;
    SCAR Code:
    {*******************************************************************************
    function GetQP: Integer;
    By: lordsaturn
    Description: Will return number of quest points.
    *******************************************************************************}

    function GetQP: Integer;
    var
      x, y: integer;
      s: string;
    begin
      if GetCurrentTab <> 3 then GameTab(3);
      if FindColor(x, y, 2070763, 650, 205, 712, 226) then
      begin
        s := Trim(GetTextAtEx(x - 2, y - 2, 5, SmallChars, False, False, 0, 1, 2070763, 3, False, tr_AllChars));
        try
          Result := StrToInt(s);
        except
          if Pos('g', Lowercase(s)) <> 0 then
          begin
            s := Uppercase(ReplaceRegex(Lowercase(s), 'g', '6'));
            try
              Result := StrToInt(s);
            except
              writeln('GetQP failed and got: '+s);
            end;
          end;
        end;
      end;
    end;



    MapWalk.scar
    SCAR Code:
    {*******************************************************************************
    function GetWalls: TPointArray;
    By: lordsaturn
    Description: Will return all the white-colored walls on the minimap in a TPA.
    Could be used for perfect map aligning projects.
    *******************************************************************************}

    function GetWalls: TPointArray;
    var
      CTS, Hi, i, x, y, c, j: integer;
      P, Playerses: TPointArray;
    begin
      if not LoggedIn then Exit;
      CTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetColorspeed2Modifiers(15.75, 5.27);    // 15462126
      FindColorsSpiralTolerance(MMCX, MMCY, P, 15593449, MMX1, MMY1, MMX2, MMY2, 7);
      SetColorspeed2Modifiers(0.2, 0.2);
      ColorToleranceSpeed(1);
      FindColorsTolerance(Playerses, 16711422, MMX1, MMY1, MMX2, MMY2, 19);
      ColorToleranceSpeed(2);
      P := RemoveDistTPointArray(MMCX, MMCY, 76, P, True);
      P := ClearTPAFromTPA(P, Playerses);
      Hi := High(P);
      for j := 0 to 2 do
        for i := 0 to Hi do
        begin
          x := P[i].x;
          y := P[i].y;
          c := GetColor(x-1, y);
          if ((GetColor(x-2, y) = c) and (GetColor(x-1, y-1) = c) and
             (GetColor(x-2, y-1) = c) and (GetColor(x, y+2) = 65536)) or
             ((c = 65536) and ((GetColor(x, y+1) = c) or (GetColor(x+2, y) = c))) or
             (GetColor(x, y+1) = 12961221) or (GetColor(x, y+1) = 13816530) then
          begin
            P := RemoveDistTPointArray(x, y, 2, P, False);
            Hi := High(P);
          end;
        end;
      Result := P;
    end;



    Math.scar
    SCAR Code:
    {*******************************************************************************
    function MidPoint(x1, y1, x2, y2: integer): TPoint;
    By: lordsaturn
    Description: Will return the midpoint of two points as a TPoint.
    *******************************************************************************}

    function MidPoint(x1, y1, x2, y2: integer): TPoint;
    var
      mx, my: integer;
      mmx, mmy: extended;
      P: TPoint;

    begin
      mx := x1 + x2;
      my := y1 + y2;
      mmx := mx / 2;
      mmy := my / 2;
      P := Point(Round(mmx), Round(mmy));
      Result := P;
    end;
    Same as:
    SCAR Code:
    MiddleTPA([inttopoint(x1, y1), inttopoint(x2, y2)]);





    Text.scar
    SCAR Code:
    {*******************************************************************************
    function FindTextArrayTPAEx(Color, Tol, xs, ys, xe, ye: integer; var x, y :integer; TextArray: TStringArray; Chars, MaxDist: integer; Action: fnct_ActionOptions; var Bools: array of Boolean): Boolean;
    By: lordsaturn
    Description: Like FindTextTPAEx, but finds an array of text, declared by
    'TextArray'. Returns true if all instances of the TextArray are found within box
    defined by distance boundaires 'w' and 'h'.
    *******************************************************************************}

    function FindTextArrayTPAEx(Color, Tol, x1, y1, x2, y2: integer; var x, y :integer; TextArray: TStringArray; Chars, w, h: integer): Boolean;
    var
      TextTPA, SearchTPA, tmpMatches: TPointArray;
      SearchT2D: T2DPointArray;
      i, j, Height, LATPA, LTSA: integer;
      foundInDist: Boolean;
    begin
      if not FindColorsTolerance(SearchTPA, Color, x1, y1, x2, y2, Tol) then Exit;
      SearchT2D := TPAtoATPAEx(SearchTPA, w, h);
      LATPA := High(SearchT2D);
      LTSA := Length(TextArray) - 1;
      for i := 0 to LATPA do
      begin
        for j := 0 to LTSA do
        begin
          TextTPA := LoadTextTPA(TextArray[j], Chars, Height);
          foundInDist := FindTextTPAinTPA(Height, TextTPA, SearchT2D[i], tmpMatches);
          if not foundInDist then Break;
        end;
        if foundInDist then Break;
      end;
      if foundInDist then
      begin
        Result := True;
        MiddleTPAEx(SearchT2D[i], x, y);
      end;
    end;


    {*******************************************************************************
    FindTextArrayTPA(Color, Tol, xs, ys, xe, ye: integer; TextArray: TStringArray; Chars: integer): Boolean;
    By: lordsaturn
    Description: Like FindTextArrayTPAEx, but has no distance restriction, and will
    only return a boolean statement.
    *******************************************************************************}

    function FindTextArrayTPA(Color, Tol, xs, ys, xe, ye: integer; TextArray: TStringArray; Chars: integer): Boolean;
    var
      cx, cy: integer;
    begin
      Result := FindTextArrayTPAEx(Color, Tol, xs, ys, xe, ye, cx, cy, TextArray, Chars, xe-xs, ye-ys);
    end;
    SCAR Code:
    {*******************************************************************************
    function TrimString(TString: string): TStringArray;
    By: lordsaturn
    Description: Trims a string into an array of short 3-character strings.
                 Used in CheckQuest, ChooseOptionText.
    *******************************************************************************}

    function TrimString(TString: string): TStringArray;
    var
      i, P, L: integer;
      S, S2: string;
      arS: TStringArray;
    begin
      S := Trim(TString);
      S := Lowercase(S);
      S := Replace(S, '''', ' ');
      S := Replace(S, '-', ' ');
      arS := strToStrArray(S);
      L := Length(arS) - 1;
      for i := 0 to L do
      begin
        arS[i] := Trim(arS[i]);
        if Pos('.', arS[i]) <> 0 then
          Delete(arS[i], P, Length(arS[i])-P+1);
        arS[i] := Replace(arS[i], '&', '');
        if (Length(arS[i]) = 1) then arS[i] := '';
        if (not(arS[i] = 'of')) and
           (not(arS[i] = 'to')) then
          arS[i] := Trim(Copy(arS[i], 2, 3));
        if arS[i] <> '' then
          S2 := S2+' '+arS[i];  //rebuilding the TSA to remove blank indexes
      end;
      S2 := Trim(S2);
      Result := strToStrArray(S2);
    end;
    SCAR Code:
    {*******************************************************************************
    function ChooseOptionTPA(Option: string): Boolean;
    By: lordsaturn
    Description: Chooses an option using TPAs. Returns true if found. Use full text
    string for best results.  Ex: ChooseOptionTPA('Talk-to Sir Vant');
                                  ChooseOptionTPA('Chop down Oak');
    *******************************************************************************}

    function ChooseOptionTPA(Option: string): Boolean;
    var
      x, y, i, c: Integer;
      TPA: TPointArray;
      P: TPoint;
      B: TBox;
      s: TStringArray;
    begin
      GetClientDimensions(B.X2, B.Y2);
      B.X1 := 0;
      B.Y1 := 0;
      FindColorsTolerance(TPA, 4674653, B.X1, B.Y1, B.X2, B.Y2, 0);
      If Length(TPA) < 10 Then
        Exit;
      B.X2 := 0;
      B.Y2 := 0;

      P := TPA[0];
      For I := 0 To High(TPA) - 1 Do
        If TPA[i].X = TPA[I+1].X - 1 Then
        Begin
          If C > 5 Then
          Begin
            B.X1 := P.X;
            B.Y1 := P.Y;
            Break;
          End Else
            C := C + 1;
        End
        Else
        Begin
          P := TPA[I + 1];
          C := 0;
        End;
      If I = Length(TPA) Then
      Begin
        WriteLn('Choose Option Menu Getting Failed');
        Exit;
      End;
      InvertTPA(TPA);
      C := 0;
      P := TPA[0];
      For I := 0 To High(TPA) - 1 Do
        If TPA[i].X = TPA[I+1].X + 1 Then
        Begin
          If C > 5 Then
          Begin
            B.X2 := P.X;
            B.Y2 := P.Y;
            Break;
          End Else
            C := C + 1;
        End Else
        Begin
          P := TPA[I + 1];
          C := 0;
        End;
      If I = Length(TPA) Then
      Begin
        WriteLn('Choose Option Menu Getting Failed');
        Exit;
      End;

      s := TrimString(Option);
      Result := FindTextArrayTPAEx(16777215, 255, B.x1, B.y1, B.x2, B.y2, x, y, s, UpChars, B.x2-B.x1, 14);
      if Result then
        if (x <> 0) and (y <> 0) then
        begin
          Mouse(x, y, (Length(Option)*5)/2, 3, True);
          Exit;
        end;
      Result := ChooseOptionMulti(s);
    end;


    Useless, but works:
    SCAR Code:
    {*******************************************************************************
    function LoadTextArrayTPA(TextArray: TStringArray; chars: integer; var Height: TIntegerArray): T2DPointArray;
    By: lordsaturn
    Description: Loads TPAs of the TStringArray 'TextArray'. Returns the TPAs in a
    T2DPointArray corresponding to the indexes of TextArray. Also returns the
    TIntegerArray 'Height' with indexes corresponding to TextArray.
    *******************************************************************************}

    function LoadTextArrayTPA(TextArray: TStringArray; chars: integer; var Height: TIntegerArray): T2DPointArray;
    var
      DC: HDC;
      CTS, w, h, BMP, i: Integer;
     
    begin;
      if Length(TextArray) = 0 then Exit;
      DC := GetClientCanvas.Handle;
      CaptureCTS(CTS);
      ColorToleranceSpeed(0);
      for i := 0 to Length(TextArray) - 1 do
      begin
        BMP := CreateBitmapMaskFromText(TextArray[i], Chars);
        GetBitmapSize(BMP, W, H);
        SetTargetDc(GetBitmapDc(BMP));
        FindColorsTolerance(Result[i], clwhite, 0, 0, w+1, h+1, 0);
        Height[i] := h - 1;
        FreeBitmap(BMP);
      end;
      SetTargetDC(DC);
      RestoreCTS(CTS);
    end;

  3. #3
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Misc:





    WizzyPlugin.scar..?
    SCAR Code:
    {*******************************************************************************
    function RemoveMultiDistTPA(x, y, w, h: Integer; ThePoints: TPointArray; Sort: Boolean): TPointArray;
    By: lordsaturn
    Description: Like RemoveDistTPointArray, but multi-dimensional. Will sort if true.
    *******************************************************************************}

    function RemoveMultiDistTPA(x, y, w, h: Integer; ThePoints: TPointArray; Sort: Boolean): TPointArray;
    var
      tmpDistX, tmpDistY, i, LTPA: integer;
    begin
      LTPA := Length(ThePoints) - 1;
      for i := 0 to LTPA do
      begin
        tmpDistX := iAbs(ThePoints[i].x - x);
        tmpDistY := iAbs(ThePoints[i].y - y);
        if w <> 0 then
          if (tmpDistX >= w) then
          begin
            TPARemove(ThePoints, i);
            LTPA := LTPA - 1;
            Continue;
          end;
        if h = 0 then Continue;
        if (tmpDistY >= h) then
        begin
          TPARemove(ThePoints, i);
          LTPA := LTPA - 1;
        end;
      end;
      if Sort then SortTPAFrom(Arr, inttopoint(x, y));
      Result := ThePoints;
    end;


    Array Removal:
    SCAR Code:
    {*******************************************************************************
    procedure TPARemove(var Arr: TPointArray; Index: Integer);
    By: lordsaturn
    Description: Will remove an index from a TPointArray
    *******************************************************************************}

    procedure TPARemove(var Arr: TPointArray; Index: Integer);
    begin
      tSwap(Arr[Index], Arr[Length(Arr) - 1]);
      SetLength(Arr, Length(Arr) - 1);
    end;


    {*******************************************************************************
    function TPAMultiRemove(Arr: TPointArray; From, Last: integer; Sort: Boolean): TPointArray;
    By: lordsaturn
    Description: Will remove multiple indexes from a TPointArray. Will sort if true.
    *******************************************************************************}

    function TPAMultiRemove(Arr: TPointArray; From, Last: integer; Sort: Boolean): TPointArray;
    var
      i, c: integer;
    begin
      for i := From to Last do
        TPARemove(Arr, i);
      if Sort then SortTPAFrom(Arr, Arr[0]);
      Result := Arr;
    end;


    {*******************************************************************************
    function TIARemove(Arr: TIntegerArray; Index: integer): TIntegerArray;
    By: lordsaturn
    Description: Will remove an index from an integer array.
    *******************************************************************************}

    function TIARemove(Arr: TIntegerArray; Index: integer): TIntegerArray;
    var
      i, arLength: integer;
    begin
      arLength := Length(Arr) - 1;
      for i := Index to arLength - 1 do
        Arr[i] := Arr[i + 1];
      SetArrayLength(Arr, arLength);
      Result := Arr;
    end;


    {*******************************************************************************
    function TIAMultiRemove(Arr: TIntegerArray; From, Last: integer): TIntegerArray;
    By: lordsaturn
    Description: Will remove multiple indexes from an integer array.
    *******************************************************************************}

    function TIAMultiRemove(Arr: TIntegerArray; From, Last: integer): TIntegerArray;
    var
      i: integer;
    begin
      for i := From to Last do
        Arr := TIARemove(Arr, i);
      Result := Arr;
    end;

  4. #4
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Skill:



    WoodCutting.scar
    SCAR Code:
    {*******************************************************************************
    function IsEnt(fx, fy: integer): Boolean;
    By: lordsaturn
    Description: Returns true if an ent is near the given coords.
    *******************************************************************************}

    function IsEnt(fx, fy: integer): Boolean;
    var
      x, y, CTS: integer;
      L: Extended;
      c, c2: T2DIntArray;
    begin
      c := GetBitmapAreaColors(fx-30, fy-30, fx+30, fy+30);
      Wait(100);
      c2 := GetBitmapAreaColors(fx-30, fy-30, fx+30, fy+30);
      CTS := GetColorToleranceSpeed;
     
      ColorToleranceSpeed(2);
      SetColorspeed2Modifiers(0.15, 0.5);
      for x := 0 to 60 do
        for y := 0 to 60 do
        begin
          if not SimilarColors(c[x][y], 5013108, 20) then
            c[x][y] := 0;
          if not SimilarColors(c2[x][y], 5013108, 20) then
            c2[x][y] := 0;
        end;
      SetColorspeed2Modifiers(0.2, 0.2);
      ColorToleranceSpeed(1);
     
      for x := 0 to 60 do
        for y := 0 to 60 do
          if (not(SimilarColors(c[x][y], c2[x][y], 5))) and
             ((c[x][y] <> 0) or (c[x][y] <> 0)) then
            Inc(L);
      Result := (L/(1.0*61*61)*100) > 30;
      ColorToleranceSpeed(CTS);
    end;

    {*******************************************************************************
    function IsEntText: Boolean;
    By: lordsaturn
    Description: Returns true if an the uptext hints there is an ent.
    *******************************************************************************}

    function IsEntText: Boolean;
    var
      CTS: Integer;
    begin
      CTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.03, 0.75);
      Result := CountColorTolerance(118478, 9, 10, 124, 23, 4) > 10;
      SetColorSpeed2Modifiers(0.2, 0.2);
      ColorToleranceSpeed(CTS);
    end;

  5. #5
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Reflection:



    Interfaces.scar

    SCAR Code:
    function GetQP: integer;
    var
      s: string;
    begin
      if not LoggedIn then Exit;
      GameTab(3);
      s := GetInterfaceText(274, 2);
      Delete(s, 1, 14);
      Result := StrToIntDef(s, -1);
    end;

  6. #6
    Join Date
    Feb 2007
    Location
    SparklesProd.com
    Posts
    2,406
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Wow, When i was teaching you 2 years ago I never dreamt of this. You made me proud ^_^

  7. #7
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    We need to have an epic discussion about HSL.

    SetColorSpeed2Modifers.

    a) Only has effect when using HSL, so, add an if()then.
    b) These modifiers are the Hue and Saturation modifiers, that SCAR's SimilarColors will use (that color finding functions use). The tolerance we use while in the CTS 2 mode, or in other words, using HSL, is the L, Luminosity, Luminance, whatever you want to call it. Now, SimilarColors does

    Hue * Luminosity and Sat * Luminosity, and compares those values of the other color input in SimilarColors. This way, we only need to use one variable to adjust tolerance, instead of doing 3x work comparing Hue and Saturation too.


    So, when you have 0.2 and 0.2, the standard ones, as the modifiers, it detects colors within 2.0 and 2.0 Hue and Saturation difference, not 0.2 and 0.2.

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

    Default

    I think that SRL needs to be seriously cleaned up, and one to two lined functions, like your CTS ones, shouldn't be added.

    For
    SCAR Code:
    function FindColorsArrayTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
    var
      i: integer;
     
    begin
      if Length(Colors) = 0 then Exit;
      Result := True;
      for i := 0 to Length(Colors) - 1 do
      begin
        FindColorsTolerance(ResultTPA[i], Colors[i], xs, ys, xe, ye, Tol);
        if Length(ResultTPA[i]) = 0 then
          Result := False;
      end;
    end;
    Try something like this instead:
    SCAR Code:
    function FindColorsArrayTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
    var
      i, Hi: integer;
     
    begin
      if Length(Colors) = 0 then Exit;
      Result := True;
      Hi:= High(Colors);
      for i := 0 to Hi do
      begin
        FindColorsTolerance(ResultTPA[i], Colors[i], xs, ys, xe, ye, Tol);
        if Length(ResultTPA[i]) = 0 then
        begin
          Result := False;
          exit;
        end;
      end;
    end;
    (Same for the one after it)

    I think MidPoint is already in wizzup's plugin.

  9. #9
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    We need to have an epic discussion about HSL.

    SetColorSpeed2Modifers.

    a) Only has effect when using HSL, so, add an if()then.
    b) These modifiers are the Hue and Saturation modifiers, that SCAR's SimilarColors will use (that color finding functions use). The tolerance we use while in the CTS 2 mode, or in other words, using HSL, is the L, Luminosity, Luminance, whatever you want to call it. Now, SimilarColors does

    Hue * Luminosity and Sat * Luminosity, and compares those values of the other color input in SimilarColors. This way, we only need to use one variable to adjust tolerance, instead of doing 3x work comparing Hue and Saturation too.


    So, when you have 0.2 and 0.2, the standard ones, as the modifiers, it detects colors within 2.0 and 2.0 Hue and Saturation difference, not 0.2 and 0.2.
    I think i understand, so SimilarColors uses Luminosity and Sat instead of just Saturation?



    Quote Originally Posted by bullzeye95 View Post
    I think that SRL needs to be seriously cleaned up, and one to two lined functions, like your CTS ones, shouldn't be added.
    You're absolutely right. I understand a lot of these functions have no chance of being added into SRL. I post them anyways for my personal value, and for everyone else to see.

    For
    SCAR Code:
    function FindColorsArrayTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
    var
      i: integer;
     
    begin
      if Length(Colors) = 0 then Exit;
      Result := True;
      for i := 0 to Length(Colors) - 1 do
      begin
        FindColorsTolerance(ResultTPA[i], Colors[i], xs, ys, xe, ye, Tol);
        if Length(ResultTPA[i]) = 0 then
          Result := False;
      end;
    end;
    Try something like this instead:
    SCAR Code:
    function FindColorsArrayTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
    var
      i, Hi: integer;
     
    begin
      if Length(Colors) = 0 then Exit;
      Result := True;
      Hi:= High(Colors);
      for i := 0 to Hi do
      begin
        FindColorsTolerance(ResultTPA[i], Colors[i], xs, ys, xe, ye, Tol);
        if Length(ResultTPA[i]) = 0 then
        begin
          Result := False;
          exit;
        end;
      end;
    end;
    (Same for the one after it)

    I think MidPoint is already in wizzup's plugin.
    But if you exit the function, it won't find the colors for each value of the color array. BTW I improved these and reuploaded them.
    And my midpoint function is for two points, wizzy's is for a TPA.


    Quote Originally Posted by Sp0rky View Post
    Wow, When i was teaching you 2 years ago I never dreamt of this. You made me proud ^_^
    Thanks, Sp0rk. I appreciate all of your help way back when

  10. #10
    Join Date
    Oct 2007
    Location
    The deep web
    Posts
    2,496
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    nice, should help me a lot with my scripting.
    Did someone say GDK?

  11. #11
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Nice st00f .
    Verrekte Koekwous

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

    Default

    Quote Originally Posted by n3ss3s View Post
    So, when you have 0.2 and 0.2, the standard ones, as the modifiers, it detects colors within 2.0 and 2.0 Hue and Saturation difference, not 0.2 and 0.2.
    1 tolerance will look for 0.2 difference, 10 tolerance will look for 2.0 difference.
    Hup Holland Hup!

  13. #13
    Join Date
    Mar 2008
    Location
    The Netherlands
    Posts
    1,395
    Mentioned
    1 Post(s)
    Quoted
    1 Post(s)

    Default

    Very naice


  14. #14
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    1 tolerance will look for 0.2 difference, 10 tolerance will look for 2.0 difference.
    Okay, I understand. So then what is the point of setting the ColorSpeed2Modifiers, if they are automatically calculated by the tolerance?

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

    Default

    Quote Originally Posted by lordsaturn View Post
    Okay, I understand. So then what is the point of setting the ColorSpeed2Modifiers, if they are automatically calculated by the tolerance?
    I think that's what n3ss3s tried to explain. It's tolerance * modifier. So, actually, you have a tolerance for each part (H, S and L). The L tolerance is the tolerance you pass with FindColor. The tolerance for H and S is calculated through the modifiers.

    So when you have modifiers (H: 0.1; S: 2.5) and do the following FindColor:

    FindColorTolerance(x, y, clRed, 0, 0, 10, 10, 10)
    (Search for a red color with tolerance 10)

    Your L tolerance is now 10
    Your H tolerance is now 0.1 * 10 = 1
    Your S tolerance is now 2.5 * 10 = 25



    clRed converted to HSL is (0, 100, 50). All matching colors have HSL values like this:

    H: -10 to 10
    S: 99 to 101
    L: 25 to 75
    Hup Holland Hup!

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

    Default

    Quote Originally Posted by lordsaturn View Post
    But if you exit the function, it won't find the colors for each value of the color array. BTW I improved these and reuploaded them.
    Oh, I see. I wasn't really getting what that function was supposed to do.

    About that midpoint, maybe it's in one of the many other plugins that I seem to have gathered over time...

  17. #17
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    I think that's what n3ss3s tried to explain. It's tolerance * modifier. So, actually, you have a tolerance for each part (H, S and L). The L tolerance is the tolerance you pass with FindColor. The tolerance for H and S is calculated through the modifiers.

    So when you have modifiers (H: 0.1; S: 2.5) and do the following FindColor:

    FindColorTolerance(x, y, clRed, 0, 0, 10, 10, 10)
    (Search for a red color with tolerance 10)

    Your L tolerance is now 10
    Your H tolerance is now 0.1 * 10 = 1
    Your S tolerance is now 2.5 * 10 = 25



    clRed converted to HSL is (0, 100, 50). All matching colors have HSL values like this:

    H: -10 to 10
    S: 99 to 101
    L: 25 to 75

    Okay, I understand now, thanks for clearing that up.
    But one more question..What role does SimilarColors have in the colorfinding procedures?


    Edit: Update.

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

    Default

    SimilarColor checks if two colors match.

    So, from my previous example:

    clRed converted to HSL is (0, 100, 50). All matching colors have HSL values like this:

    H: -10 to 10
    S: 99 to 101
    L: 25 to 75
    If you do a FindColorsTolerance (cts = 2), all the colors with the above specifications will be returned.
    Hup Holland Hup!

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

    Default

    Where is the StrToStrArray function?
    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

  20. #20
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    Where is the StrToStrArray function?
    misc/arrayLoader.scar

    i'll probably make an alternative soon.

  21. #21
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by NaumanAkhlaQ View Post
    CheckQuest is broken. You have function in there which aren't in srl?
    It's not broken, It just uses my functions 'TrimString' and 'FindTextArrayTPAEx'.

  22. #22
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Actually, one to two lined functions (well, more like macros) are common in most standards. Just because they're small doesn't mean they shouldn'd be included, as a standard is just... for... often used stuff...?
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Saturn's Tut Runner!
    By lordsaturn in forum RS3 Outdated / Broken Scripts
    Replies: 100
    Last Post: 06-19-2009, 08:39 AM
  2. Saturn's Grand Exchange Walker!
    By lordsaturn in forum RS3 Outdated / Broken Scripts
    Replies: 8
    Last Post: 08-09-2008, 04:32 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
  •