Jump to content
lazarbeam

[2007] Special Attack

Recommended Posts

Returns the estimated percent full of the special attack bar: Retuns -1 if it can't find the special attack bar.

This was fairly accurate with my tests. May return 11% for 10% or 21% for 20%, but 30%-100% has been dead on, as well as 0% and -1.

If there's problems, you may need to adjust the tolerance (it's so high to address a problem at 0%)

Function GetSpecialAttackLevel:Integer;
var x,y:Integer;
Begin
 If(RS07_LoggedIn)Then
   Begin
     If(Not(RS07_GameTabOpen(0)))Then RS07_OpenGameTab(0);
     If(FindColorTol(x,y,29,572,417,713,419,100))Then
       Begin
         Result:= Round(100-100*(713-x)/141);  
       end else 
         Begin
           If(Not(FindColorTol(x,y,4361025,572,417,713,419,50)))Then
             Begin
               Result:= -1;
             end else Result:=100;
         end;
   end;
end;

Edited by lazarbeam
Link to comment
Share on other sites

Nice work, looking good!

 

If you want to tweak the logical part a bit, then you could change:

 

If(Not(RS07_GameTabOpen(0)))Then RS07_OpenGameTab(0); => if RS07_OpenGameTab(0) then

 

Because RS07_OpenGameTab() is based on RS07_OpenGameTabEx() which uses RS07_GameTabOpen() in it.

 

Source (Includes\MSSL\Library\Gaming\RuneScape_2007\Core\Level-2\GameTab.scar) for RS07_OpenGameTabEx():

 

function RS07_OpenGameTabEx(i, interval, maxTime: Integer): Boolean;
{==============================================================================]   
 Created: February 25th, 2013.
 Contributors: Janilabo
 Explanation: Opens game tab with ID (i). Tries to open game tab with interval.
              Keeps going till maxTime has reached or game tab activated.
              Returns true with success.                   
[==============================================================================}
var
 tm, tm2: Integer;
 p: TPoint;
begin
 if RS07_LoggedIn then
 begin
   if (IsTextAtEx(184, 34, 'The Bank', 0, RS07_MainFont, False, False, 0, 0, 2070783) or IsTextAtEx(332, 288, 'Withdraw', 0, RS07_SmallFont, False, False, 0, 0, 2070783)) then
   begin
     p := Point((428 + Random(20)), (39 + Random(4)));
     tm := GetSystemTime;
     repeat    
       if (not RS07_LoggedIn or ((GetSystemTime - tm) > 5000)) then
         Exit;
       if ((GetSystemTime - tm2) > (150 + Random(150))) then
       begin
         RS07_ClickMouse(p.X, p.Y, mbLeft);
         tm2 := GetSystemTime;
       end; 
     until not (IsTextAtEx(184, 34, 'The Bank', 0, RS07_MainFont, False, False, 0, 0, 2070783) or IsTextAtEx(332, 288, 'Withdraw', 0, RS07_SmallFont, False, False, 0, 0, 2070783));                                          
   end;
   p := BoxCenter(RS07_GameTabs[i].area); 
   MSSL_OffsetPoint(p, RandomRange(-4, 5), RandomRange(-4, 5));
   tm := GetSystemTime;
   repeat       
     if not RS07_LoggedIn then
       Exit; 
     Result := RS07_GameTabOpen(i); // <= this line over here
     if not Result then
     begin   
       if ((GetSystemTime - tm2) > interval) then
       begin 
         if MouseInBox(RS07_GameTabs[i].area) then
           RS07_Click(mbLeft)
         else
           RS07_ClickMouse(p.X, p.Y, mbLeft);
         tm2 := GetSystemTime;  
       end;   
       MSSL_Wait(0);
     end;
   until (Result or ((GetSystemTime - tm) > maxTime));
 end;
end;

 

So as you see: "Result := RS07_GameTabOpen(i);"

 

Infact, you could actually even remove the RS07_LoggedIn from this function, because that is also checked with RS07_OpenGameTabEx(), meaning RS07_OpenGameTab() returns false if you aren't logged in. :P

 

I would do something this:

 

function GetSpecialAttackLevel: Integer;
var
 x, y: Integer;
begin     
 Result := -1;
 if RS07_OpenGameTab(0) then
 case FindColorTol(x, y, 29, 572, 417, 713, 419, 100) of
   True: Result := Round(100 - (100 * (713 - x) / 141));
   False:         
   if FindColorTol(x, y, 4361025, 572, 417, 713, 419, 50) then
     Result := 100;                                           
 end;
end;

 

But for some reason, the function returns 0 if special attack bar isn't there.. Should it be like that? I mean is it better to return it as 0 if its not even found? I think this result might be because the tolerance is just too high for the first FindColorTol() [100]..

 

Nevertheless, nice job and keep em coming lazar!

Link to comment
Share on other sites

Thanks for the tips! I haven't done much scripting since 2.03 and am trying to get back into the swing of things and learn all of the new functions.

 

And the return of -1 is a check if a weapon compatible with special attack is being wielded. In the case that I wrote this script, I am switching to Excalibur to use the special attack. So a return of -1 doubles as a check for that.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...