Results 1 to 7 of 7

Thread: GetXP Fix

  1. #1
    Join Date
    Jan 2011
    Posts
    121
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default GetXP Fix

    I've written a new GetXP function. I used both the current GetXP function and GetChooseOptions as my guides.

    Why it should be committed: this one actually works!

    Simba Code:
    function GetXPNew(Skill: Variant): Integer;
    var
      TPA1, TPA2: TPointArray;
      ATPA, ATPAt: T2DPointArray;
      P: TPoint;
      B: TBox;
    begin
      Result := -1;
      if (not TabExists(tab_Stats)) then exit;
      GameTab(tab_Stats);
      if (GetCurrentTab <> tab_Stats) then exit;
      P := SkillToCoords(Skill);
      if (P.x < 1) then exit;
      MMouse(P.x, P.y + 5, 12, 4);
      if (not WaitFindColors(TPA1, 4305653, MIX1, MIY1, MIX2, MIY2, 1, 4000)) then exit; // Orange text color of XP boxes
      FindColorsTolerance(TPA2, 921102, MIX1, MIY1, MIX2, MIY2, 1); // black behind the orange text
      //15133931 is another useful color: the white bound of the hover box
      TPA1 := CombineTPA(TPA1, TPA2);
      B := GetTPABounds(TPA1);

      B := IntToBox(B.X1, B.Y1 + 17, B.X2, B.Y1 + 17 + 13); // get just the line that current xp is on
      FindColorsTolerance(TPA1, 4305653, B.X1, B.Y1, B.X2, B.Y2, 2); // TPA of that line's text
      ATPA := SplitTPAEx(TPA1, 15, 2);
      SortATPAFromFirstPointY(ATPA, Point(B.X2-B.X1+2/2,0));

      TPA1 := ATPA[0];
      ATPAt := SplitTPAEx(TPA1, 1, 10); // Split one into characters
      SortATPAFromFirstPointX(ATPAt, Point(0, 0));
      Result := StrToIntDef(GetNumbers(GetTextATPA(ATPAt, 4, 'SmallChars')), -1);
    end;

  2. #2
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Looks sound to me. One thing: What if the length of ATPA is 0 - if you didn't find any colours?



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  3. #3
    Join Date
    Jan 2011
    Posts
    121
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    That should be covered by the default value in StrToIntDef correct? Also these colors are all static, this shouldn't ever be a problem.

    I get your point though, I'm also going to expand it to be able to fetch values for the next level and the remaining xp to level so I'll add a failsafe I guess.

    E:
    Actually I've found a problem - GetTextATPA seems to quit if there's a lot of blank horizontal spacing?
    In this image GetTextATPA returns the whole line with numbers for the 2nd and 3rd rows but not the 4th:
    what I'm talking about

    E2:
    It was a stupid oversight on my part, I figured it out.
    Here's what I propose should be committed:
    Simba Code:
    {*******************************************************************************
    function GetXP(Skill: Variant; Which: String): Integer;
    By: Legoace
    Credit to: Nielsie95 for the original
    Description: Returns xp value for a skill depending on Which
      Options for Which are ['current', 'next', 'remaining']
      Returns -3 if super-fails
              -2 if skill is mem and this is F2P account
              -1 if text-reading sucked
    *******************************************************************************}

    function GetXPNew(Skill: Variant; Which: String): Integer;
    var
      TPA1, TPA2: TPointArray;
      ATPA, ATPAt: T2DPointArray;
      P: TPoint;
      B: TBox;
      YOffset, I: Integer;
      S: String;
    begin
      Result := -3;

      if(not(TabExists(tab_Stats)))then exit;
      GameTab(tab_Stats);
      if(GetCurrentTab <> tab_Stats)then exit;
      P := SkillToCoords(Skill);
      if(P.x < 1)then exit;
      MMouse(P.x, P.y + 5, 12, 4);
      Wait(100 + Random(50));

      FindColorsTolerance(TPA2, 921102, MIX1, MIY1, MIX2, MIY2, 1); // black behind the orange text
      FindColorsTolerance(TPA1, 4305653, MIX1, MIY1, MIX2, MIY2, 1); // Orange text color of XP boxes
      //15133931 is another useful color: the white bound of the hover box
      TPA1 := CombineTPA(TPA1, TPA2);
      B := GetTPABounds(TPA1);

      if((B.Y2 - B.Y1) > 20)then // F2P boxes for Mem skills won't be large enough
      begin
        case Which of
          'current': YOffset := 17;
          'next': YOffset := 31;
          'remaining': YOffset := 45;
        end;

        B := IntToBox(B.X1, B.Y1 + YOffset, B.X2, B.Y1 + YOffset + 13); // get just the line that current xp is on
        FindColorsTolerance(TPA1, 4305653, B.X1, B.Y1, B.X2, B.Y2, 2); // TPA of that line's text
        ATPA := SplitTPAEx(TPA1, 15, 2);
        SortATPAFromFirstPointY(ATPA, Point(B.X2-B.X1+2/2,0));

        if(length(ATPA) > 0)then
        begin
          for I := 0 to High(ATPA) do
          begin
            TPA1 := ATPA[I];
            ATPAt := SplitTPAEx(TPA1, 1, 10); // Split one into characters
            SortATPAFromFirstPointX(ATPAt, Point(0, 0));
            S := S + GetTextATPA(ATPAt, 4, 'SmallChars');
          end;
          Result := StrToIntDef(GetNumbers(S), -1);
        end;
      end else result := -2;
    end;

  4. #4
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    I'd split that function so scripts don't break because of the parameter addition. Change your function name to GetSpecificXP or something, then still use the GetXP(skill: variant) like what's in the include right now.

  5. #5
    Join Date
    Jan 2011
    Posts
    121
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    How about this?

    E: Added Nava's suggestions.

    Simba Code:
    {*******************************************************************************
    function GetXP(Skill: Variant): Integer;
    By: Legoace
    Credit to: Nielsie95 for the original
    Description: Returns current xp value for a skill
    *******************************************************************************}

    function GetXP(Skill: Variant): Integer;
    begin
      result := GetXPEx(Skill, 'current', True);
    end;

    {*******************************************************************************
    function GetXPEx(Skill: Variant; Which: String, MaintainTab: Boolean): Integer;
    By: Legoace
    Credit to: Nielsie95 for the original
    Description: Returns xp value for a skill depending on Which.
      Options for Which are ['current', 'next', 'remaining']
      If MaintainTab is true, returns to current tab after execution.
      Returns -3 if super-fails
              -2 if skill is mem and this is F2P account
              -1 if text-reading sucked
    *******************************************************************************}

    function GetXPNew(Skill: Variant; Which: String): Integer;
    var
      TPA1, TPA2: TPointArray;
      ATPA, ATPAt: T2DPointArray;
      P: TPoint;
      B: TBox;
      YOffset, I, T: Integer;
      S: String;
    begin
      Result := -3;
      T := GetCurrentTab;
      if(not(GameTab(tab_Stats)))then exit;
      P := SkillToCoords(Skill);
      if(P.x < 1)then exit;
      MMouse(P.x, P.y + 5, 12, 4);
      Wait(100 + Random(50));

      FindColorsTolerance(TPA2, 921102, MIX1, MIY1, MIX2, MIY2, 1); // black behind the orange text
      FindColorsTolerance(TPA1, 4305653, MIX1, MIY1, MIX2, MIY2, 1); // Orange text color of XP boxes
      //15133931 is another useful color: the white bound of the hover box
      TPA1 := CombineTPA(TPA1, TPA2);
      B := GetTPABounds(TPA1);

      if((B.Y2 - B.Y1) > 20)then // F2P boxes for Mem skills won't be large enough
      begin
        case Which of
          'current': YOffset := 17;
          'next': YOffset := 31;
          'remaining': YOffset := 45;
        end;

        B := IntToBox(B.X1, B.Y1 + YOffset, B.X2, B.Y1 + YOffset + 13); // get just the line that current xp is on
        FindColorsTolerance(TPA1, 4305653, B.X1, B.Y1, B.X2, B.Y2, 2); // TPA of that line's text
        ATPA := SplitTPAEx(TPA1, 15, 2);
        SortATPAFromFirstPointY(ATPA, Point(B.X2-B.X1+2/2,0));

        if(length(ATPA) > 0)then
        begin
          for I := 0 to High(ATPA) do
          begin
            TPA1 := ATPA[I];
            ATPAt := SplitTPAEx(TPA1, 1, 10); // Split one into characters
            SortATPAFromFirstPointX(ATPAt, Point(0, 0));
            S := S + GetTextATPA(ATPAt, 4, 'SmallChars');
          end;
          Result := StrToIntDef(GetNumbers(S), -1);
        end;
      end else result := -2;
      if(T)then GameTab(T);
    end;

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

    Default

    iirc, this:
    Simba Code:
    if(not(TabExists(tab_Stats)))then exit;
      GameTab(tab_Stats);
      if(GetCurrentTab <> tab_Stats)then exit;

    Can be replaced with:
    Simba Code:
    if (not GameTab(tab_stats)) then exit;

    Also, perhaps maintaining the old gametab isn't a bad idea?
    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

  7. #7
    Join Date
    Jan 2011
    Posts
    121
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks Nava, I'll condense those lines.

    I'm not sure if the old tab should be stored and returned to. I guess the main point of me writing this was so I could quickly get the xp for my F2P accounts now that they are off the highscores.

    I guess I'll add it as an option.

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
  •