PDA

View Full Version : OGL Progress Reports



Ross
05-03-2015, 03:46 AM
Hi, just sharing what I use for progress reports. You can put this into any OGL script and it tracks XP extremely well, plus has the benefits of being really pretty.


program progressReport;

var
startXp: integer;
xpIcon: glTextureArray;
xpBox: TBox;

procedure setupScript;
begin
xpIcon:= ogl.getTextures({put the skill texture ID here});
if (not xpIcon.isEmpty()) then
begin
xpBox:=intToBox(xpIcon[0].bounds.x1 - 150, xpIcon[0].bounds.y1, xpIcon[0].bounds.x2, xpIcon[0].bounds.y2);
startXp := explode('+', ogl.getChars(xpBox).toString())[0].parseInt();
end
else
begin
writeln('Enable your XP counter!');
terminateScript;
end;
end;

procedure progressReport();
var
currentXp: uint32;
paintXp, xpHour :integer;
begin
currentXp := explode('+', ogl.getChars(xpBox).toString())[0].parseInt();
paintXp := currentXp - startXp;
xpHour := round(paintXp * (3600.0 / (getTimeRunning / 1000.0)));
smart.__graphics.clear;
smart.__graphics.DrawText(toStr(paintXp) + ' xp gained', 'smallChars', point(11, 11), 1);
smart.__graphics.DrawText(toStr(paintXp) + ' xp gained', 'smallChars', point(10, 10), clWhite);
smart.__graphics.DrawText(toStr(xpHour) + ' xp/hr', 'smallChars', point(11, 29), 1);
smart.__graphics.DrawText(toStr(xpHour) + ' xp/hr', 'smallChars', point(10, 28), clWhite);
end;

IDs (thank you Justin):

Attack: 16918
Strength: 39319
Defence: 41952
Range: 20999
Magic: 51211
Hitpoints: 38262
Thieving: 25506
Crafting: 33559
Fletching: 19315
Mining: 16653
Smithing: 31773
Fishing: 54626
Runecrafting: 33877
Slayer: 54733
Farming: 34536
Construction: 54189
Hunter: 30306
Summoning: 37582
Prayer: 23912
Agility: 29580
Herblore: 54427
Cooking: 47376
Firemaking: 46008
Woodcutting: 44243
Dungeoneering: 58390
Divination: 22933
All Combat: 31110
Overall: 48705

Justin
05-03-2015, 03:51 AM
You should add a length check in your procedure setupScript; procedure

Ross
05-03-2015, 03:55 AM
You should add a length check in your procedure setupScript; procedure

Good call, I usually just let the access violations speak for themselves in situations like that :p
I'll add one.

The Mayor
05-03-2015, 07:29 AM
I would make your setup procedure a function that just returns current XP. Or better yet, there should be something like a getXP(skill: int): integer; function added to the include.

currentXP := getXP(123456);

Justin
05-03-2015, 08:00 AM
Attack: 16918
Strength: 39319
Defence: 41952
Range: 20999
Magic: 51211
Hitpoints: 38262
Thieving: 25506
Crafting: 33559
Fletching: 19315
Mining: 16653
Smithing: 31773
Fishing: 54626
Runecrafting: 33877
Slayer: 64733
Farming: 34536
Construction: 54189
Hunter: 30306
Summoning: 37582
Prayer: 23912
Agility: 29580
Herblore: 54427
Cooking: 47376
Firemaking: 46008
Woodcutting: 44243
Dungeoneering: 58390
Divination: 22933
All Combat: 31110
Overall: 48705

Ross
05-03-2015, 01:15 PM
Attack: 16918
Strength: 39319
Defence: 41952
Range: 20999
Magic: 51211
Hitpoints: 38262
Thieving: 25506
Crafting: 33559
Fletching: 19315
Mining: 16653
Smithing: 31773
Fishing: 54626
Runecrafting: 33877
Slayer: 64733
Farming: 34536
Construction: 54189
Hunter: 30306
Summoning: 37582
Prayer: 23912
Agility: 29580
Herblore: 54427
Cooking: 47376
Firemaking: 46008
Woodcutting: 44243
Dungeoneering: 58390
Divination: 22933
All Combat: 31110
Overall: 48705

Thank you, will edit top post. Can you move this to another section in public that's appropriate? I wasn't sure if SRL snippets was a good place for it.

Justin
05-03-2015, 01:23 PM
Thank you, will edit top post. Can you move this to another section in public that's appropriate? I wasn't sure if SRL snippets was a good place for it.

No problem.

Thread moved :)

Obscurity
05-04-2015, 07:42 AM
Justin, your slayer texture is incorrect. See below.

A quick note - those textures share with the skills tab and sometimes monster weakness. The ranged weakness icon is the same as the ranged XP, for example. However, the XP tracker is drawn last and therefore will appear last in the array. So, you're better off using:
xpIcon[high(xpIcon)].bounds.x1

Edit: However, I got bored...
function getSkillTexture(funcString:string):int32;
begin
case funcString:=lowercase(funcString) of
'agility':result:=29580;
'attack':result:=16918;
'combat':result:=31110;
'constitution','hitpoints':result:=38262;
'construction':result:=54189;
'cooking':result:=47376;
'crafting':result:=33559;
'defence':result:=41952;
'divination':result:=22933;
'dungeoneering':result:=58390;
'farming':result:=34536;
'firemaking':result:=46008;
'fishing':result:=54626;
'fletching':result:=19315;
'herblore':result:=54427;
'hunter':result:=30306;
'magic':result:=51211;
'mining':result:=16653;
'overall':result:=48705;
'prayer':result:=23912;
'ranged':result:=20999;
'runecrafting':result:=33877;
'slayer':result:=54733;
'strength':result:=39319;
'smithing':result:=31773;
'summoning':result:=37582;
'thieving':result:=25506;
'woodcutting':result:=44243;
end;
end;


function getXPTracker(funcString:string):int32;
var
funcBounds:tBox;
funcID:int32;
funcPointer:pointer;
funcPointerIndex,
funcPointerSize:uInt32=0;
funcText:string;
begin
if funcID:=getSkillTexture(funcString) then
begin
{
Because we know that the skill icon we're looking for is one of the
last drawn textures, we set the pointer to the end and work backward
to save time.
}
funcPointer:=glTextures(funcPointerSize)+(36*(func PointerSize-1));
if funcPointer<>nil then
begin
{
Again, because we know that the texture we're looking for will
appear very close to the end, it should be safe to only need to
search one fifth of the textures.
}
for funcPointerIndex to funcPointerSize div 5 do
begin
{
funcPointer^ contains the ID of the current texture. Because
glTextures are 36 bytes, (funcPointer-36)^ contains the ID of
the previous texture.

The 0+ tells it ahead of time that we're dealing with an
integer. Without it, we'd get an access violation.

(funcPointer+28)^ and (funcPointer+20)^ contain the X2 and X1
of the current texture.
}

if (funcPointer^=funcID) and ((0+(funcPointer+28)^-(funcPointer+20)^=25)) then
begin
{
(funcPointer+20)^, (funcPointer+24)^, (funcPointer+28)^,
and (funcPointer+32)^ contain the bounds of the current
texture.
}
funcBounds:=[0+(funcPointer+20)^-200,(funcPointer+24)^,(funcPointer+28)^,(funcPoint er+32)^];
break;
end;
{
Because glTextures are 36 bytes, and we're working backward,
we subtract 36 from the current pointer to reach the previous
one.
}
funcPointer:=funcPointer-36;
end;
{
If funcPointerIndex were to be greater then one fifth of the
funcPointerSize, odds are we didn't find the texture we were
looking for.
}
if funcPointerIndex<=funcPointerSize div 5 then
begin
{
Again, because we know that the XP tracker is one of the last
drawn interfaces, we can start at the end of the pointer and
work backward to save time.
}
funcPointer:=glFonts(funcPointerSize)+(48*(funcPoi nterSize-1));
if funcPointer<>nil then
begin
{
See two notes below for why we should only need to search
half of the chars.
}
for funcPointerIndex:=0 to funcPointerSize div 2 do
begin
{
(funcPointer+8)^ and (funcPointer+12)^ contain the X
and Y of the current texture.
}
if pointInBox([(funcPointer+8)^,(funcPointer+12)^],funcBounds) then
begin
funcText:=char((funcPointer+16)^)+funcText;
end
{
If we found text within the area, but the next char
isn't in the desired bounds, we've no reason to
proceed.
}
else if (funcText<>'') and (funcText[1]<>'+') then
begin
result:=explode('+',funcText)[0].parseInt();
break;
end;
{
Although glChars are 48 bytes, we know that the text
drawn by the XP tracker has a shadow, and we can
therefore skip every other char.
}
funcPointer:=funcPointer-96;
end;
end;
end;
end;
end;
exit(result);
end;

writeLN(getXPTracker('slayer'));

I might just add something like this into ogLib, if you don't mind? Not the progress report, but getting the XP tracker.

Ross
05-04-2015, 12:25 PM
Absolutely, go for it! Awesome work :)