Results 1 to 12 of 12

Thread: Is this loop correct?

  1. #1
    Join Date
    Dec 2006
    Location
    Australia
    Posts
    698
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default Is this loop correct?

    Can someone tell me, if this:
    -find a cow (slaughtercow)
    -a wait procedure(patience)
    -if danger range is true it will start go to the bank
    - if it isnt, collects the hide
    -until it the invent is full
    -then it will walk to the bank find the bank and than come back

    SCAR Code:
    repeat
          if (WereAtBank = true) then Tofield;
          if (WereAtCows = true) then
          begin
            repeat
              if (SlaughterCow = true) then
               begin
                patience;
                if (DangerRange = True) then exit;
                CollectHide;
               end;
            until ((InvFull))
          end;
          ToBank;
          OpenAccount;
          ToField;
        until (toll >= Players[CurrentPlayer].integer2)

  2. #2
    Join Date
    Apr 2007
    Posts
    581
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    Looks like a good loop.

  3. #3
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Yes, it will do most things, but

    if (DangerRange = True) then exit;

    With this it will exit your whole script. So change it to a Break.
    Hup Holland Hup!

  4. #4
    Join Date
    Dec 2006
    Location
    Australia
    Posts
    698
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    changing it to break will break the current loop and move it on to the next part..

    thanks does that mean i have to change the if statement below?

    SCAR Code:
    Procedure patience;
    var cowwait : integer;
    begin
     marktime(cowwait);
     repeat
      wait(500+random(250));
      if (((TimeFromMark(cowwait) > ((cowpatience/2)+random((cowpatience/2))))) or (DangerRange = True)) then exit;
     until (not(InFight));
    end;

  5. #5
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Yes. And you can just use if SlaughterCow then..
    It's the same as if SlaughterCow = True

    ps. For false set not before it (if not SlaughterCow)
    Hup Holland Hup!

  6. #6
    Join Date
    Dec 2006
    Location
    Australia
    Posts
    698
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    What would i change the if statement to? a break, thanks for that neielsie never new that before, always learning

  7. #7
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    I don't really get your question, but..

    Exit exits a procedure (in your case your mainloop, so your whole script)
    Break breaks out of a loop and goes on after the loop.

    Example Exit:

    SCAR Code:
    var i: integer;
    begin
      repeat
       WriteLn(IntToStr(i);
       if i > 3 then Exit;
      until False
      WriteLn('We are out of the loop'); //It will never come here because we exit from the procedure
    end.

    Example Break
    SCAR Code:
    var i: integer;
    begin
      repeat
       WriteLn(IntToStr(i);
       if i > 3 then Break; //Breaks out of the loop
      until False
      WriteLn('We are out of the loop');
    end.
    Hup Holland Hup!

  8. #8
    Join Date
    Dec 2006
    Location
    Australia
    Posts
    698
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    ok thanks alot, yeah i worked it out i get muddled alot

  9. #9
    Join Date
    Mar 2007
    Posts
    674
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Dude looks fine, to be honest i didnt revise it all the way. I got annoyed when you mistook "were" for "we are"

  10. #10
    Join Date
    Dec 2006
    Location
    Australia
    Posts
    698
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    ok? thanks i spose?

    Can someone tell me why it isnt attacking the cows? and just do a general read over i wanna get this one perfect.
    SCAR Code:
    program Skinner;
    {
          #####   ##    ##                                      ###
       ######  /#### #####                                       ###
      /#   /  /  ##### #####                        #             ##
     /    /  /   # ##  # ##                        ##             ##
         /  /    #     #                           ##             ##
        ## ##    #     #      /##  ###  /###     ######## /###    ##       /###
        ## ##    #     #     / ###  ###/ #### / ######## / ###  / ##      / #### /
        ## ##    #     #    /   ###  ##   ###/     ##   /   ###/  ##     ##  ###/
        ## ##    #     #   ##    ### ##    ##      ##  ##    ##   ##    ####
        ## ##    #     ##  ########  ##    ##      ##  ##    ##   ##      ###
        #  ##    #     ##  #######   ##    ##      ##  ##    ##   ##        ###
           /     #      ## ##        ##    ##      ##  ##    ##   ##          ###
       /##/      #      ## ####    / ##    ##      ##  ##    /#   ##     /###  ##
      /  #####           ## ######/  ###   ###     ##   ####/ ##  ### / / #### /
     / #   ##                #####    ###   ###     ##   ###   ##  ##/     ###/
     #  #
      ##
            #######      /
          /       ###  #/         #
         /         ##  ##        ###
         ##        #   ##         #
          ###          ##
         ## ###        ##  /##  ###   ###  /###   ###  /###     /##  ###  /###
          ### ###      ## / ###  ###   ###/ #### / ###/ #### / / ###  ###/ #### /
            ### ###    ##/   /    ##    ##   ###/   ##   ###/ /   ###  ##   ###/
              ### /##  ##   /     ##    ##    ##    ##    ## ##    ### ##
                #/ /## ##  /      ##    ##    ##    ##    ## ########  ##
                 #/ ## ## ##      ##    ##    ##    ##    ## #######   ##
                  # /  ######     ##    ##    ##    ##    ## ##        ##
        /##        /   ##  ###    ##    ##    ##    ##    ## ####    / ##
       /  ########/    ##   ### / ### / ###   ###   ###   ### ######/  ###
      / #    #####       ##   ##/   ##/   ###   ###   ###   ### #####    ###
      #  #
      ####
    }

    {.include SRL/SRL.scar}
    {.include SRL/SRL/Skill/Fighting.scar}

    var {counters}
      toll, logd, bankd, xet, killd, KillingAttempts, hidecolor, CColors: integer;
    var {Colors}
      CowColor: array[1..4] of integer;
     
    const cowpatience           = 20000;
    const MissedColor           = 16728128;
    const HitColor              = 192;

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

      Players[0].Name := '';
      Players[0].Pass := '';
      Players[0].Nick := ''; {3-4 letters of your name}
      Players[0].Skill := 'strength'; {Fight Mode}
      Players[0].Active := True; {Use player?}
      Players[0].integer2 := 10;
    end;

    {======================================================================
                                 Colors
    =======================================================================}


    procedure CowColors;
    begin
      CowColor[1] := 3620687;
      CowColor[2] := 6975347;
      CowColor[3] := 1843500;
      CowColor[4] := 4941444;
      hidecolor := 11185588;
    end;

    Function InFightAt(x, y: Integer):Boolean;
    var
      dx, dy: Integer;
    begin
     if ( FindColor(dx, dy, GreenStatusColor, x - 20, y - 10, x + 20, y + 10) or
        FindColor(dx, dy, RedStatusColor, x - 20, y - 10, x + 20, y + 10)   or
        FindColor(dx, dy, MissedColor, x - 20, y - 10, x + 20, y + 10)   or
        FindColor(dx, dy, HitColor, x - 20, y - 10, x + 20, y + 10) ) then
        Result:=True;

    end;

    {======================================================================
                                Checks Hp Level
    =======================================================================}


    function DangerRange: boolean;
    begin
      if (GetHp <= (4 + Random(3))) then
      begin
        runawaydirection('W');
        wait(2500 + random(2000));
        Result := True
      end;
    end;

    {======================================================================
                                   Get Combat Level
    =======================================================================}


    function getcombatlevelb: integer;
    var
      Curtab, i: integer;
      Cmblvl: string;
    begin
      CurTab := getcurrenttab;
      gametab(1);
      Cmblvl := GetTextAtEx(671, 230, 100, StatChars, False, True, 0, 5, -1, 2, True, tr_Digits);
      if (Trim(Cmblvl) = '') then
        for i := 1 to 5 do
        begin
          Cmblvl := GetTextAtEx(671 + i, 230, 100, StatChars, False, True, 0, 5, -1, 2, True, tr_Digits);
          if (Trim(Cmblvl) <> '') then Exit;
        end;
      if (not (Trim(Cmblvl) = '')) then
        result := StrToInt(Trim(Cmblvl));
      wait(500 + random(200));
      gametab(Curtab);
    end;

    {======================================================================
                                   Player Report
    =======================================================================}


    procedure PlayerReport;
    var i: integer;
    begin
      for I := 0 to HowManyPlayers - 1 do
      begin
        WriteLn(Players[i].Name + ' = ' + booltostr(Players[i].Active));
        WriteLn('Att ' + inttostr(Players[i].level[1]) + ', Str ' + inttostr(Players[i].level[2]) + ', Def ' + inttostr(Players[i].level[3]));
        WriteLn('Cmb ' + inttostr(Players[i].integer1) + ', Hps ' + inttostr(Players[i].level[8]) + ', Pry ' + inttostr(Players[i].level[5]));
        WriteLn('Worked For: ' + IntToStr(Players[i].Worked) + ' min, Killed : ' + IntToStr(Players[i].Killed) + ', Loc: ' + Players[i].loc);
        WriteLn('Banked: ' + IntToStr(Players[i].Banked) + ' loads');
        WriteLn('');
        Writeln('================================================================');
      end
    end;

    {======================================================================
                                   Progress Report
    =======================================================================}


    procedure ProgressReport;
    begin
      writeln('');
      WriteLn('================================================================');
      WriteLn('|                     Me_ntals Killer                          |');
      Writeln('================================================================');
      Writeln('  Worked For ' + TimeRunning);
      Writeln('  Logged In ' + InttoStr(logd));
      Writeln('  Banked ' + InttoStr(bankd));
      writeln('  Kills  ' + InttoStr(killd));
      Writeln('================================================================');
    end;

    {======================================================================
                                   Introduction
    =======================================================================}


    procedure Introd;
    begin
     repeat
      wait(250);
      cleardebug;
      xet:= xet -1;
      writeln('               Me_ntals Skinner');
      writeln('');
      writeln('             Loading please wait');
      writeln('                      '+inttostr(xet));
     until(xet = 0)
     cleardebug;
     if (xet = 0) then
     writeln('                    Here We ago');
     writeln('                 ~Mentals Skinner~');
    end;


    {======================================================================
                                   Set Combat
    =======================================================================}


    procedure Combattype;
    begin
      if Players[CurrentPlayer].Skill = 'attack' then SetFightMode(1);
      if Players[CurrentPlayer].Skill = 'strength' then SetFightMode(2);
      if Players[CurrentPlayer].Skill = 'defence' then SetFightMode(4);
    end;


    {======================================================================
                                 Attack Cows
    =======================================================================}


    function SlaughterCow: boolean;
    begin
     KillingAttempts := KillingAttempts +1
     for CColors := 1 to 4 do
      begin
       if findcolorspiral(x, y, CowColor[CColors] , msx1, msy1, msx2, msy2)then
        begin
          mmouse(x, y, 3, 3);
          wait(100+Random(100));
          if IsUpTextMulti('tta','ow','ck C') and
          not(InFightAt(x, y)) then
           begin
            mouse(x, y, 0, 0, true);
            if (InChatMulti('alr', 'und ',' att')) then
              begin
                 Result:=True;
                 Exit;
              end;
              if (InChatMulti('ome', 'one ',' ing')) then
              begin
                 Result:=False;
                 Exit;
              end else
              begin
                Result := True;
                KillingAttempts := 0;
                killd := killd + 1;
                toll := toll + 1;
              end;
              if (KillingAttempts >= 100) then
                begin
                 WriteLn('Too Busy World');
                 terminatescript;
                end;
          end;
        end;
      end;
    end;

    {======================================================================
                                 Waits While Attacking Cows
    =======================================================================}


    Procedure patience;
    var cowwait : integer;
    begin
     marktime(cowwait);
     repeat
      wait(1000+random(1000));
      if (((TimeFromMark(cowwait) > ((cowpatience/2)+random((cowpatience/2))))) or (DangerRange = True)) then exit;
     until (not(InFight));
    end;

    {======================================================================
                                Collects Hide
    =======================================================================}


    procedure CollectHide;
    begin
     writeln('woo')
     writeln('woo')
     writeln('woo')
    end;

    {======================================================================
                                Walks To bank
    =======================================================================}


    procedure ToBank;
    begin
      if (RadialWalkEx(x, y, MMCX, MMCY, 1732439, 10, 0, 360, 40)) then Mouse(x, y, 5, 5, true);
      flag;
      if (RadialWalkEx(x, y, MMCX, MMCY, 234, 10, 355, 5, 25)) then Mouse(x, y, 5, 5, true);
      flag;
      if (FindSymbol(x, y, 'tree')) then Mouse(x, y, 5, 5, true);
      flag;
    end;

    {======================================================================
                                Banks Hide
    =======================================================================}


    procedure BankHides;
    var bx, by: integer;
    begin
      if (FindColorTolerance(bx, by, hidecolor, MIX1, MIY1, MIX2, MIY2, 10)) then
      begin
        Mouse(x, y, 1, 1, false);
        Wait(100 + Random(100));
        ChooseOption(x, y, 'All');
        bankd := bankd + 1;
        CloseBank;
      end;
    end;

    {======================================================================
                           Finds and Opens the Bank
    =======================================================================}


    procedure OpenAccount;
    var BBooth, BBooth2, tolran: Integer;
    begin
      BBooth := BitmapFromString(116, 1, 'z78DAADCD310E84301003C02F' +
        '11B2D8DE3224D9FF3FE940A01388205D712EA6B2EC883D2C4CC05' +
        '50F773756667060A3415765144A31AFBE68A1631D48AEA803C58A' +
        '76B33310374313A7A79E34330D9C95399F4260BEC9EDD9066AFB5' +
        'F06BAFC6B57255EE4C050A39E96A4A08B508EBF59506DDF9DCCD8' +
        '01D39B47676043B7F9D411D65F059AD59F3C961364E55F7E00CCD' +
        'E9B3F');
      BBooth2 := BitmapFromString(13, 1, 'z78DA3335333132B2302582347' +
        '204626CA4AB9133108249007EAC107C');
      repeat
        if (findbitmaptolerancein(BBooth, x, y, msx1, msy1, msx2, msy2, tolran)) or
          (findbitmaptolerancein(BBooth2, x, y, msx1, msy1, msx2, msy2, tolran)) then
        begin
          MMouse(x, y, 3, 3)
            Wait(100 + Random(100));
          tolran := tolran + 3;
          if (isuptextmulti('ooth', 'ank', 'nk bo')) then
          begin
            mouse(x, y, 4, 4, false)
              wait(100 + Random(100));
            clickoption('uick', 1);
            freebitmap(BBooth);
            freebitmap(BBooth2);
            wait(100 + Random(100));
            BankHides;
          end;
        end;
      until ((tolran >= 150) or (not (loggedin)))
        if (tolran >= 150) then
      begin
        Players[currentplayer].loc := 'Bank Problem'
          toll := players[currentplayer].integer2
      end;
    end;

    {======================================================================
                              Walks to Field
    =======================================================================}


    procedure ToField;
    begin
      RadialRoadWalk(findfallyRoadColor, 230, 195, 60, 1, 1);
      flag;
      RadialRoadWalk(findfallyRoadColor, 195, 170, 50, 1, 1);
      flag;
      RadialRoadWalk(findfallyRoadColor, 190, 170, 60, 1, 1);
      flag;
      if (FindSymbol(x, y, 'tree')) then Mouse(x, y, 5, 5, true);
      flag;
      if (RadialWalkEx(x, y, MMCX, MMCY, 234, 10, 115, 90, 60)) then Mouse(x, y, 5, 5, true);
      flag;
    end;

    {======================================================================
                             Determines Where we are
    =======================================================================}


    function WereAtBank: Boolean;
    begin
      if FindSymbol(x, y, 'bank') then
      begin
        mouse(x, y, 0, 0, true);
        flag;
        Players[currentplayer].loc := 'bank';
        result := true
      end;
    end;

    function WereAtCows: Boolean;
    begin
      if findcolortolerance(x, y, 1732439, mmx1, mmy1, mmx2, mmy2, 50) then
      begin
        Players[currentplayer].loc := 'field';
        result := true
        WriteLn('were at cows')
      end;
    end;


    {======================================================================
                                   Setup's
    =======================================================================}


    procedure SetupScript;
    begin
      DeclarePlayers;
      CowColors;
      ClearDebug;
      ClearReport;
      CColors := 0;
      toll := 0;
      bankd := 0;
      killd := 0;
      logd := 0;
      Introd;
      wait(1000);
        ActivateClient;
    end;

    procedure SetupPlayer;
    begin
      logd := logd + 1;
      HighestAngle;
      CombatType;
      SetChat('on', 1);
      SetChat('friends', 2);
      SetChat('off', 3);
      MakeCompass('N');
    end;

    {======================================================================
                                   Main Loop
    =======================================================================}


    begin
      SetupSRL;
      xet:=10;
      SetupScript;
      loginplayer;
      repeat
        if (not (LoggedIn)) then loginplayer;
        SetupPlayer
          repeat
          if (WereAtBank = true) then Tofield;
          if (WereAtCows = true) then
          begin
            repeat
              if (SlaughterCow) then
               begin
                patience;
                if (DangerRange = True) then break;
                CollectHide;
               end;
            until ((InvFull))
          end;
          ToBank;
          OpenAccount;
          ToField;
        until (toll >= Players[CurrentPlayer].integer2)
          if (toll >= Players[CurrentPlayer].integer2) then
        begin
          GetAllLevels;
          Players[currentplayer].integer1 := getcombatlevelb;
          ProgressReport;
          PlayerReport;
          SRLRandomsReport;
          LogOut;
          NextPlayer(True);
          toll := 0;
          SetupPlayer;
        end;
      until False;
    end.

  11. #11
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Maybe you have to use some tolerance ?
    Hup Holland Hup!

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

    Default

    yea they change their colors a lot so do FindColorTolerance and put like 5

    plus...ur supposed to put the number of the color...not the name...right?

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Is this correct?
    By NCDS in forum OSR Help
    Replies: 1
    Last Post: 12-23-2008, 03:14 AM
  2. is this correct?
    By jones2644 in forum OSR Help
    Replies: 2
    Last Post: 07-05-2008, 10:37 PM

Posting Permissions

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