Results 1 to 17 of 17

Thread: Shortened + new functions for SRL

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

    Default Shortened + new functions for SRL

    My Func List!

    Hey all, I was roaming through the includes and picked up some code which would either not work or could be made shorter (in my view).

    SRL/SRL/Skill/Magic.Scar

    SetUpAutoCast(AutoSpell: string; Defensive: Boolean):

    SCAR Code:
    function SetUpAutoCast(AutoSpell: string; Defensive: Boolean): Boolean;
    var
      X, Y, Col, Row, Msk: Integer;
      TB : TBox;
      Spells, ColArray : TVariantArray;
    begin
      if not GameTab(1) then exit;
      if Defensive then
        Mouse(655, 253, 50, 25, True)
      else Mouse(665, 320, 50, 25, True);
      Spells := ['', 'wind strike', 'water strike', 'earth strike', 'fire strike',
                'wind bolt', 'water bolt', 'earth bolt', 'fire bolt',
                'wind blast', 'water blast', 'earth blast', 'fire blast',
                'wind wave', 'water wave', 'earth wave', 'fire wave'];
      ColArray := [835570, 16579836, 16563743, 3003805, 835570];
      While (GetColor(587, 363) = 8621205) Do Wait(100 + Random(100));
      Try Msk := StrToIntDef(AutoSpell, -1) Except end;
      If Msk <> -1 Then
        Row := Trunc(Msk Div 4) + 1
      Else
      For Msk := 0 to High(Spells) Do
      If AutoSpell = Spells[Msk] Then
        Row := Trunc(Msk Div 4) + 1;

      If (Msk Mod 4) = 0 Then Dec(Row);
      Col := Msk Mod 4;
      If Col = 0 Then Col := 4;
      TB.x1 := 571 + 40 * (Col - 1);
      TB.y1 := 229 + 60 * (Row - 1);
     
      For Msk := 0 to High(Spells) Do
      If (LowerCase(AutoSpell) = Spells[Msk]) or (LowerCase(AutoSpell) = IntToStr(Msk)) Then
        Result := FindColor(X, Y, ColArray[Msk Mod 4], TB.x1, TB.y1, TB.x1 + 40, TB.y1 + 60);
      If Result <> True Then
      Begin
        srl_Warn('SetUpAutoCast', '"' + AutoSpell + '" is not a valid autocasting spell.', -2);
        Mouse(687, 448, 9, 4, True); // Exits the autocasting Spells setup 'popup'.
      End Else
        Mouse(x, y, 2, 2, True);
    End;

    Replaces the current one, I edited it a lot from the first release and it now works! Horaay! However, the last one would not exit the menu as there was a wrong co-ord, this now does.



    SRL/SRL/Core/MapWalk.Scar

    GetMiniMapDotsIn(WhatDot: String; x1, y1, x2, y2: Integer): TPointArray;

    SCAR Code:
    function GetMiniMapDotsIn(WhatDot: String; x1, y1, x2, y2: Integer): TPointArray;
    var
      Color, I: Integer;
      Arr : TVariantArray;
    begin
      WhatDot := LowerCase(WhatDot);
      Arr := [0, 'npc', 'yellow', 60909, 'cape', 'blue', 12742980, 'item', 'red',
             789758, 'player', 'white', 16711422, 'friend', 'green', 61440];
      For I := 0 to (High(Arr) Div 3)- 1 Do
      If (WhatDot = Arr[I*3+1]) Or (WhatDot = Arr[I*3+2]) Then
        Color := Arr[I*3+3];
      FindColorsSpiralTolerance(MMCX, MMCY, Result, Color, x1, y1, x2, y2, 0);
      RAaSTPA(Result, 4);
      if (WhatDot = 'player') or (WhatDot = 'white') then
      begin
        Swap(Result[0], Result[High(Result)]);
        SetLength(Result, High(Result));
      end;
    end;

    Hopefully that fixes the access violation error, and hopefully it is shorter.


    SRL/SRL/Skill/Cooking.Scar

    FindRange(Var X, Y : Integer) : Boolean;

    SCAR Code:
    Function FindRange(Var X, Y : Integer) : Boolean;
    Begin
      X := MSCX;
      Y := MSCY;
      Result := FindObjTPA(X, Y, 6579308, 10, 2, 10, 10, 20, ['ange']);
      If Result <> False Then GetMousePos(x, y);
    End;

    The last one had an error, I didn't do much here.


    SRL/SRL/Skill/Crafting.Scar

    FindOven(Var XX, YY : Integer) : Boolean;

    SCAR Code:
    Function FindOven(Var XX, YY : Integer) : Boolean;
    Begin
      XX := MSCX;
      YY := MSCY;
      Result := FindObjTPA(XX, YY, 3754068, 13, 2, 10, 10, 30, ['ven']);
      If Result <> False Then GetMousePos(xx, yy);
    End;

    Current one will keep on hovering and will not click. Again, I did not do much here.


    SRL/SRL/Core/Login.Scar

    Function LogOut : Boolean;

    SCAR Code:
    Function LogOut : Boolean;
    Var I : Integer;
    Begin
      Result := (LoggedIn <> True);
      If Result Then Exit;
      If SRL_Procs[srl_OnLogOut] <> nil Then
        SRL_Procs[srl_OnLogOut]();
      GameTab(14);
      Wait(200 + Random(100));
      While LoggedIn And (I <= 10) Do
      Begin
        Inc(I);

        If I Mod 2 = 0 Then
        If ClickText('here', UpChars, MIX1, MIY1, MIX2, MIY2, True) Then
        Begin
          Wait(600 + Random(300));
          If LoggedIn <> True Then Break;
        End;
      End;
      Result := True;
    End;

    ^ My shot ^


    SRL/SRL/Core/GameTab.Scar

    DoEmote(EmoteNumber : Integer)

    SCAR Code:
    Procedure DoEmote(EmoteNumber : Integer);
    Var Ex, Ey, Row, Col : Integer;
    Begin
      If (EmoteNumber / 46 > 1) Or (EmoteNumber * 34729237 = 0) Then
      Begin
        srl_Warn('DoEmote', 'Invalid EmoteNumber: ' + IntToStr(EmoteNumber) + ', Valid Emotes: 1..46', warn_AllVersions);
        Exit;
      End;
      GameTab(12);

      If EmoteNumber <= 20 Then
      If GetColor(724, 222) = 1975337 Then
        Mouse(724, 233, 5, 5, True);

      If InRange(EmoteNumber, 21, 40) Then
      Begin
        If GetColor(727, 360) = 2106924 Then
          Mouse(727, 360, 5, 5, True);
          EmoteNumber := EmoteNumber - 20;
      End;
               
      If InRange(EmoteNumber, 41, 46) Then
      Begin
        If GetColor(723, 443) = 1975337 Then
          Mouse(723, 443, 3, 3, True);
          EmoteNumber := EmoteNumber - 28;
      End;
     
      Row := (Trunc(EmoteNumber / 4) + 1);
        If EmoteNumber Mod 4 = 0 Then Dec(Row);
      Col := EmoteNumber Mod 4;
        If Col = 0 Then Col := 4;
     
      Ex := 562 + 37 * (Col - 1);
      Ey := 231 + 44 * (Row - 1);

      If CountColor(65536, Ex, Ey, Ex + 37, Ey + 44) >= 5 Then
      Begin
        Mouse(Ex, Ey, 23, 25, True);
        Wait(1200 + Random(700));
      End;
    End;

    DoEmote wasn't working and 9 new emotes have been added.


    Hopefully people can give me tips to improve .
    Thanks
    Last edited by Naum; 06-27-2009 at 05:25 PM.

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

    Default

    Moved on request..
    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

  3. #3
    Join Date
    Dec 2007
    Location
    192.168.1.73
    Posts
    2,439
    Mentioned
    6 Post(s)
    Quoted
    119 Post(s)

    Default

    I'm failing to see the point in shortening code, someone point out why its better?

    Nice collection of functions though, perhaps use srl_Explode for SetupAutoCast? Instead of having a huge array with all the spells.

  4. #4
    Join Date
    May 2007
    Location
    UK
    Posts
    4,007
    Mentioned
    1 Post(s)
    Quoted
    12 Post(s)

    Default

    Shorter = more efficient (faster) code
    I think ^^

    Well done Naum

    T~M

  5. #5
    Join Date
    Dec 2007
    Location
    192.168.1.73
    Posts
    2,439
    Mentioned
    6 Post(s)
    Quoted
    119 Post(s)

    Default

    Quote Originally Posted by The Man View Post
    Shorter = more efficient (faster) code
    I think ^^

    Well done Naum

    T~M
    Not necessarily, things like changing a mass of If's to a case will make it more efficient, but sometimes longer can be better, like with larger arrays, SCAR will have to go through the entire array every time it searches for a specific thing.

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

    Default

    Richard, I can easily change the array to make it faster, just add a begin after the if statement and make it:

    SCAR Code:
    If Result Then Exit

    So it won't loop through all of the array,

    Thanks for the comments though
    Last edited by Naum; 06-23-2009 at 11:34 PM.

  7. #7
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Hurrah for agreeances. Exactly my point of that thread (i'm just probably not the best person to do it for many of the really rs'y ones).

    idk why i didnt think of putting the strings in an array, when you added that i was like...wut?! Naice jobs.
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


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

    Default

    Quote Originally Posted by Dan Cardin View Post
    Hurrah for agreeances. Exactly my point of that thread (i'm just probably not the best person to do it for many of the really rs'y ones).

    idk why i didnt think of putting the strings in an array, when you added that i was like...wut?! Naice jobs.
    Thanks . Naice to see someone likes

  9. #9
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    procedure AreaInfo(area : string; var x1, y1, RowSize, ColSize, ColNum, RowNum : Integer);
    var
      Info : array [0..4] of TVariantArray;
      h, i : integer;
    begin
      Info[0] := [560, 212, 36, 42, 4, 7, 'inventory'];
      Info[1] := [63, 97, 55, 39, 21, 4, 'shop'];
      Info[2] := [35, 91, 44, 44, 10, 5, 'bank'];
      Info[3] := [310, 75, 32, 49, 4, 7, 'trade'];
      Info[4] := [24, 75, 32, 49, 4, 7, 'your trade'];
      h := high(Info);
      area := lowercase(area);
      for i := 0 to h do
      begin
        if area <> Info[i][6] then
          Continue;
        x1 := Info[i][0];
        y1 := Info[i][1];
        RowSize := Info[i][2];
        ColSize := Info[i][3];
        ColNum := Info[i][4];
        RowNum := Info[i][5];
        exit;
      end;
    end;
    Last edited by Da 0wner; 06-26-2009 at 12:10 AM.

  10. #10
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    SCAR Code:
    for i := 0 to 6 do

    Beat both of yous...

  11. #11
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Of course, but I have it like that so you can add them easily.

  12. #12
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Da 0wner View Post
    Of course, but I have it like that so you can add them easily.
    What would you need to add though?

  13. #13
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I don't even know what the function does tbh. I just did that because Naum did it . If it should be static then yes, we could use what you put.

  14. #14
    Join Date
    Sep 2008
    Posts
    241
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I don't see a difference in shortening code.

    In C++, when I compile a simple program with a "for" loop and a "while" loop with variables, both turn out to be the exact same file.

    SCAR runs with a compiler, so it wouldn't make that much of a difference.
    PM me if you need any help with math.
    I can try to help you with anything!


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

    Default

    Would you like to eat your words and time it using Niels's timer?
    Believe me, me and Da0wner had a heated contest..

  16. #16
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    He very much wants to have some exact timing with the best 3 out of five..
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


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

    Default

    Sorry guys, I completely scored the last one. It was because the current one is easier to edit.
    Furthermore, my one gave an out of range error which could be easily fixed by adding another line.

    Edit : Added another fix, this one is for DoEmote.

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
  •