SRL Archive - SRL Snippets

getHP;


Turpinator

2013-12-10 02:34:52

Simple and effective.

HP
function TRSActionBar.getHPPercent: integer;
var
xx, yy: Integer;
begin
xx := self.X1 + 46;
yy := self.Y1 + 23;
for result := 100 downto 1 do
if getColor(xx + result, yy) <> 2894115 then
break;
end;

ADRLN
function TRSActionBar.getAdrenalinePercent: integer;
var
xx, yy: Integer;
begin
xx := self.X1 + 185;
yy := self.Y1 + 23;
for result := 100 downto 1 do
if getColor(xx + result, yy) <> 2894115 then
break;
end;

Prayer
function TRSActionBar.getPrayerPercent: integer;
var
xx, yy: Integer;
begin
xx := self.X1 + 324;
yy := self.Y1 + 23;
for result := 100 downto 1 do
if getColor(xx + result, yy) <> 2894115 then
break;
end;

Summoning
function TRSActionBar.getSummoningPercent: integer;
var
xx, yy: Integer;
begin
xx := self.X1 + 463;
yy := self.Y1 + 23;
for result := 100 downto 1 do
if getColor(xx + result, yy) <> 2894115 then
break;
end;

Grabs 0,0 of action bar, uses static coords of the HP bar to check for the background color. Once it is not found, it exits and returns the number of pixels left (hp bar is 100 pixels long, so that nice. ;))

made for @The Mayor because @Sjoe's was slower and processed 300-400 pixels, and this processes 100 at max, with the actual number being 100-hp percent.

edit: added the others and switched it to an object func. so usage is still as simple as
actionBar.getHPPercent

The Mayor

2013-12-10 04:26:12

Works well :)



(1075/1473) = 72.98%

Olly

2013-12-11 22:14:37

Added to SRL-6.

Turpinator

2013-12-12 20:50:32

From: Olly
Added to SRL-6.


Olly – Change all the 100 downto 1's to 100 downto 0. if it goes down to 0, it has the possibly of resulting in -1 if for some reason something weird happens.

note: yaay first func(s) in SRL.

Coh3n

2013-12-12 23:46:02

Nice work. I think they should be combined into one function though and take a parameter. Avoids some repeated code. Or at the very least use a constant for the background color (easier to update).

Turpinator

2013-12-13 03:45:44

From: Coh3n
Nice work. I think they should be combined into one function though and take a parameter. Avoids some repeated code. Or at the very least use a constant for the background color (easier to update).


Drunkenly updated/wrote this…
const
__AB_PERCENT_BACKGROUND = 2894115;
AB_HP = 1;
AB_ADRNL = 2;
AB_PRAYER = 3;
AB_SUMMONING = 4;

function TRSActionBar.getPercent(which: Integer): Integer;
var
xx, yy: Integer;
begin
If not inRange(which, AB_HP, AB_SUMMONING) then
begin
print('TRSActionBar.getPercent(): Invalid option"'+toStr(which)+'"', TDebug.ERROR);
exit(-1);
end;
xx := self.X1 + 46 + 139 * (which - 1);
yy := self.Y1 + 23;
for result := 100 downto 1 do
if getColor(xx + result, yy) <> __AB_PERCENT_BACKGROUND then
break;
end;

function TRSActionBar.getPercent: array[0..3] of Integer; overload;
var
xx, yy, i: Integer;
begin
for i := 0 to 3 do
result[i] := self.getPercent(i + 1);
end;

note comments for suggestions/'idkwhatSRL6standardsandprintstuffare'
as well as a name is needed to replace GENERICNAME that describes all of the action bar's 'things you can get percents from'
also, idk correct overload notation/stuff.
@Olly


EDIT: Updated, now it actually compiles.

Coh3n

2013-12-13 12:51:47

Why not just TRSActionBar.getPercent(which: integer);? No need for a GENERICNAME in between. I'd just call the constants AB_PRAYER, AB_SUMMONING, etc., and the background constant should be internal (__AB_PERCENT_BACKGROUND).

I made this comment on Olly's commit, but we'll make the getPercent function internal and call it in the functions that are currently in SRL (for compatibility purposes). Your overload syntax is almost right. You need a ';' after Integer, not a ':'. Also, the syntax for debugging in this case would be print('TRSActionBar.getPercent(): Invalid option "'+toStr(which)+'"', TDebug.ERROR);

Nice work. :)

Olly

2013-12-16 13:58:58

done. https://github.com/SRL/SRL-6/commit/91be814ff078ae37e0f02f3fabf0b1b64b5c2cb5