PDA

View Full Version : [OSR] AeroLib Check if Prayer is active



Dan the man
09-20-2015, 07:44 AM
Hi all,

I was working on a NMZ script that requires prayer to be activated temporarily and I couldn't see any includes inside Aerolib that took care of this through the prayer tab so I thought I would have a crack at making one :)

Here is my snippet, let me know what you think and any improvements that I can make on it.

Cheers!


{*
PrayerActive
~~~~~~~~~~~~

.. code-block:: AeroLib

PrayerActive(PrayerName: String; Toggle: Boolean): Boolean;

Returns true if the specified prayer string is active and then turns it off if toggle is true.

Example:

if PrayerActive('Melee', True) then
WriteLn('Melee protection was on but we disabled it!');

*}

function PrayerActive(PrayerName: String; Toggle: Boolean): Boolean;
var
Color_PrayerActive: TColEx;
foundPnt: Tpoint;
PrayerTbox: Tbox;


begin
if GameTab(TAB_PRAYER) then
begin
case PrayerName of
//Assigns Tbox Co-ordinates based on prayer nominated
'Melee' : PrayerTbox := IntToBox(662, 325, 695, 358);
'Ranged' : PrayerTbox := IntToBox(625, 325, 658, 358);
'Magic' : PrayerTbox := IntToBox(588, 325, 621, 358);
'Rapid Heal': PrayerTbox := IntToBox(699, 251, 732, 284);
end;
// Creates the color and checks to see if its located within Tbox meaning prayer is active
Color_PrayerActive.create(7318465, 3, 0.02, 1.96);
if Color_PrayerActive.findIn(PrayerTbox,foundPnt) then
begin
WriteLn('Prayer: '+PrayerName+ ' is active.');
Result := True;
end else
begin
Result := False;
end;
//If Toggle is enabled, it will click the prayer icon it checked using a GaussMouseBox.
if Toggle then
begin
WriteLn('Toggling Prayer');
gaussMouseBox(PrayerTbox.X1, PrayerTbox.Y1, PrayerTbox.X2, PrayerTbox.Y2, MOUSE_LEFT);
end;
end;
end;





Edit: Decided to turn this into a little include :)


function GetPrayerBox(Name: Variant): Tbox;
begin
if VariantIsString(Name) then
begin
case Capitalize(LowerCase(Name)) of
'Thick Skin': Result := IntToBox(551, 214, 584, 247);
'Burst Of Strength': Result := IntToBox(588, 214, 621, 247);
'Clarity Of Thought': Result := IntToBox(625, 214, 658, 247);
'Sharp Eye': Result := IntToBox(662, 214, 695, 247);
'Mystic Will': Result := IntToBox(699, 214, 732, 247);
'Rock Skin': Result := IntToBox(551, 251, 584, 284);
'Superhuman Strength': Result := IntToBox(588, 251, 621, 284);
'Improved Reflexes': Result := IntToBox(625, 251, 658, 284);
'Rapid Restore': Result := IntToBox(662, 251, 695, 284);
'Rapid Heal': Result := IntToBox(699, 251, 732, 284);
'Protect Items': Result := IntToBox(551, 288, 584, 321);
'Hawk Eye': Result := IntToBox(588, 288, 621, 321);
'Mystic Lore': Result := IntToBox(625, 288, 658, 321);
'Steel Skin': Result := IntToBox(662, 288, 695, 321);
'Ultimate Strength': Result := IntToBox(699, 288, 732, 321);
'Incredible Reflexes': Result := IntToBox(551, 325, 584, 358);
'Protect From Magic': Result := IntToBox(588, 325, 621, 358);
'Protect From Missiles': Result := IntToBox(625, 325, 658, 358);
'Protect From Melee': Result := IntToBox(662, 325, 695, 358);
'Eagle Eye': Result := IntToBox(699, 325, 732, 358);
'Mystic Might': Result := IntToBox(551, 362, 584, 395);
'Retribution': Result := IntToBox(588, 362, 621, 395);
'Redemption': Result := IntToBox(625, 362, 658, 395);
'Smite': Result := IntToBox(662, 362, 695, 395);
'Chivalry': Result := IntToBox(699, 362, 732, 395);
'Piety': Result := IntToBox(551, 399, 584, 432);
end;
end;
end;


{*
ActivatePrayer
~~~~~~~~~~~~

.. code-block:: AeroLib

ActivatePrayer(PrayerName: string): Boolean;

Activates the PrayerName prayer if its not active.

Example:

if ActivatePrayer('Protect From Magic') then

*}
function ActivatePrayer(PrayerName: string): Boolean;
var
PBox: Tbox;
Color_PrayerActive: TColEx;
foundPnt: Tpoint;

begin
if GameTab(TAB_PRAYER) then
begin
PBox := GetPrayerBox(PrayerName);
Color_PrayerActive.create(7318465, 3, 0.02, 1.96);
if not Color_PrayerActive.findIn(PBox,foundPnt) then
begin
gaussMouseBox(PBox.X1, PBox.Y1, PBox.X2, PBox.Y2, MOUSE_LEFT);
WriteLn(+PrayerName+ ' activated.');
Result := True;
end else
begin
WriteLn(+PrayerName+ ' is already active!');
Result := False;
end;
end;
end;

{*
DeactivatePrayer
~~~~~~~~~~~~

.. code-block:: AeroLib

DeactivatePrayer(PrayerName: string): Boolean;

Deactivates the PrayerName prayer if its not active.

Example:

if DeactivatePrayer('Protect From Magic') then

*}
function DeactivatePrayer(PrayerName: string): Boolean;
var
PBox: Tbox;
Color_PrayerActive: TColEx;
foundPnt: Tpoint;

begin
if GameTab(TAB_PRAYER) then
begin
PBox := GetPrayerBox(PrayerName);
Color_PrayerActive.create(7318465, 3, 0.02, 1.96);
if Color_PrayerActive.findIn(PBox,foundPnt) then
begin
gaussMouseBox(PBox.X1, PBox.Y1, PBox.X2, PBox.Y2, MOUSE_LEFT);
WriteLn(+PrayerName+ ' de-activated.');
Result := True;
end else
begin
WriteLn(+PrayerName+ ' is not active!');
Result := False;
end;
end;
end;




{*
PrayerActive
~~~~~~~~~~~~

.. code-block:: AeroLib

PrayerActive(PrayerName: String; Toggle: Boolean): Boolean;

Returns true if the specified prayer string is active and then turns it off if toggle is true.

Example:

if PrayerActive('Protect From Melee', True) then
WriteLn('Melee protection was on but we disabled it!');

*}

function PrayerActive(PrayerName: String; Toggle: Boolean): Boolean;
var
Color_PrayerActive: TColEx;
foundPnt: Tpoint;
PrayerTbox: Tbox;


begin
if GameTab(TAB_PRAYER) then
begin
PrayerTbox := GetPrayerBox(PrayerName);

// Creates the color and checks to see if its located within Tbox meaning prayer is active
Color_PrayerActive.create(7318465, 3, 0.02, 1.96);
if Color_PrayerActive.findIn(PrayerTbox,foundPnt) then
begin
WriteLn('Prayer: '+PrayerName+ ' is active.');
Result := True;
end else
Result := False;
//If Toggle is enabled, it will click the prayer icon it checked using a GaussMouseBox.
if Toggle then
begin
Wait(randomRange(200,400));
WriteLn('Toggling Prayer');
gaussMouseBox(PrayerTbox.X1, PrayerTbox.Y1, PrayerTbox.X2, PrayerTbox.Y2, MOUSE_LEFT);
end;
end;
end;

Fitta
09-22-2015, 12:48 AM
Flight; take a look :)

Dan the man
09-22-2015, 11:33 AM
Decided to turn it into an include, see OP :D