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.
SCAR Code:
{*******************************************************************************
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.
SCAR Code:
{*******************************************************************************
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.
SCAR Code:
{*******************************************************************************
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.
SCAR Code:
{*******************************************************************************
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.
SCAR Code:
{*******************************************************************************
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.
SCAR Code:
{*******************************************************************************
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]
Code:
{*******************************************************************************
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;