SRL Archive - SRL Archives

Objective Functions


Rick

2009-10-04 23:39:12

I was bored and there weren't any Objective Functions in SRL, so I made these.

This will return the percentage of completion of the current objective. Its not accurate to the text, but accurate to the progress bar.

{*******************************************************************************
function ObjPercent: Integer;
By: r!ch!e
Description: Returns (Roughly) Objective Completion in Percent
*******************************************************************************}
function ObjPercent: Integer;
begin
Result := Round((CountColor(42772, 594, 387, 691, 402)/1137)*100);
end;
Returns coords of 1 of those 6 boxes that come up from pressing Random Objective. Thanks to Naum :) Fixed up his fix, perfect coords with randomness.


{*******************************************************************************
function ObjCoords(ObjSlot: Integer): TPoint;
By: r!ch!e & NaumanAkhlaQ
Description: Returns Coords of Random Objective Slot (ObjSlot : 1..6)
*******************************************************************************}
function ObjCoords(ObjSlot: Byte) : TPoint;
var
Row, Col : Integer;
begin
if not InRange(ObjSlot, 1, 6) then
begin
srl_Warn('ObjCoords', 'Invalid Slot', Warn_AllVersions);
Exit;
end;
Row := Trunc(ObjSlot / 2) + 1;
if Row mod 2 = 0 then Dec(Row);
Col := ObjSlot mod 3
if Col = 0 then Col := 3;
Result := Point(RandomRange(20 + 165 * (Col - 1), 160 + 165 * (Col - 1)), RandomRange(50 + 65 * (Row - 1), 160 + 65 * (Row - 1)));
end;

Returns True if an Objective is set.


{*******************************************************************************
function HasObjective: Boolean;
By: r!ch!e
Description: Returns True if an Objective is set.
*******************************************************************************}
function HasObjective: Boolean;
begin
Result := (GetColor(582, 267) <> 3029570);
end;

Self-explanatory. Clears the Objective only if there is an active objective.

{*******************************************************************************
function ClearObjective: Boolean;
By: r!ch!e
Description: Returns True if an Objective is Cleared, or no Objective Exists.
*******************************************************************************}
function ClearObjective: Boolean;
begin
GameTab(tab_Objectives);
Result := HasObjective;
if Result then
Mouse(RandomRange(559, 724), RandomRange(447, 456), 0, 0, True)
else
srl_Warn('ClearObjective', 'No Objective to Clear', Warn_AllVersions);
end;
Sets an objective based on the skill and level input. Also checks to see if it can input an objective before typing away.

{*******************************************************************************
function SetObjective(Skill: String; Level: Integer) : Boolean;
By: r!ch!e
Description: Sets Objective according to Skill and Level.
Returns True if Objective is set.
*******************************************************************************}
function SetObjective(Skill: String; Level: Integer) : Boolean;
var
TP : TPoint;
TPA: TPointArray;
Box: TBox;
s: String;
begin
if not InRange(Level, 1, 99) then
begin
srl_Warn('SetObjective', IntToStr(Level) + ' is not a valid level', Warn_AllVersions);
Exit;
end;
GameTab(tab_Stats);
TP := SkillToCoords(True, Skill)
Mouse(TP.x, TP.y + 3, 2, 2, False);
WaitOption('bjec', 300 + Random(500));
Wait(1000 + Random(250));
if (FindColorsTolerance(TPA, 0, 100, 390, 235, 410, 0)) then
begin
Box := GetTPABounds(TPA);
s := Trim(GetTextAtEx(Box.x1 - 2, Box.y1 - 2, 0, SmallChars, False, False,
0, 1, 0, 40, False, tr_AllChars));
end;
Result := (Pos('Enter the skill', s) > 0);
if Result then
TypeSend(IntToStr(Level));
end;
Sets a random objective based of the Objective slot. There are 6 slots that come up after pressing Random Objective and this chooses a specified one.

{*******************************************************************************
function SetRandomObjective(ObjNum: Integer; KeepOld: Boolean): Boolean;
By: r!ch!e
Description: Sets a Random Objective Slot (ObjSlot : 1..6). If an objective is
already set KeepOld determines if it is overwritten.
Returns True if Objective is set.
*******************************************************************************}
function SetRandomObjective(ObjSlot: Integer; KeepOld: Boolean): Boolean;
var
ObjP: TPoint;
begin
if not InRange(ObjSlot, 1, 6) then
begin
srl_Warn('SetRandomObjective', 'Invalid Objective Slot', Warn_AllVersions);
Exit;
end;
GameTab(tab_Objectives);
if (HasObjective) and (KeepOld) then
Exit;
Mouse(RandomRange(556, 725), RandomRange(422, 432), 0, 0, True);
Wait(400 + Random(350));
ObjP := ObjCoords(ObjSlot);
Mouse(ObjP.x, ObjP.y, 0, 0, True);
Result := HasObjective;
end;

Please provide feedback :)

Thanks.

Edit: Updated a few things. Thanks Naum.
Edit 2: Added HasObjective, and changed other procedures to use it.
Edit 3: Tweaked to use TabObjectives rather than TabObj.
Edit 4: All updated [04/08/2010]


{*******************************************************************************
function ObjectivePercent: Integer;
By: r!ch!e
Description: Returns (Roughly) Objective Completion in Percent
*******************************************************************************}
function ObjectivePercent: Integer;
begin
Result := Round(CountColor(42516, 596, 390, 690, 400) / 9.73);
end;

{*******************************************************************************
function ObjectiveCoords(ObjSlot: Integer): TPoint;
By: r!ch!e & Naum
Description: Returns Coords of Random Objective Slot (ObjSlot : 1..6)
*******************************************************************************}
function ObjectiveCoords(ObjectiveSlot: Byte) : TPoint;
begin
if not InRange(ObjectiveSlot, 1, 6) then
begin
srl_Warn('ObjectiveCoords', 'Invalid Slot', Warn_AllVersions);
Exit;
end;
Result.y := Trunc(ObjectiveSlot / 2) + 1;
if Result.y mod 2 = 0 then Dec(Result.y);
Result.x := ObjectiveSlot mod 3
if Result.x = 0 then Result.x := 3;
Result := Point(RandomRange(20 + 165 * (Result.x - 1), 160 + 165 * (Result.x - 1)), RandomRange(50 + 65 * (Result.y - 1), 160 + 65 * (Result.y - 1)));
end;

{*******************************************************************************
function HasObjective: Boolean;
By: r!ch!e
Description: Returns True if an Objective is set.
*******************************************************************************}
function HasObjective: Boolean;
begin
Result := (GetColor(582, 267) <> 3029570);
end;

{*******************************************************************************
function ClearObjective: Boolean;
By: r!ch!e
Description: Returns True if an Objective is Cleared, or no Objective Exists.
*******************************************************************************}
function ClearObjective: Boolean;
begin
GameTab(tab_Objectives);
Result := HasObjective;
if Result then
Mouse(RandomRange(559, 724), RandomRange(447, 456), 0, 0, True)
else
srl_Warn('ClearObjective', 'No Objective to Clear', Warn_AllVersions);
end;

{*******************************************************************************
function SetObjective(Skill: String; Level: Integer) : Boolean;
By: r!ch!e
Description: Sets Objective according to Skill and Level.
Returns True if Objective is set.
*******************************************************************************}
function SetObjective(Skill: String; Level: Integer) : Boolean;
var
TP : TPoint;
begin
if not InRange(Level, 1, 99) then
begin
srl_Warn('SetObjective', IntToStr(Level) + ' is not a valid level', Warn_AllVersions);
Exit;
end;
GameTab(tab_Stats);
TP := SkillToCoords(Skill);
Mouse(TP.x, TP.y + 3, 2, 2, False);
WaitOption('bjec', 300 + Random(500));
Wait(1000 + Random(250));
if (FindTextTpa(0, 0, 100, 390, 235, 410, 'Enter the skill', UpChars, Nothing)) then
begin
Wait(1000 + Random(250));
TypeSend(IntToStr(Level));
Result := True;
end;
end;

{*******************************************************************************
function SetRandomObjective(ObjectiveSlot: Integer; KeepOld: Boolean): Boolean;
By: r!ch!e
Description: Sets a Random Objective Slot (ObjSlot : 1..6). If an objective is
already set KeepOld determines if it is overwritten.
Returns True if Objective is set.
*******************************************************************************}
function SetRandomObjective(ObjectiveSlot: Integer; KeepOld: Boolean): Boolean;
var
ObjP: TPoint;
begin
if not InRange(ObjectiveSlot, 1, 6) then
begin
srl_Warn('SetRandomObjective', 'Invalid Objective Slot', Warn_AllVersions);
Exit;
end;
GameTab(tab_Objectives);
if (HasObjective) and (KeepOld) then
Exit;
Mouse(RandomRange(556, 725), RandomRange(422, 432), 0, 0, True);
Wait(400 + Random(350));
ObjP := ObjectiveCoords(ObjectiveSlot);
Mouse(ObjP.x, ObjP.y, 0, 0, True);
Result := HasObjective;
end;

Neehosoft

2009-10-04 23:42:48

:) Repped

Naum

2009-10-04 23:55:05

I thought ObjCoords could be done something like this:

Function ObjCoords(ObjSlot : Byte) : TPoint;
Var Row, Col : Integer;
Begin
Row := Trunc(ObjSlot / 2) + 1;
If Row Mod 2 = 0 Then Dec(Row);
Col := ObjSlot Mod 3
If Col = 0 Then Col := 3;
Result := Point(23 + 170 * (Col-1), 49 + 68 * (Row-1));
End;

That doesn't include randomness.

Edit: It's good practice to use InRange, instead of V < or > signs ;)

EDIT2 : If your really clever than you can use Result.x1/y1 instead of Row/Col, that is if you use it :)

Rick

2009-10-05 00:03:18

Thanks NeehoSoft.

Thanks Naum I'll change that.
Also, do you mind explaining how you got that?

Rich

2009-10-05 00:41:39

GameTab already checks whether it's in that tab or not, so there's no need for
if (GetCurrentTab <> tab_Obj) then

Richard.

Rick

2009-10-05 01:20:33

From: R1ch
GameTab already checks whether it's in that tab or not, so there's no need for
if (GetCurrentTab <> tab_Obj) then

Richard.


Changed.

I was messing around with the Code Naum posted and I perfected it. Achieves the original coords I posted and has randomness :)


{*******************************************************************************
function ObjCoords(ObjSlot: Integer): TPoint;
By: NaumanAkhlaQ & r!ch!e
Description: Returns Coords of Random Objective Slot (ObjSlot : 1..6)
*******************************************************************************}
function ObjCoords(ObjSlot: Byte) : TPoint;
var
Row, Col : Integer;
begin
if not InRange(ObjSlot, 1, 6) then
begin
srl_Warn('ObjCoords', 'Invalid Slot', Warn_AllVersions);
Exit;
end;
Row := Trunc(ObjSlot / 2) + 1;
if Row mod 2 = 0 then Dec(Row);
Col := ObjSlot mod 3
if Col = 0 then Col := 3;
Result := Point(RandomRange(20 + 165 * (Col - 1), 160 + 165 * (Col - 1)), RandomRange(50 + 65 * (Row - 1), 160 + 65 * (Row - 1)));
end;

Rick

2009-10-07 23:16:31

Bump ?

Nava2

2009-10-08 00:47:00

These look good, I don't have an SVN account so I cannot commit. I can't test either.

Rick

2009-10-09 15:19:07

Thanks :)

Should I have each function that changes the GameTab remember the previously used GameTab and switch back to it? Or should that be up to the user to do that?

senrath

2009-10-09 15:21:49

I'd say leave it up to the scripter.

BobboHobbo

2009-10-09 20:31:08

From: senrath
I'd say leave it up to the scripter.


But alot of people would proberly miss this thread, so it would be a smarter idea to have it in SRL :).

Nava2

2009-10-09 23:19:53

From: r!ch!e
Thanks :)

Should I have each function that changes the GameTab remember the previously used GameTab and switch back to it? Or should that be up to the user to do that?


yes.

Rick

2009-10-10 14:15:03

I'll add it, but looking through the GameTab Include no other functions do that ?

And, seeing as TabObjectives has been committed I will quickly change these.

lordsaturn

2009-10-10 15:09:45

Whats an objective?

Rick

2009-10-10 15:13:53

Objectives
The Objective system is an interface released on 17 September 2009. You can choose a random objective from a list or choose a goal yourself by right-clicking on a skill or quest. The objective system can also monitor the player's progress with the goal and notify what the player will receive by doing the goal.

Rick

2009-10-17 19:41:38

Yes, No ? Is there anything I should change, or did wrong ?
Feedback please :p

Awkwardsaw

2009-10-17 19:49:15

From: EvilChicken!
Good work, it is.
But I just can't imagine this being commonly used in scripts, which leads me to think that this doesn't belong in SRL.

Sorry.


is friends.scar even used at all?

:)

EvilChicken!

2009-10-17 19:58:18

From: Awkwardsaw
is friends.scar even used at all?

:)


I actually see more use for Friends.scar than this.
Again, no offense to you, r!ch!e, but I even had a couple of idea for different uses for it.

.. though you are partially right, that's one of the least used includes. (Along with FindXP?)

Awkwardsaw

2009-10-17 20:01:54

FindXP is amazing :) i use it all the time, :p

and how do you find more use in friends.scar?

Rick

2009-10-17 20:48:14

Alright, thanks.

EvilChicken!

2010-08-04 15:57:05

I'm an idiot, disregard my previous posts.

I'll commit this if it still works, please confirm/discard that.

[/BUMP]

Noted, lordsaturn.

lordsaturn

2010-08-04 16:20:01

If Obj stands for Objective, you should rename your functions to spell out Objective as to not confuse Obj with Object.

Rick

2010-08-04 19:03:04

From: EvilChicken!
I'm an idiot, disregard my previous posts.

I'll commit this if it still works, please confirm/discard that.

[/BUMP]

Noted, lordsaturn.


I'll check each function, and update any that need it.

Also, I'll edit the names.

Edit 2: All functions working.


{*******************************************************************************
function ObjectivePercent: Integer;
By: r!ch!e
Description: Returns (Roughly) Objective Completion in Percent
*******************************************************************************}
function ObjectivePercent: Integer;
begin
Result := Round(CountColor(42516, 596, 390, 690, 400) / 9.73);
end;

{*******************************************************************************
function ObjectiveCoords(ObjSlot: Integer): TPoint;
By: r!ch!e & Naum
Description: Returns Coords of Random Objective Slot (ObjSlot : 1..6)
*******************************************************************************}
function ObjectiveCoords(ObjectiveSlot: Byte) : TPoint;
begin
if not InRange(ObjectiveSlot, 1, 6) then
begin
srl_Warn('ObjectiveCoords', 'Invalid Slot', Warn_AllVersions);
Exit;
end;
Result.y := Trunc(ObjectiveSlot / 2) + 1;
if Result.y mod 2 = 0 then Dec(Result.y);
Result.x := ObjectiveSlot mod 3
if Result.x = 0 then Result.x := 3;
Result := Point(RandomRange(20 + 165 * (Result.x - 1), 160 + 165 * (Result.x - 1)), RandomRange(50 + 65 * (Result.y - 1), 160 + 65 * (Result.y - 1)));
end;

{*******************************************************************************
function HasObjective: Boolean;
By: r!ch!e
Description: Returns True if an Objective is set.
*******************************************************************************}
function HasObjective: Boolean;
begin
Result := (GetColor(582, 267) <> 3029570);
end;

{*******************************************************************************
function ClearObjective: Boolean;
By: r!ch!e
Description: Returns True if an Objective is Cleared, or no Objective Exists.
*******************************************************************************}
function ClearObjective: Boolean;
begin
GameTab(tab_Objectives);
Result := HasObjective;
if Result then
Mouse(RandomRange(559, 724), RandomRange(447, 456), 0, 0, True)
else
srl_Warn('ClearObjective', 'No Objective to Clear', Warn_AllVersions);
end;

{*******************************************************************************
function SetObjective(Skill: String; Level: Integer) : Boolean;
By: r!ch!e
Description: Sets Objective according to Skill and Level.
Returns True if Objective is set.
*******************************************************************************}
function SetObjective(Skill: String; Level: Integer) : Boolean;
var
TP : TPoint;
begin
if not InRange(Level, 1, 99) then
begin
srl_Warn('SetObjective', IntToStr(Level) + ' is not a valid level', Warn_AllVersions);
Exit;
end;
GameTab(tab_Stats);
TP := SkillToCoords(Skill);
Mouse(TP.x, TP.y + 3, 2, 2, False);
WaitOption('bjec', 300 + Random(500));
Wait(1000 + Random(250));
if (FindTextTpa(0, 0, 100, 390, 235, 410, 'Enter the skill', UpChars, Nothing)) then
begin
Wait(1000 + Random(250));
TypeSend(IntToStr(Level));
Result := True;
end;
end;

{*******************************************************************************
function SetRandomObjective(ObjectiveSlot: Integer; KeepOld: Boolean): Boolean;
By: r!ch!e
Description: Sets a Random Objective Slot (ObjSlot : 1..6). If an objective is
already set KeepOld determines if it is overwritten.
Returns True if Objective is set.
*******************************************************************************}
function SetRandomObjective(ObjectiveSlot: Integer; KeepOld: Boolean): Boolean;
var
ObjP: TPoint;
begin
if not InRange(ObjectiveSlot, 1, 6) then
begin
srl_Warn('SetRandomObjective', 'Invalid Objective Slot', Warn_AllVersions);
Exit;
end;
GameTab(tab_Objectives);
if (HasObjective) and (KeepOld) then
Exit;
Mouse(RandomRange(556, 725), RandomRange(422, 432), 0, 0, True);
Wait(400 + Random(350));
ObjP := ObjectiveCoords(ObjectiveSlot);
Mouse(ObjP.x, ObjP.y, 0, 0, True);
Result := HasObjective;
end;

EvilChicken!

2010-08-05 19:19:53

These functions have been slightly modified and committed to the OpenDev repository, revision #581 as of today.
Full credit is given.

Oh, and thanks! :)
It would be nice if you could do a checkout and ensure that all newly added features are functional. ;)

Rick

2010-08-05 19:50:18

Thanks for committing :)

Checked out and checked the functions, all work :)

NCDS

2010-08-05 21:16:45

I was thinking of this not too long ago but figured it wouldn't be used >.<

Nice job with it :)