Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Thread: Objective Functions

  1. #1
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Objective Functions

    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;
    Last edited by EvilChicken!; 08-05-2010 at 11:22 PM.

  2. #2
    Join Date
    Jul 2009
    Posts
    421
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Repped
    Quote Originally Posted by Cstrike View Post
    Why do I even try these things? I just shit my pants over this god damn tutorial. Fuck, that's uncleanable. I can't even wash that out because there's so much of my shit it will just stain everything else. If I put it in the washing machine, I'm sure to stain the sides.

  3. #3
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    I thought ObjCoords could be done something like this:

    SCAR Code:
    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
    Last edited by Naum; 10-05-2009 at 04:01 AM.

  4. #4
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks NeehoSoft.

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

  5. #5
    Join Date
    May 2007
    Location
    England
    Posts
    4,141
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

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

    Richard.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  6. #6
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by R1ch View Post
    GameTab already checks whether it's in that tab or not, so there's no need for
    SCAR Code:
    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

    Code:
    {*******************************************************************************
    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;
    Last edited by Rick; 10-08-2009 at 03:16 AM.

  7. #7
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

  8. #8
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    These look good, I don't have an SVN account so I cannot commit. I can't test either.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  9. #9
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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?

  10. #10
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    I'd say leave it up to the scripter.

  11. #11
    Join Date
    May 2007
    Location
    NSW, Australia
    Posts
    2,823
    Mentioned
    3 Post(s)
    Quoted
    25 Post(s)

    Default

    Quote Originally Posted by senrath View Post
    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 .

  12. #12
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by r!ch!e View Post
    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.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  13. #13
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

  14. #14
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Whats an objective?

  15. #15
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

  16. #16
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

  17. #17
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by EvilChicken! View Post
    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?

    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  18. #18
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    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?)

  19. #19
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    FindXP is amazing i use it all the time,

    and how do you find more use in friends.scar?
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  20. #20
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

  21. #21
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    I'm an idiot, disregard my previous posts.

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

    [/BUMP]

    Noted, lordsaturn.
    Last edited by EvilChicken!; 08-04-2010 at 08:37 PM.

  22. #22
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

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

  23. #23
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by EvilChicken! View Post
    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.

    SCAR 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;
    Last edited by EvilChicken!; 08-05-2010 at 07:03 AM. Reason: s/code/scar/

  24. #24
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    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.
    Last edited by EvilChicken!; 08-05-2010 at 11:21 PM.

  25. #25
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks for committing

    Checked out and checked the functions, all work

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •