Results 1 to 3 of 3

Thread: [Help] Creating my first Scar Script.

  1. #1
    Join Date
    Apr 2008
    Posts
    28
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default [Help] Creating my first Scar Script.

    I've been a member for a while and I still don't have a clue on how to script. So I decided to make a simple easy script by compiling functions, procedures, and other components of different scripts.

    This script is supposed to do the following:
    -Walk a short distance to a general store
    -Trade the store owner and buy 27 pie dishes
    -Walk back a short distance to deposit boxes
    -Deposit all items
    -Repeat

    So this is what I have so far, mind you this is taken from two scripts (skilld u's "Cow Killa" and Nicabz "Eye of Newter").

    SCAR Code:
    // -------------------------------------------------------------------------- //
    //                                    pwnt!                                   //
    // -------------------------------------------------------------------------- //
    // --                                                                      -- //
    // --                              Pie Disher                              -- //
    // --                                 By                                   -- //
    // --                      sex°, skilld u and Nicabz                       -- //
    // --                                                                      -- //
    // -------------------------------------------------------------------------- //
    // --                                                                      -- //
    // --                       Buys Pie Dishes and Banks.                     -- //
    // --                                                                      -- //
    // -------------------------------------------------------------------------- //
    // --                            Instructions                              -- //
    // -------------------------------------------------------------------------- //
    // --                                                                      -- //
    // --  Keep Cash in first inventory slot.                                  -- //
    // --  Place your Player(s) in fron of the Deposit Boxes.                  -- //
    // --  Suggested to have nothing equipped.                                 -- //
    // --                                                                      -- //
    // -------------------------------------------------------------------------- //
    // --                              Features                                -- //
    // -------------------------------------------------------------------------- //
    // --                                                                      -- //
    // --  Should Never Get Lost.                                              -- //
    // --  Buys Pie Dishes!                                                    -- //
    // --  Banks Pie Dishes!                                                   -- //
    // -------------------------------------------------------------------------- //
    // --                                                 Stole this thing From-- //
    // --                                              Wizzup? and Fakawi Mager-- //
    // -------------------------------------------------------------------------- //

    program PieDisher;

    {.include SRL\SRL.scar}

    var
     x, y, i, Loads, PiesBought, LoadsDone, Pies, Dishes, Exxey: integer;
     Loop: string;
     DDTMfailed : array[1..2] of Integer;

    //----------------------------------------------------------------------------//
    const MySRLID             = '';//<- your SRL ID (for stats) in here.
    const MySRLPassword       = '';//<- your SRL PW (for stats) in here.
    const NumLoads            = 10;    //<- Loads before Switching players
    //----------------------------------------------------------------------------//

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

      Players[0].Name :='';
      Players[0].Pass :='';
      Players[0].Nick :='';
      Players[0].Active :=True;

      {Players[1].Name :='';
      Players[1].Pass :='';
      Players[1].Nick :='';
      Players[1].Active :=False;

      Players[2].Name :='';
      Players[2].Pass :='';
      Players[2].Nick :='';
      Players[2].Active :=False;}


    end;

    procedure TheRespond;
    begin
      if InChat('hey') or InChat('hi') or InChat('whats up?') or InChat('ello')
      or InChat('wassup') or InChat('sup') or InChat('h ey') or InChat('h ello')
      or InChat('hows it going') or InChat('was up') or InChat('w hats up') then
      begin
        case Random(10) of
          0 : TypeSend('hi');
          1 : TypeSend('hello');
          2 : TypeSend('hey');
          3 : TypeSend('sup');
          4 : TypeSend('hola');
          5 : TypeSend('yo');
          6 : TypeSend('dont feel like talking now, sorry');
          7 : TypeSend('sup');
          8 : TypeSend('not now');
          9 : TypeSend('please leave me alone');
        end;
      end;
      if InChat('lol') or InChat('funny') or InChat('ha')or
      InChat('wow') or InChat('rofl') or InChat('omg')then
      begin
        case Random(10) of
          0 : TypeSend('lol');
          1 : TypeSend('lmao');
          2 : TypeSend('hehe');
          3 : TypeSend('roflmao');
          4 : TypeSend('rofl');
          5 : TypeSend('funny funny');
          6 : TypeSend('haha');
          7 : TypeSend('omg');
          8 : TypeSend('that was funny');
          9 : TypeSend('lol!');
        end;
      end;
      if InChat(Players[CurrentPlayer].Nick) then
      begin
        case Random(10) of
          0 : TypeSend('leave me alone');
          1 : TypeSend('get away from me please');
          2 : TypeSend('what?');
          3 : TypeSend('im busy');
          4 : TypeSend('sorry, cant talk now');
          5 : TypeSend('not now');
          6 : TypeSend('busy');
          7 : TypeSend('i am busy sorry');
          8 : TypeSend('scram');
          9 : TypeSend('go away');
        end;
      end;
      if InChat('noob') or InChat('newb') or InChat('nub') or InChat('choob')
      or InChat('ch00b') or InChat('n00b') or InChat('nooby') or InChat('nublet')
      or InChat('newby') or InChat('nubby') then
      begin
        case Random(11) of
          0 : TypeSend('thanks');
          1 : TypeSend('w/e');
          2 : TypeSend('thnx');
          3 : TypeSend('thank you');
          4 : TypeSend('thanks :p');
          5 : TypeSend('your a noob');
          6 : TypeSend('im not nub');
          7 : TypeSend('i pwn you.');
          8 : TypeSend('go away');
          9 : TypeSend('you nub');
          10 : TypeSend(';p');
        end;
      end;
      if InChat('bye') or InChat('cya') or InChat('gtg') or InChat('im leaving')
      or InChat('im going') or InChat('see you later') or InChat('l8r mate')
      or InChat('l8r') or InChat('ttyl') or InChat('ttfn') or InChat('b ye')
      or InChat('by') then
      begin
        case Random(11) of
          0 : TypeSend('c ya');
          1 : TypeSend('bye');
          2 : TypeSend('ttyl');
          3 : TypeSend('b ye');
          4 : TypeSend('by');
          5 : TypeSend('ttfn');
          6 : TypeSend('b y');
          7 : TypeSend('l8r');
          8 : TypeSend('cya');
          9 : TypeSend('l8r mate');
          10 : TypeSend('bye');
        end;
      end;
    end;


    procedure AntiBan;
    begin
      case random(200) of
        0, 16, 17, 18, 19: begin
             MakeCompass('S');
             Wait(50 + random(100));
             MakeCompass('W');
             Wait(50 + random(100));
             MakeCompass('N');
             Wait(50 + random(100));
             SetAngle(false);
             Wait(50 + random(100));
             SetAngle(true);
           end;
        1, 20, 21, 22, 23: begin
             MakeCompass('W');
             Wait(50 + random(100));
             MakeCompass('E');
             Wait(50 + random(100));
             MakeCompass('S');
             Wait(50 + random(100));
             MakeCompass('N');
           end;
        2, 24, 25, 26, 27: begin
             KeyDown(VK_Left);
             Wait(1000 + random(500));
             KeyUp(VK_Left);
             Wait(50 + random(100));
             KeyDown(VK_Right);
             Wait(1000 + random(500));
             KeyUp(VK_Right);
             Wait(50 + random(100));
             MakeCompass('N');
           end;
        3, 28, 29, 30: begin
                         KeyDown(VK_Down);
             Wait(1000 + random(500));
             KeyUp(VK_Down);
             Wait(50 + random(100));
             KeyDown(VK_Up);
             Wait(1000 + random(500));
             KeyUp(VK_Up);
           end;
        4, 31, 32, 33: AlmostLogout;
        5, 6, 7: RandomMovement;
        8, 9, 10: MMouse(5 + random(250), 5 + random(250), 5, 5);
        11, 12, 13, 14, 15: begin
                              Mouse(5 + random(100), 5 + random(100), 5, 5, false);
                              Wait(50 + random(25));

                              MMouse(5 + random(50), 5 + random(50), 5, 5);
                            end;
        34, 35, 36, 37: HoverSkill('random', false);
        38, 39, 40: RandomMovement;
        41, 42, 43: BoredHuman;
        44, 45, 46: PickUpMouse;
      end
    end;
     
    function FindGrassColor: Integer; //-20 + 20
    var
      H,S,L,X,Y,Z : Extended;
      R,G,B,P,A,TestColor,xx,xy : Integer;
      TPA : TPointArray;
    begin
      if Not(LoggedIn) then Exit;
      xx:= MMCX;
      xy := MMCY;
      FindColorsSpiralTolerance(xx, xy, TPA, 5611431, MMX1, MMY1, MMX2, MMY2, 60)
      P := High(TPA);
      for A := 0 to P do
      begin
        if RS_OnMinimap(TPA[A].X, TPA[A].Y) then
        begin
          TestColor := GetColor(TPA[A].X, TPA[A].Y);
          if SimilarColors(TestColor, 5611431, 50) then
          begin
            ColorToRGB(TestColor, R, G, B);
            ColorToHSL(TestColor, H, S, L);
            ColorToXYZ(TestColor, X, Y, Z);
            if InRange(R - G, -12, 28) then //-20 + 20
            if InRange(R - B, 62, 102) then
            if InRange(G - B, 54, 94) then
            if InRange(Round(S) - Round(H), 3, 49) then//-15 + 15
            if InRange(Round(L) - Round(H), 19, 0) then
            if InRange(Round(S) - Round(L), -31, -1) then
            if InRange(Round(X) - Round(Y), -11, 3) then  //-7 + 7
            if InRange(Round(Y) - Round(Z), 13, 27) then
            if GetColor(TPA[A].X + 2, TPA[A].Y + 2) = TestColor then
            if GetColor(TPA[A].X + 1, TPA[A].Y + 1) = TestColor then
            begin
              Result := TestColor;
              Exit;
            end;
          end;
        end;
      end;
      Writeln('Couldnt find Color!');
      Result := 0;
    end;

    procedure OpenDepositer;
    var
      Colors: TIntegerArray;
      BankTPA: TPointArray;
      i, k: integer;
    begin
      Colors := [5987413, 4934727, 5855827, 3436859];
      if not LoggedIn or FindDead then Exit;
      for k := 0 to High(colors) do
      if FindColorsTolerance(BankTPA, colors[k], MSX1, MSY1, MSX2, MSY2, 10) then
      begin
        repeat
          for i := 0 to High(BankTPA) do
          begin
            MMouse(BankTPA[i].x, BankTPA[i].y, 5, 5);
            Wait(500);
          end;
        until IsUpText('pen');
        if IsUpText('pen') then
        begin
          GetMousePos(x, y);
          Mouse(x, y, 5, 5, true);
          Flag;
        end;
      end;
    end;

    function LoadDDTMs(CaseNumber: integer): integer;
    var
      dtmMainPoint: TDTMPointDef;
      dtmSubPoints: Array [0..3] of TDTMPointDef;
      dtSubPoints: Array [0..4] of TDTMPointDef;
      WalkOneDDTM, TaShopDDTM, TaBankDDTM: TDTM;
    begin
      case CaseNumber of
        1: begin //to shop from bank
             dtmMainPoint.x := 650;
             dtmMainPoint.y := 112;
             dtmMainPoint.AreaSize := 1;
             dtmMainPoint.AreaShape := 0;
             dtmMainPoint.Color := FindTreeTopColor;
             dtmMainPoint.Tolerance := 1;

             dtSubPoints[0].x := 651; //main point root
             dtSubPoints[0].y := 116;
             dtSubPoints[0].AreaSize := 1;
             dtSubPoints[0].AreaShape := 0;
             dtSubPoints[0].Color := FindTreeRootColor;
             dtSubPoints[0].Tolerance := 1;

             dtSubPoints[1].x := 661; //lower tree root
             dtSubPoints[1].y := 107;
             dtSubPoints[1].AreaSize := 1;
             dtSubPoints[1].AreaShape := 0;
             dtSubPoints[1].Color := FindTreeRootColor;
             dtSubPoints[1].Tolerance := 10;

             dtSubPoints[2].x := 657; //top tree root
             dtSubPoints[2].y := 99;
             dtSubPoints[2].AreaSize := 1;
             dtSubPoints[2].AreaShape := 0;
             dtSubPoints[2].Color := FindTreeRootColor;
             dtSubPoints[2].Tolerance := 10;

             dtSubPoints[3].x := 659; //tree next to main
             dtSubPoints[3].y := 114;
             dtSubPoints[3].AreaSize := 1;
             dtSubPoints[3].AreaShape := 0;
             dtSubPoints[3].Color := FindTreeRootColor;
             dtSubPoints[3].Tolerance := 10;

             dtSubPoints[4].x := 659; //tree next to main top
             dtSubPoints[4].y := 110;
             dtSubPoints[4].AreaSize := 1;
             dtSubPoints[4].AreaShape := 0;
             dtSubPoints[4].Color := FindTreeTopColor;
             dtSubPoints[4].Tolerance := 1;

             TaCowsDDTM.MainPoint := dtmMainPoint;
             TaCowsDDTM.SubPoints := dtmSubPoints;
             Result := AddDTM(TaCowsDDTM);

           end;
        2: begin //to bank
             dtmMainPoint.x := 820;
             dtmMainPoint.y := 277;
             dtmMainPoint.AreaSize := 1;
             dtmMainPoint.AreaShape := 0;
             dtmMainPoint.Color := FindGrassColor;
             dtmMainPoint.Tolerance := 1;

             dtSubPoints[0].x := 827; //tree top point
             dtSubPoints[0].y := 287;
             dtSubPoints[0].AreaSize := 1;
             dtSubPoints[0].AreaShape := 0;
             dtSubPoints[0].Color := FindTreeTopColor;
             dtSubPoints[0].Tolerance := 1;

             dtSubPoints[1].x := 844; //npc color
             dtSubPoints[1].y := 266;
             dtSubPoints[1].AreaSize := 1;
             dtSubPoints[1].AreaShape := 0;
             dtSubPoints[1].Color := 60909;
             dtSubPoints[1].Tolerance := 10;

             dtSubPoints[2].x := 817; //bank symbol
             dtSubPoints[2].y := 263;
             dtSubPoints[2].AreaSize := 1;
             dtSubPoints[2].AreaShape := 0;
             dtSubPoints[2].Color := 1103344;
             dtSubPoints[2].Tolerance := 10;

             dtSubPoints[3].x := 861; //general store
             dtSubPoints[3].y := 291;
             dtSubPoints[3].AreaSize := 1;
             dtSubPoints[3].AreaShape := 0;
             dtSubPoints[3].Color := 66139;
             dtSubPoints[3].Tolerance := 10;

             dtSubPoints[4].x := 845; //tree root
             dtSubPoints[4].y := 260;
             dtSubPoints[4].AreaSize := 1;
             dtSubPoints[4].AreaShape := 0;
             dtSubPoints[4].Color := FindTreeRootColor;
             dtSubPoints[4].Tolerance := 1;

             TaBankDDTM.MainPoint := dtmMainPoint;
             TaBankDDTM.SubPoints := dtmSubPoints;
             Result := AddDTM(TaBankDDTM);
           end;
      end;
    end;

    function DDTMmaster(Number:integer; Recursive:boolean):boolean; //stole this idea from king vash <3
    var
     MouseRan,ddtm,flagger:integer;
    begin
      if not LoggedIn then Exit;
      Writeln('DDTMMaster(' + inttostr(number) + ')');
      MakeCompass('n');
      Result   := False;
      Flagger  := 5;
      MouseRan := 5;
      case Number of
       1: ddtm := LoadDDTMs(1);// 1 is to shop from bank
       2: ddtm := LoadDDTMs(2);// 2 is to bank from shop
      if not LoggedIn then Exit;
      if (DTMRotated(ddtm, x, y, mmx1 , mmy1, mmx2, mmy2)) then
      begin
        Status(Loop + 'Found DDTM(' + inttostr(number) + ')');
        if rs_onminimap(x, y) and rs_onminimap(x, y) then
        Mouse(x, y, MouseRan, MouseRan, true)                                           // Yes: Click there
        else
        begin                                                                                         // No : DDTM plus offset is not onscreen
          Writeln('DDTMMaster(' + inttostr(number) + ') OffMiniMap helper was just called from ' + loop)      // Debug this fact
          if rs_onminimap(x, y) and rs_onminimap(x, y) then
          Mouse(x, y, 6, 6, True)                                                                        // Yes : Click somewhere to DDTM
          else Mouse(x, y, 3, 3, True);                                                                       // No  : Click close to DDTM                                                                                          // Wait till your Close
          if (DTMRotated(ddtm, x, y, mmx1 , mmy1, mmx2, mmy2))                                                // Find The DDTM again
          then Mouse(x, y, 5, 5, true)                                            // Found and Clicked properly
        end;
        Result:=True;                                                                                         // Result is True!
        Ftwait(4);                                                                                            // Look for Bad Stuff
        FFlag(flagger);                                                                                  // Wait Till player is appropiate distance away
      end;
      FreeDTM(ddtm);
      if not Result then
      begin
        if Recursive then Result := DDTMMaster(number, False)
        else
        begin
          Players[CurrentPlayer].Loc := ('F in DDTMMaster(' + inttostr(number) + ')');
          Writeln(Players[CurrentPlayer].Loc);
          Inc(DDTMFailed[number]);
        end;
      end;
    end;

    procedure WalkToBank;
    begin
      if not DDTMMaster(4, true) then
      if not RadialWalk(FindGrassColor, 0, 13, 51, 5, 5) then
      if not RadialWalk(FindGrassColor, 322, 337, 53, 5, 5) then
      begin
        WriteLn('Walking to Bank Failed. =[');
        NextPlayer(false);
      end;
    end;

    procedure CloseIt;
    begin
      Exxey := BitmapFromString(6, 1, 'beNpLdCtIREUAPdcGiw==');
      if FindBitmap(Exxey, x, y) then
      begin
        Mouse(x, y, 5, 5, true);
        Wait(500 + random(500));
      end;
    end;

    procedure DepositStuff;
    begin
      Pie := DTMFromString('78DA637461626078C2800276AE5FC7C005A41' +
           '981F83F10300602D5DC6340038C4824907606AAB94E408D0550CD' +
           '5D026AAC806ADE1150E30954F389801A7FA09AA7F8D50000C9150' +
           'E5C');
      if FindDTM(Pie, x, y, msx1, msy1, msx2, msy2) then
      begin
        Mouse(x, y, 5, 5, false);
        ChooseOption('ll');
        Wait(500 + random(500));
        CloseIt;
        Loads := Loads + 1;
        LoadsDone := LoadsDone + 1;
        ReportVars[3] := ReportVars[3] + 1;
      end;
    end;

    procedure WalkToShop;
    begin
      if not DDTMMaster(3, true) then
      if not RadialWalk(FindGrassColor, 152, 136, 43, 5, 5) then
      if not RadialWalk(FindGrassColor, 118, 143, 43, 5, 5) then
      begin
        WriteLn('Walking to Shop failed. =[');
        NextPlayer(false);
      end;
    end;

    function FindHieronymus: Boolean;
    var
      i: Integer;
      Hieronymus Avlafrim : Array [0..5] of Integer;

    begin
      Hieronymus Avlafrim[0] := 1209614;
      Hieronymus Avlafrim[1] := 1973792;
      Hieronymus Avlafrim[2] := 8816529;
      Hieronymus Avlafrim[3] := 5995424;
      Hieronymus Avlafrim[4] := 3026218;
      Hieronymus Avlafrim[5] := 7440783;
      for i := 0 to 5 do
      begin
        if(FindColorSpiralTolerance(x,y,Hieronymus Avlafrim[i],MSX1,MSY1,MSX2,MSY2,5))then
         MMouse(x,y,1,1);
        if IsUpText ('ymus avla') then
         Mouse(x,y,0,0,False);
        ChooseOption('rade')
        Begin
          Result := True;
          Exit
          Writeln('Found & Traded. :)');
        end;
      end;
      Result := False;
      Writeln('Not Found or Traded. :(');
    end;

    procedure FreeDTMs;
    begin
      FreeBitmap(Exxey);
      FreeDTM(Hide);
    end;

    procedure Report;
    begin
      ClearReport;
      SRLRandomsReport;
      AddToReport('/\/\/\/\/\/\ Pie Disher /\/\/\/\/\/\');
      AddToReport(Padr('[ Bought: ' + IntToStr(PiesBought) + ' Pie Dishes', 34) + ']');
      AddToReport(Padr('[ Completed: ' + IntToStr(LoadsDone) + ' loads', 34) + ']');
      AddToReport(Padr('[ Failed DDTMs: ', 34) + ']');
      for i := 1 to 10 do
      if (DDTMfailed[i] > 0) then
      AddToReport(Padr('[' + IntToStr(i) + '=' + IntToStr(DDTMfailed[i]) + ',', 34) + ']');
      AddToReport(Padr('[ Ran For: ' + TimeRunning, 34) + ']');
      AddToReport('/\/\/\/\/\/\/ Pie Disher \/\/\/\/\/\/');
      SendSRLReport;
    end;

    procedure MainLoop;
    begin
      repeat
        repeat
          repeat
            begin
              AntiBan;
              TehRespond;
              if InFight then
              begin
                repeat
                  Wait(500 + random(500));
                until not InFight;
              end;
              PiesBought := PiesBought + 27;
              ReportVars[0] := ReportVars[0] + 1;
            end;
          until InvFull;
          WalkToBank;
          DepositStuff;
          WalkToShop;
          Report;
        until Loads >= NumLoads;
        NextPlayer(LoggedIn);
        Loads := 0;
      until False;
    end;

    begin
      SetupSRL;
      ScriptId := '817';
      SRLId := MySRLId;
      SRLPassword := MySRLPassword;
      ClearDebug;
      DeclarePlayers;
      ActivateClient;
      LoginPlayer;
      repeat
        MainLoop;
        ResetMe;
      until False;
      FreeDTMs;
    end.

    What I need help with:
    -Walking too and from bank-shop
    -Trading the General Store Owner (Name: Hieronymus Avlafrim)
    -DDTM for a Pie Dish

    Notes: The existing DDTM in the script is for a cow hide(The existing DDTM in the Cow Killa script). Also this script is non-fuctional.

    Also, I know I'm a noob and I'm new so if I'm violating any rules or you feel I'm just leeching parts of scripts and calling them my own(I'm not), please be polite in letting me know.

  2. #2
    Join Date
    Jul 2008
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Try Searching The Forums

  3. #3
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    You should ask Skilld U and Nicbaz for permission to release their scripts modified/cut up before posting it on the forums or releasing it as a script. Also make sure you have somewhere showing ownership to them as it's polite if they do grant you permission.

    As for the actual help, I would say taking bits from scripts to make your own is actually very hard compared to normal scripting. There are a lot of general scripting tutorials that will explain basic scar scripting and you should work up from there. Most people's first scripts are power miner's or power chopper's because it is quite a simple thing to do and will work up from there by maybe making it walk to a nearby bank or make it walk to a shop and sell the goods etc.

    If you really wanted to continue with this, I would say read a couple of tutorials on walking - I doubt any scripts would have the specific walking you would need.
    For trading the store owner, you will want to look up object searching o,r if you wanted to have more control over it, look up colour finding with arrays returned and then going through the array and checking the points against UpText.
    There are a few DDTM tutorials, but I think you would only need a DTM for a pie dish rather than a DDTM as that's made only when you may need to change a DTM during script run time.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Creating Your own procedures/functions in SCAR
    By drizzt in forum Outdated Tutorials
    Replies: 3
    Last Post: 05-17-2008, 03:11 AM
  2. Creating your first Scar Script
    By TravisV10 in forum Outdated Tutorials
    Replies: 8
    Last Post: 09-04-2007, 11:11 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
  •