Results 1 to 6 of 6

Thread: HpPercent broken?

  1. #1
    Join Date
    Nov 2011
    Posts
    335
    Mentioned
    0 Post(s)
    Quoted
    68 Post(s)

    Default HpPercent broken?

    Trying to make my script check for hp while its fighting but it keeps stopping with an error in GameTab (right about where the HpPercent function is located).

    This is the code that causes the script to stop:
    Simba Code:
    While (SRL_InFight) do
            begin
              repeat
                If (HpPercent<50) then
                  begin
                    Writeln('hp less than 50%, stopping');
                    TerminateScript;
                  end else
                Wait(RandomRange(100, 200));
              until TimeFromMark(Counter)>10000
            end;

    and this is the error:
    Simba Code:
    Error: Out Of Range at line 1631
    The following DTMs were not freed: [SRL - Lamp bitmap, 1]
    The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap, SRL - NavBar Bitmap, SRL - Options Bitmap, 5]

    any advice?
    Last edited by l6bustank; 01-30-2013 at 10:57 AM.

  2. #2
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    I was able to replicate the problem, I didn't have any Player Declarations.

    To fix this, add this function:

    Simba Code:
    Procedure DeclarePlayers;
    Begin
      HowManyPlayers := 1;
      NumberOfPlayers(HowManyPlayers);
      CurrentPlayer := 0;
      With Players[0] Do
      Begin
        Name        := '';
        Pass        := '';
        Active      := True;
      End;
    End;

    Then after you have
    Simba Code:
    SetupSRL;

    Add:
    Simba Code:
    DeclarePlayers;

    My test script (Returned Out Of Range)
    Simba Code:
    program new;
    {$I SRL/SRL.Simba}

    begin
    SetupSRL;
    writeln(HPPercent);
    end.

    Script that didn't error and returned a value:

    Simba Code:
    program new;
     {$I SRL/SRL.Simba}

     Procedure DeclarePlayers;
    Begin
      HowManyPlayers := 1;
      NumberOfPlayers(HowManyPlayers);
      CurrentPlayer := 0;
      With Players[0] Do
      Begin
        Name        := '';
        Pass        := '';
        Active      := True;
      End;
    End;


    begin
    SetupSRL;
    DeclarePlayers;
    writeln(HPPercent);
    end.

    I also noticed that HpPercent returned 400 (400%) because of the EoC Update

    HP Level: 99
    HP orb: 3960

    I know @Ashaman88 has a solution for this in his LRC miner. I have mentioned him in this thread in hope he will read this and also help you with this problem

    E: I have just opened a bug report (http://villavu.com/forum/project.php?issueid=34) Hope this issue will get fixed in the next SRL update so you wont need to add a custom function for this.
    Last edited by Justin; 01-30-2013 at 11:18 AM.

  3. #3
    Join Date
    Nov 2011
    Posts
    335
    Mentioned
    0 Post(s)
    Quoted
    68 Post(s)

    Default

    lmao, I was missing DeclarePlayers from my main loop . Thanks Justin

  4. #4
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Quote Originally Posted by l6bustank View Post
    lmao, I was missing DeclarePlayers from my main loop . Thanks Justin
    No worries. Also no need to have DeclarePlayers in your main loop as it only needs to be called once. Let me know if you don't understand what I mean

  5. #5
    Join Date
    Mar 2006
    Location
    Belgium
    Posts
    3,564
    Mentioned
    111 Post(s)
    Quoted
    1475 Post(s)

    Default

    Quote Originally Posted by l6bustank View Post
    lmao, I was missing DeclarePlayers from my main loop . Thanks Justin
    If it's buggy try something like:
    Simba Code:
    Hphealth := GetMMLevels('hp')
    HalfHPhealth := HPhealth / 2
    if GetMMlevels('hp') =< HalfHPhealth then ..
    Just a thought , I'm not an advanced scripter

    Creds to DannyRS for this wonderful sig!

  6. #6
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

    Default

    Callin me out... I see how it is.


    Simba Code:
    Function HPLevel: Integer;                                        
    Var
      ColourString: String;
    Begin                                  
      Result:= GetMMLevels('HP', ColourString);
    End;

    Simba Code:
    Function GetMaxHP: Extended;
    Var
      Text: String;
      B, BigBox: TBox;
      TPA : TPointArray;
      ATPA : T2DPointArray;
      I,cts: Integer;
      BoxColors: TIntegerArray;
    Begin
      GameTab(Tab_Combat);
      HumanMouseBox(650,394-50,682,401-50);
      Wait(RandomRange(500,700));

      B := IntToBox(594, 365-50, 694, 394-50);
      cts := GetColorToleranceSpeed;
      ColorToleranceSpeed(1);
      //            Black
      BoxColors := [1774603];
      SetLength(ATPA, Length(BoxColors));
      for i := 0 to High(BoxColors) do
        FindColorsTolerance(ATPA[i], BoxColors[i], B.X1, B.Y1, B.X2, B.Y2, 0);
      TPA := MergeATPA(ATPA);
      If Length(TPA) < 10 Then
      begin
        Writeln('Not enough colors');
        ColorToleranceSpeed(cts);
        Exit;
      end;

      ATPA := SplitTPA(TPA, 4);
      For i := 0 to High(ATPA) do
      begin
        B := GetTPABounds(ATPA[i]);
        if ((B.x2-B.x1) > 4) and ((B.y2-B.y1) > 4) then
          Break
        else
          B := IntToBox(0, 0, 0, 0);
      end;

      If (B.x2 = 0) then
      begin
        ColorToleranceSpeed(cts);
        Exit;
      end;

      BigBox := B;

      Text:= GetTextAtExWrap(BigBox.X1, BigBox.Y1, BigBox.X2, BigBox.Y2, 0, 5, 2, 3111603, 10, 'UpChars');
      Text:= Copy(Text, 0, High(Text)-1);
      If (StrToIntDef(Text, 0)=100) Then
        Result:=HPLevel Else
        Result:= (HPLevel*100)/(StrToIntDef(Text, 0));
    End;


    Have a variable called maxhp. Do maxhp:=getmaxhp; once at the setup of your script, then do checks for your hp lvl.


    Simba Code:
    If ((HPLevel < (HP*0.80))) Then
      Begin
        If HPLevel=-1 Then
          Exit;

    That 80 you can replace with whatevers

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
  •