SRL Archive - SRL Archives

Updated SkillCoords and SkillToCoords


Coh3n

2010-04-12 15:21:44

I've tested both, and they work, but I may have missed something, so testing is appreciated. You'll need to update your skill constants.


const
Skill_Attack = 1;
Skill_Strength = 2;
Skill_Defense = 3;
Skill_Range = 4;
Skill_Prayer = 5;
Skill_Mage = 6;
Skill_RuneCrafting = 7;
Skill_HP = 8;
Skill_Agility = 9;
Skill_Dungeoneering = 10;
Skill_Herblore = 11;
Skill_Thieving = 12;
Skill_Crafting = 13;
Skill_Fletching = 14;
Skill_Slayer = 15;
Skill_Mining = 16;
Skill_Smithing = 17;
Skill_Fishing = 18;
Skill_Cooking = 19;
Skill_FireMaking = 20;
Skill_WoodCutting = 21;
Skill_Farming = 22;
Skill_Construction = 23;
Skill_Hunter = 24;
Skill_Summoning = 25;

{*******************************************************************************
function SkillCoords(Row, Column: Integer): TPoint;
By: Naum & Coh3n
Description: Returns Coords of Skill's Row and Column (Used for GetSkill functions)
*******************************************************************************}
function SkillCoords(Row, Column : ShortInt): TPoint;
begin
if (((Column = 2) or (Column = 3)) and (Row = 9)) then
begin
srl_Warn('SkillCoords', 'Invalid skill choice ', warn_AllVersions);
Exit;
end;

Result := Point(577 + (60 * (Column - 1)), 223 + (28 * (Row - 1)));
end;

{*******************************************************************************
function SkillToCoords(ScrollDownIfNeeded: Boolean; Skill: Variant): TPoint;
By: Masquerader, Cheesehunk, Raymond, Wizzup?, ZephyrsFury, Timer & Coh3n
Description: Turns skill string into tpoint.
If Scroll returns true then you must scroll down.
*******************************************************************************}
function SkillToCoordsEx(Skill: Variant): TPoint;
var
SkillArr: TStringArray;
CX, CY, Col, skNo: Integer;
SkillS: string;
begin
if (not LoggedIn) then exit;

if (VarType(Skill) = varInteger) then
SkillS := IntToStr(Skill)
else
SkillS := Lowercase(Skill);

case Lowercase(SkillS) of
'hp', 'constitution': SkillS := 'hitpoints';
'ranged': SkillS := 'range';
'hunter': SkillS := 'hunting';
end;

SkillArr := ['attack', 'strength', 'defence', 'range', 'prayer', 'magic',
'runecrafting', 'hitpoints', 'agility', 'dungeoneering', 'herblore', 'thieving', 'crafting',
'fletching', 'slayer', 'mining', 'smithing', 'fishing', 'cooking',
'firemaking', 'woodcutting', 'farming', 'construction', 'hunting', 'summoning'];

