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

Thread: String Functions

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

    Default

    I am making a script in which you must type in a type of spell.

    My current code (it sucks, I know) is this"
    SCAR Code:
    if (not pos('strike', spell) = 0) then RuneType := 'mind';
      if (not pos('bolt', spell) = 0) then RuneType := 'chaos';
      if (not pos('blast', spell) = 0) then RuneType := 'death';
      if (not pos('wave', spell) = 0) then RuneType := 'blood';

    Is there any way to check (in SCAR) if a substring exists in another string?

    Also, is there any reason SCAR always gets an Access Violation whenever I use Bitmaps?

    How would a script that just moves the mouse to a bitmap look?

    SCAR Code:
    program New;
    var i, xx, yy: Integer;
    begin
      FindBitmap(i, xx, yy);
    end.

    WHY???

    I get this error upon compilation:
    Code:
    [Runtime Error] : Exception: Access violation at address 006585D8 in module 'scar.exe'. Read of address 00000000 in line 5 in script
    Any help?

    Please?
    Last edited by ZephyrsFury; 07-08-2009 at 12:13 PM. Reason: Triple
    PM me if you need any help with math.
    I can try to help you with anything!


  2. #2
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by xXxBlender3DxXx View Post
    SCAR Code:
    program New;
    var i, xx, yy: Integer;
    begin
      FindBitmap(i, xx, yy);
    end.

    WHY???

    I get this error upon compilation:
    Code:
    [Runtime Error] : Exception: Access violation at address 006585D8 in module 'scar.exe'. Read of address 00000000 in line 5 in script
    Any help?

    Please?
    You need to declare the bitmap, silly.
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

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

    Default

    Well, I do.

    It works, but when I use RuneAmount('inv', 'mind'), it gives me the same error, only on FindBitmapTransparent().

    Okay, so here is the main problem(s):

    I always get an access violation on line 66 in the include Amount.scar, at FindBitmapTransparentTolerance().
    And how do I check to see if spell contains each of the strings (the procedures are commented out).

    SCAR Code:
    program DemonMager;
    {.Include SRL\SRL\misc\Smart.scar}
    {.Include SRL\SRL.scar}
    {.Include SRL\SRL\reflection\Reflection.scar}
    {.Include SRL\SRL\skill\Magic.scar}

    {****************************************************************************************************
                                     Start setting up the script
     ****************************************************************************************************}

    const spell = 'wind strike';                // Type in the name of your attack spell. 'Wind Strike' is an example.
          defensive = false;         // True if you want to gain Magic and Defense XP at the same time. False otherwise.
          username  = '';            // The player's username.
          password  = '';            // The player's password.
          nickname  = '';            // The first 3-4 letters of the player's username.
    {****************************************************************************************************
                                     Stop setting up the script
     ****************************************************************************************************}


    var xx, yy, Mark, DeadDemons, StartRunes, StartXP: Integer;
        RuneType: String;

    procedure DeclarePlayer;
    begin
      HowManyPlayers := 1;
      NumberOfPlayers(HowManyPlayers);
      CurrentPlayer := 0;

      Players[0].Name   := username;
      Players[0].Pass   := password;
      Players[0].Nick   := nickname;
      Players[0].Active := true;
    end;

    procedure AntiBan;
    begin
      case RandomRange(1, 50) of
        1: BoredHuman;
        3: RandomMovement;
        4: GameTab(RandomRange(1, 15));
        5: Sleep(RandomRange(4000, 10000));
        6: HoverSkill('magic', false);
      end;
    end;

    procedure SetupSMART;
    begin
      Smart_Members := true;
      Smart_Server := RandomWorld(Smart_Members, False);
      Smart_Signed := False;
      Smart_SuperDetail := False;
    end;

    procedure SetupPlayer;
    begin
    {  if (not pos('strike', spell) = 0) then} RuneType := 'mind';
    {  if (not pos('bolt', spell) = 0) then RuneType := 'chaos';
      if (not pos('blast', spell) = 0) then RuneType := 'death';
      if (not pos('wave', spell) = 0) then RuneType := 'blood';}


      FixSpells;
      SetUpAutoCast(spell, defensive);
      StartRunes := RuneAmount('inv', RuneType);
      writeln('You have ' + IntToStr(StartRunes) + ' ' + RuneType + ' runes.');
      StartXP := GetXP('magic');
      writeln('You have ' + IntToStr(StartXP) + ' Magic XP.');
     
      MakeCompass('n');
      SendArrowWait(0, RandomRange(1000, 1500));
    end;

    function IsCasting: boolean;
    var A1, A2: Integer;
    begin
      A1 := RuneAmount('inv', RuneType);
      sleep(RandomRange(1000, 1200));
      A2 := RuneAmount('inv', RuneType);
     
      if not(A1 = A2) then
      begin
        Result := true;
      end else
      begin
        Result := false;
      end;
    end;

    procedure PrintProggy;
    begin
      writeln('[--------------------------------->');
      Sleep(300);
      writeln('[  Spells Cast:     ' + IntToStr(StartRunes - RuneAmount('inv', RuneType)));
      Sleep(300);
      writeln('[  Demons killed:   ' + IntToStr(DeadDemons));
      Sleep(300);
      writeln('[  Total XP Gained: ' + IntToStr(GetXP('magic') - StartXP));
      Sleep(300);
      writeln('[--------------------------------->');
    end;

    procedure PrintSiggy;
    begin
      ClearDebug;
      writeln('[--------------------------------->');
      Sleep(300);
      writeln('[  Demon Mager v. 1.0.0.0');
      Sleep(300);
      writeln('[--------------------------------->');
    end;

    begin
      ClearDebug;
     
      SetupSRL;
      SetupReflection;
      SetupSMART;
     
      PrintSiggy;

      DeclarePlayer;
      LoginPlayer;
     
      SetupPlayer;
     
      repeat
        if not(LoggedIn) then LoginPlayer;
       
        FindNormalRandoms;
       
        if (FindObjCustom(xx, yy, ['2'], [2964863, 2110593, 1846639], 5)) then
        begin
          DeadDemons := DeadDemons + 1;

          GetMousePos(xx, yy);
          Mouse(xx, yy, 0, 0, False);

          Wait(50 + Random(500));
          ChooseOption('tack');
         
          FFlag(10);
         
          if (FindBlackChatMessage('ough run')) then
          begin
            writeln('You are out of runes!');
            PrintProggy;
            Logout;
            TerminateScript;
          end;
         
          MarkTime(Mark);
          repeat
            if (not(LoggedIn) or (FindNormalRandoms)) then Break;
            Sleep(1000 + Random(500));
          until (TimeFromMark(Mark) > 10000);
        end;

        while (IsCasting) do
        begin
          AntiBan;
          FindNormalRandoms;
        end;
      until false;
    end.

    Is it that bad?
    Last edited by ZephyrsFury; 07-08-2009 at 12:14 PM. Reason: Triple
    PM me if you need any help with math.
    I can try to help you with anything!


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

    Default

    You need to have a bitmap...

  5. #5
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    No need to keep posting, just give people time to reply

    SCAR Code:
    function SetupPlayer(Rune: String);
    begin
      case Lowercase(Rune) of
        'mind' : Result := pos('strike', spell) = 0;
        'chaos' : Result := pos('bolt', spell) = 0;
        'death' : Result := pos('blast', spell) = 0;
        'blood' : Result := pos('wave', spell) = 0;
      end;
      RuneType := Rune;
      FixSpells;  
      SetUpAutoCast(spell, defensive);
      StartRunes := RuneAmount('inv', RuneType);
      writeln('You have ' + IntToStr(StartRunes) + ' ' + RuneType + ' runes.');
      StartXP := GetXP('magic');
      writeln('You have ' + IntToStr(StartXP) + ' Magic XP.');
      MakeCompass('n');
      SendArrowWait(0, RandomRange(1000, 1500));
    end;

    Instead of repetative code, try using cases

    Do you understand what I did here?
    Last edited by NCDS; 07-08-2009 at 08:23 AM.

  6. #6
    Join Date
    Mar 2007
    Posts
    3,042
    Mentioned
    1 Post(s)
    Quoted
    14 Post(s)

    Default

    Quote Originally Posted by NCDS View Post
    No need to keep posting, just give people time to reply

    SCAR Code:
    procedure SetupPlayer(Rune: String);
    begin
      case Lowercase(Rune) of
        'mind' : Result := pos('strike', spell) = 0;
        'chaos' : Result := pos('bolt', spell) = 0;
        'death' : Result := pos('blast', spell) = 0;
        'blood' : Result := pos('wave', spell) = 0;
      end;
      RuneType := Rune;
      FixSpells;  
      SetUpAutoCast(spell, defensive);
      StartRunes := RuneAmount('inv', RuneType);
      writeln('You have ' + IntToStr(StartRunes) + ' ' + RuneType + ' runes.');
      StartXP := GetXP('magic');
      writeln('You have ' + IntToStr(StartXP) + ' Magic XP.');
      MakeCompass('n');
      SendArrowWait(0, RandomRange(1000, 1500));
    end;

    Instead of repetative code, try using cases

    Do you understand what I did here?
    Yes, you tried to use Result in a procedure.
    :-)

  7. #7
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    NCDS Your funny He will still have to use the if else case no matter what to find the positions anyway in order to send it through the procedure.

    Try this:
    SCAR Code:
    if (pos('strike', spell) > 0) then
      RuneType := 'mind'
    else if (pos('bolt', spell) > 0) then
      RuneType := 'chaos'
    else if (pos('blast', spell) > 0) then
      RuneType := 'death'
    else if (pos('wave', spell) > 0) then
      RuneType := 'blood';



    ~NS

  8. #8
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    >.< hate when hat stuff happens.

    Changed to function.

    That works, no?

  9. #9
    Join Date
    Feb 2007
    Location
    Alberta,Canada
    Posts
    2,358
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    or you can make an array (TStringArray) and loop through the code so for i := 0 to high(array) do if Pos(array[i], spell) > 0 then Index := i; Case Index of yadayada. ( I like doing that more than large if..then..else statements. Either or work, tbh my way is probably slower.
    “Ignorance, the root and the stem of every evil.”

  10. #10
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by NCDS View Post
    No need to keep posting, just give people time to reply

    SCAR Code:
    function SetupPlayer(Rune: String);
    begin
      case Lowercase(Rune) of
        'mind' : Result := pos('strike', spell) = 0;
        'chaos' : Result := pos('bolt', spell) = 0;
        'death' : Result := pos('blast', spell) = 0;
        'blood' : Result := pos('wave', spell) = 0;
      end;
      RuneType := Rune;
      FixSpells;  
      SetUpAutoCast(spell, defensive);
      StartRunes := RuneAmount('inv', RuneType);
      writeln('You have ' + IntToStr(StartRunes) + ' ' + RuneType + ' runes.');
      StartXP := GetXP('magic');
      writeln('You have ' + IntToStr(StartXP) + ' Magic XP.');
      MakeCompass('n');
      SendArrowWait(0, RandomRange(1000, 1500));
    end;

    Instead of repetative code, try using cases

    Do you understand what I did here?
    Quote Originally Posted by NCDS View Post
    >.< hate when hat stuff happens.

    Changed to function.
    NCDS, I doubt you took a look over it again, you still need to add in : Boolean; and read my last post it shows how your function has no mean, lol do you know what is he trying to do?



    ~NS

  11. #11
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Disregard that post then I guess lol. I'm a bit rushed right now as I'm trying to pick up and put Nathan to bed. I will look back at this later.

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

    Default

    Lulz. I'm making some code for that setting runetype or w/e. Hold on.

    SCAR Code:
    function GetRuneType(SpellName : string) : string;
    var
      TSA : TStringArray;
      i : integer;
    begin
      TSA := ['strike', 'bolt', 'blast', 'wave', 'mind', 'chaos', 'death', 'blood'];
      for i := 0 to 3 do
        if pos(TSA[i], SpellName) > 0 then
        begin
          result := TSA[i + 4];
          exit;
        end;
    end;
    or:
    SCAR Code:
    function GetRuneType(SpellName : string) : string;
    var
      TSA : TStringArray;
      i : integer;
    begin
      TSA := ['strike', 'bolt', 'blast', 'wave', 'mind', 'chaos', 'death', 'blood'];
      InStrArrEx(Copy(SpellName, pos(' ', SpellName) + 1, length(SpellName)), TSA, i);
      Result := TSA[i + 4];
    end;

    Your choice .
    Last edited by Da 0wner; 07-08-2009 at 08:45 AM.

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

    Default

    Thanks NCDS and Da 0wner.

    I basically have that worked out, but my script just dies at one point.

    It can count the runes once, but the second time it just gives me a runtime error in Amount.scar.
    Should I be freeing the called SRL bitmaps (through CountRunes())?
    PM me if you need any help with math.
    I can try to help you with anything!


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

    Default

    Bitmaps should be freed in that procedure already.

  15. #15
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by xXxBlender3DxXx View Post
    Thanks NCDS and Da 0wner.

    I basically have that worked out, but my script just dies at one point.

    It can count the runes once, but the second time it just gives me a runtime error in Amount.scar.
    Should I be freeing the called SRL bitmaps (through CountRunes())?
    Waah..? No thanks to me?

    You should try using the try finally except concept. Something like:

    SCAR Code:
    try
      // Do stuff to load bitmap and count
    finally
      // Free bitmap here
    except end;



    ~NS

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

    Default

    Well I actually posted (a) working function(s) .

    Anyways, he isn't loading them with his own function I don't think. I believe it is in Magic.scar.

  17. #17
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Da 0wner View Post
    Well I actually posted (a) working function(s) .

    Anyways, he isn't loading them with his own function I don't think. I believe it is in Magic.scar.
    I meant the bitmap issue



    ~NS

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

    Default

    So did I.

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

    Default

    I'm loading (well, using) via RuneAmount().

    It works the first time, but on the second calling of the function, I get a runtime exception.

    I only (sort of) fix it it I shove a srl_FreeBitmaps before and after each calling of the function.


    Do I smell a bug?

    Oh, and thanks Nadeem, sorta forgot about you!
    PM me if you need any help with math.
    I can try to help you with anything!


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

    Default

    SCAR Code:
    function RuneAmount(Area, RuneType: string): Integer;
    var
      RuneBmp, II: Integer;
      RuneNames: TStringArray;
    begin
      RuneNames := ['air', 'mind', 'water', 'fire', 'earth', 'law', 'nature', 'chaos', 'death', 'body', 'cosmic', 'soul', 'blood'];
      if (InStrArrEx(Lowercase(RuneType), RuneNames, II)) then
      begin
        RuneBmp := srl_GetBitmap(18 + II);
        Result := ItemAmount(Area, 'bmp', RuneBmp, [20]);
        FreeBitmap(RuneBmp);
      end else
        srl_Warn('RuneAmount', 'Invalid RuneType: ''' + RuneType + '''', warn_AllVersions);
    end;

    It frees it.

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

    Default

    Hmm, then why does the function only work when I shove a srl_FreeBitmaps before and after it?
    PM me if you need any help with math.
    I can try to help you with anything!


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

    Default

    Not entirely sure. Maybe you could post a fix to that function with SRL_freebitmaps .

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

    Default

    It works on it's own, but when more than one instance of the function occurs, the script dies and scar has a seizure.

    Sorta broken version:
    SCAR Code:
    {*******************************************************************************
    function RuneAmount(area, runetype: String): Integer;
    By: masquerader and modified by Ron and ZephyrsFury
    Description: Returns the amount of a certain rune in the specified area.
    *******************************************************************************}


    function RuneAmount(Area, RuneType: string): Integer;
    var
      RuneBmp, II: Integer;
      RuneNames: TStringArray;
    begin
      RuneNames := ['air', 'mind', 'water', 'fire', 'earth', 'law', 'nature', 'chaos', 'death', 'body', 'cosmic', 'soul', 'blood'];
      if (InStrArrEx(Lowercase(RuneType), RuneNames, II)) then
      begin
        RuneBmp := srl_GetBitmap(18 + II);
        Result := ItemAmount(Area, 'bmp', RuneBmp, [20]);
        FreeBitmap(RuneBmp);
      end else
        srl_Warn('RuneAmount', 'Invalid RuneType: ''' + RuneType + '''', warn_AllVersions);
    end;

    My sorta fix:
    SCAR Code:
    {*******************************************************************************
    function RuneAmount(area, runetype: String): Integer;
    By: masquerader and modified by Ron and ZephyrsFury
    Description: Returns the amount of a certain rune in the specified area.
    *******************************************************************************}


    function RuneAmount(Area, RuneType: string): Integer;
    var
      RuneBmp, II: Integer;
      RuneNames: TStringArray;
    begin
      srl_FreeBitmaps;

      RuneNames := ['air', 'mind', 'water', 'fire', 'earth', 'law', 'nature', 'chaos', 'death', 'body', 'cosmic', 'soul', 'blood'];
      if (InStrArrEx(Lowercase(RuneType), RuneNames, II)) then
      begin
        RuneBmp := srl_GetBitmap(18 + II);
        Result := ItemAmount(Area, 'bmp', RuneBmp, [20]);
        FreeBitmap(RuneBmp);

      srl_FreeBitmaps;
      end else
        srl_FreeBitmaps;

        srl_Warn('RuneAmount', 'Invalid RuneType: ''' + RuneType + '''', warn_AllVersions);

        srl_FreeBitmaps;
    end;

    It's he only thing that works.
    0.o
    PM me if you need any help with math.
    I can try to help you with anything!


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

    Default

    xXxBlender3DxXx, remember to use the Edit button next time you have something to add to a post. Don't post more than one post consecutively.. it gets annoying.

    Thanks.

  25. #25
    Join Date
    Jul 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    is there a place to find out all the functions?

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
  •