if (GetNumbers(SkillS) = SkillS) and (InRange(StrToIntDef(GetNumbers(SkillS), 0), 1, Length(SkillArr))) then
skNo := StrToInt(SkillS) - 1
else
if (not InStrArrEx(SkillS, SkillArr, skNo)) then
begin
srl_Warn('SkillToCoords', 'Invalid Skill Name/Number: ''' + string(Skill) + '''', warn_AllVersions);
Exit;
end;

Writeln(IntToStr(skNo));
if (InRange(skNo + 1, 1, 25)) then
begin
CX := skNo div 9 + 1;
CY := skNo mod 9 + 1;
end;

Result := SkillCoords(CY, CX);
end;

mastaraymond

2010-04-12 15:22:41

I already committed something =)

Coh3n

2010-04-12 15:23:27

From: mastaraymond
I already committed something =)

Bah, probably should have checked. :p

E: Just tested yours. You may want to have it add a little more to each row as the coords are at the very top of each skill. Also, adding the srl_Warn for the non-skill areas may not be a bad idea.

mastaraymond

2010-04-12 15:38:55

From: Coh3n
Bah, probably should have checked. :p

E: Just tested yours. You may want to have it add a little more to each row as the coords are at the very top of each skill. Also, adding the srl_Warn for the non-skill areas may not be a bad idea.

I looked up where the 'old' starting point was, and it was a little bit left from the attack-level (the upper one)..

E: Try now :)

Coh3n

2010-04-12 15:52:28

From: mastaraymond
I looked up where the 'old' starting point was, and it was a little bit left from the attack-level (the upper one)..

E: Try now :)

Still the same. It's at the top for every skill. It's not really a big deal because it still works, I was just pointing it out. :p


Naum

2010-04-12 16:02:40

program New;
{.Include SRL/SRL.Scar}
{.Include SRL/SRL/Misc/Debug.Scar}
{.Include SRL/SRL/Misc/Users.Scar}

Var X, Y, I : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
TP : TPoint;
TB : TBox;

Function SkillCoords2(Row, Column : ShortInt): TPoint;
Begin
Result := Point(570 + (60 * (Column - 1)) + Column * 2,
211 + (27 * (Row - 1)) + Round(Row Div 2 * 1.5));
End;

function SkillToCoords2(Skill: Variant) : TPoint;
var
SkillArr: TStringArray;
CX, CY, skNo: Integer;
SkillS: string;

begin
if (not LoggedIn) then exit;

if (VarType(Skill) = varInteger) then
SkillS := IntToStr(Skill)
else
SkillS := Lowercase(Skill);

case Lowercase(SkillS) of
'hp', 'constitution': SkillS := 'hitpoints';
'ranged': SkillS := 'range';
'hunter': SkillS := 'hunting';
end;

SkillArr := ['attack', 'strength', 'defence', 'range', 'prayer', 'magic',
'runecrafting', 'construction', 'dungeoneering', 'hitpoints',
'agility', 'herblore', 'thieving', 'crafting', 'fletching', 'slayer',
'hunting', '', 'mining', 'smithing', 'fishing', 'cooking',
'firemaking', 'woodcutting', 'farming', 'summoning'];

if (GetNumbers(SkillS) = SkillS) and (InRange(StrToIntDef(GetNumbers(SkillS), 0), 1, Length(SkillArr))) then
skNo := StrToInt(SkillS) - 1
else
if (not InStrArrEx(SkillS, SkillArr, skNo)) then
begin
srl_Warn('SkillToCoords', 'Invalid Skill Name/Number: ''' + string(Skill) + '''', warn_AllVersions);
Exit;
end;
If skNo = 18 Then Inc(SkNo); //empty space

if (InRange(skNo + 1, 1, 27)) then
begin
CX := skNo div 9 + 1;
CY := skNo mod 9 + 1;
Disguise(SkillArr[SkNo]);
end;

Result := SkillCoords2(CY, CX);

GameTab(tab_Stats);
end;

function GetSkillInfo2(Skill: Variant; Amount : Boolean): Integer;
var
TP: TPoint;
Box : TBox;
TPA : TPointArray;
Cts : Integer;

begin
Result := -1;
GameTab(tab_Stats);
TP := SkillToCoords2(Skill);
if (not(Amount)) then
TP := Point(TP.x + 7, TP.y + 15);
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(0);
if not FindColors(TPA, 65535, TP.x - 5, TP.y - 4, TP.x + 29, TP.y + 14) then
exit;
DebugTPA(TPA, '');
Box := GetTPABounds(TPA);
Result := StrToIntDef(GetNumbers(GetTextAtEx(Box.x1 - 2, Box.y1 - 1, 140,
StatChars, False, True, 0, 3, 65535, 3, True, tr_Digits)), -1);
ColorToleranceSpeed(CTS);
end;

function GetSkillLevel2(Skill: Variant): Integer;
begin
Result := GetSkillInfo2(Skill, False);
end;


Begin
SetupSRL;
SRLPlayerForm(False, [], [], [], []);
For I := 1 To 25 Do
Begin
{ TP := SkillToCoords2(I);
MMouse(TP.x, TP.y, 0, 0); }
WriteLn(GetSkillLevel2(I));
wait(1200);
End;
End.

This one works in scar, but only cannot get 4 skills due to the ocr failing.
In simba it works 100% perfect.

(I've attached it with the test script and stuff, I'd advise you to use it with strings, not integers)

Timer

2010-04-12 16:09:40

From: Naum
program New;
{.Include SRL/SRL.Scar}
{.Include SRL/SRL/Misc/Debug.Scar}
{.Include SRL/SRL/Misc/Users.Scar}

Var X, Y, I : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
TP : TPoint;
TB : TBox;

Function SkillCoords2(Row, Column : ShortInt): TPoint;
Begin
Result := Point(570 + (60 * (Column - 1)) + Column * 2,
211 + (27 * (Row - 1)) + Round(Row Div 2 * 1.5));
End;

function SkillToCoords2(Skill: Variant) : TPoint;
var
SkillArr: TStringArray;
CX, CY, skNo: Integer;
SkillS: string;

begin
if (not LoggedIn) then exit;

if (VarType(Skill) = varInteger) then
SkillS := IntToStr(Skill)
else
SkillS := Lowercase(Skill);

case Lowercase(SkillS) of
'hp', 'constitution': SkillS := 'hitpoints';
'ranged': SkillS := 'range';
'hunter': SkillS := 'hunting';
end;

SkillArr := ['attack', 'strength', 'defence', 'range', 'prayer', 'magic',
'runecrafting', 'construction', 'dungeoneering', 'hitpoints',
'agility', 'herblore', 'thieving', 'crafting', 'fletching', 'slayer',
'hunting', '', 'mining', 'smithing', 'fishing', 'cooking',
'firemaking', 'woodcutting', 'farming', 'summoning'];

if (GetNumbers(SkillS) = SkillS) and (InRange(StrToIntDef(GetNumbers(SkillS), 0), 1, Length(SkillArr))) then
skNo := StrToInt(SkillS) - 1
else
if (not InStrArrEx(SkillS, SkillArr, skNo)) then
begin
srl_Warn('SkillToCoords', 'Invalid Skill Name/Number: ''' + string(Skill) + '''', warn_AllVersions);
Exit;
end;
If skNo = 18 Then Inc(SkNo); //empty space

if (InRange(skNo + 1, 1, 27)) then
begin
CX := skNo div 9 + 1;
CY := skNo mod 9 + 1;
Disguise(SkillArr[SkNo]);
end;

Result := SkillCoords2(CY, CX);

GameTab(tab_Stats);
end;

function GetSkillInfo2(Skill: Variant; Amount : Boolean): Integer;
var
TP: TPoint;
Box : TBox;
TPA : TPointArray;
Cts : Integer;

begin
Result := -1;
GameTab(tab_Stats);
TP := SkillToCoords2(Skill);
if (not(Amount)) then
TP := Point(TP.x + 7, TP.y + 15);
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(0);
if not FindColors(TPA, 65535, TP.x - 5, TP.y - 4, TP.x + 29, TP.y + 14) then
exit;
DebugTPA(TPA, '');
Box := GetTPABounds(TPA);
Result := StrToIntDef(GetNumbers(GetTextAtEx(Box.x1 - 2, Box.y1 - 1, 140,
StatChars, False, True, 0, 3, 65535, 3, True, tr_Digits)), -1);
ColorToleranceSpeed(CTS);
end;

function GetSkillLevel2(Skill: Variant): Integer;
begin
Result := GetSkillInfo2(Skill, False);
end;


Begin
SetupSRL;
SRLPlayerForm(False, [], [], [], []);
For I := 1 To 25 Do
Begin
{ TP := SkillToCoords2(I);
MMouse(TP.x, TP.y, 0, 0); }
WriteLn(GetSkillLevel2(I));
wait(1200);
End;
End.

This one works in scar, but only cannot get 4 skills due to the ocr failing.
In simba it works 100% perfect.

(I've attached it with the test script and stuff, I'd advise you to use it with strings, not integers)

SRL Compiled in 16 msec
-1
3
26
64
24
8
28
1
1
5
6
1
37
7
26
1
23
-1
-1
-1
17
99
44
30
1
Successfully executed

Coh3n

2010-04-12 16:47:34

There's also some unused variables in your version, Ray. ;)

mastaraymond

2010-04-12 16:56:08

From: Coh3n
There's also some unused variables in your version, Ray. ;)

:redface:. I'm willing to accept fixes to make it work for Scar, but please let it use the current system, as dirty hax are dirty and not readable ;). Also have to fix Pinball for Simba 2morrow (note to self)

Coh3n

2010-04-12 17:13:01

From: mastaraymond
:redface:. I'm willing to accept fixes to make it work for Scar, but please let it use the current system, as dirty hax are dirty and not readable ;). Also have to fix Pinball for Simba 2morrow (note to self)

Dirty hax?

Oh, and if someone were to have 4 or 5 randomness when moving/clicking the mouse, it could result in hovering/clicking the wrong skill…

Wanted

2010-04-12 20:09:56

This still needs to be 100% fixed, I am working on it.

Any progress anyone makes or suggestions to this thread would be appreciated.

Wizzup?

2010-04-13 04:11:25

From: IceFire908
This still needs to be 100% fixed, I am working on it.

Any progress anyone makes or suggestions to this thread would be appreciated.


Seems to work for me, Naum and Raymond?

Coh3n

2010-04-13 10:17:09

From: Wizzup?
Seems to work for me, Naum and Raymond?

What Raymond committed works, yes, but the coords aren't near the middle of the skill box (they're almost at the very top edge). It's not really a big deal, but depending on the randomness of the point, it is possible to return an invalid point. I was discussing this with IceFire last night; if you use my SkillCoords, and the SkillToCoords ray committed, it works perfect in both SCAR and Simba. That being said, IceFire was still working on it after I left, so he may have noticed something I didn't.

Also, I'm pretty sure GetSkillInfo doesn't work (and I think Naum posted a Simba fix above, but doesn't work 100% in SCAR).

mastaraymond

2010-04-13 12:05:41

It returns the exact same point as the old one returned, just relative to the new box.. The old 'SkillCoords' returned the upper-level-coordinate. That's why I changed kept this behavior to not break any backwards compatibility..

Also running this script in scar works fine:

program New;
{.include srl/srl.scar}
begin
setupsrl;
Writeln(getxp(skill_woodcutting));
end.

So I fail to see your point Coh3n ;). Use less randomness in skill hovering ^^

Coh3n

2010-04-13 13:59:02

From: mastaraymond
It returns the exact same point as the old one returned, just relative to the new box.. The old 'SkillCoords' returned the upper-level-coordinate. That's why I changed kept this behavior to not break any backwards compatibility..

Also running this script in scar works fine:

program New;
{.include srl/srl.scar}
begin
setupsrl;
Writeln(getxp(skill_woodcutting));
end.

So I fail to see your point Coh3n ;). Use less randomness in skill hovering ^^

I should have said that it worked, but it could be made better in my opinion.

I didn't realize that the old one also returned coords near the edge. I thought when I used HoverSkill, it would hover in the middle, but maybe the coords are edited in that procedure. I don't know, I've never looked at it. I just thought it would make more sense to have it return coords in the middle of the box.

And it would appear that GetSkillInfo is working, my bad. :p

Wanted

2010-04-13 18:20:15

All skills, hovering, getxp, getlevel seem to work pretty well in SCAR 3.23 Beta Latest Rev / Open Dev SRL Latest Rev.

Also fixed the worldswitcher.

Edit: Noticed that this version doesn't like bytes ect… for input. I'm pretty sure the old one worked with bytes so I went ahead and added that ability.

Wizzup?

2010-04-13 18:26:57

Why on earth would you use a Byte for this… To save memory…? I can assure those three bytes aren't going to make ANY noticeable difference… You're only making this more complex by using Variants.
Honestly…? Why not just use Integers…

If it's for backwards compatibility… Who ever got that idea… (I hope it wasn't me… ;) )

EDIT: Also, why doesn't a byte just work automatically? Casting a byte to an integer should never be a problem…

Wanted

2010-04-13 18:29:25

From: Wizzup?
Why on earth would you use a Byte for this… To save memory…? I can assure those three bytes aren't going to make ANY noticeable difference… You're only making this more complex by using Variants.
Honestly…? Why not just use Integers…

If it's for backwards compatibility… Who ever got that idea… (I hope it wasn't me… ;) )


Lol a few of the scripts I were using were using Bytes, and I just tested them out to see the debug spammed by 25 lines of "*****WARNING"

It's for backwards compatibility. The variants have been apart of this since the beginning.

Wizzup?

2010-04-13 18:33:37

From: IceFire908
Lol a few of the scripts I were using were using Bytes, and I just tested them out to see the debug spammed by 25 lines of "*****WARNING"

It's for backwards compatibility. The variants have been apart of this since the beginning.


Well, IMO they should just update their scripts. Keeping endless backwards compatibility not a good idea.

Wanted

2010-04-13 18:39:56

From: Wizzup?
Also, why doesn't a byte just work automatically? Casting a byte to an integer should never be a problem…


I dunno why it doesn't work either :(, all I had to do was add or (This)) then.. not a big change :)

var
B: Byte;

begin
WriteLn(BoolToStr(VarType(B) = VarInteger));
WriteLn(BoolToStr(VarType(B) = VarByte));
end.

From: Wizzup?
Well, IMO they should just update their scripts.


Thought it was easier to update the SVN then two or three (known) scripts =P

From: Wizzup?
Keeping endless backwards compatibility not a good idea.


SRL5 :sasmokin: