Results 1 to 2 of 2

Thread: Simba scripts for _other_ games.

  1. #1
    Join Date
    Oct 2010
    Posts
    36
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Simba scripts for _other_ games.

    Not sure if this is the right spot for Simba scripts that are for something besides playing RS, if not then let me know where to post it. Just finished my first [working] script to farm level 5 npcs, and I'm looking for some feedback.

    It could use some polishing, and I plan on adding some color and character recognition [when I learn how...], improve error handling, randomize wait times, add a startup delay, ini file editor, and whatever else I can think of(!) but otherwise it works. Simba is awesome.

    Simba Code:
    //ini File Format

    {Instructions:
    Using a text editor such as notepad, create a file ending in .ini with a Main
       section and from 1 to 10 City sections (City1 to City10). Each city section
       describes 1 city starting with the topmost city (the one under the Friends
       List button). Choose a name to describe the city and place after 'Name='.
       Enter the map coordinates after 'Coords='. The Rally entry is the SCREEN
       PERCENTAGE (0 to 100%, 0 to 100%) of the center of the Rally Spot within the
       town view - (60, 45) is where the Rally Spot is located on the screen for a
       level 10 NPC. Lastly make a list of the NPCs you want to farm under NPC_Array
       in the form of "(nnn,nnn),(nnn,nnn),...(nnn,nnn)" (up to the number of heroes
       that you would send out.) Save the file to the directory you saved this
       script to and change the filename in the LoadSettings statement (around line
       #407)}

    {Example:

    [Main]
    Account="my_account"

    [City1]
    Name="city1"
    Coords="24, 344"
    Rally="60, 45"
    NPC_Array="(18,111),(18,112),(19,111),(20,113),(21,113),(21,114)"

    End of example.}
    Simba Code:
    program EFarm2;

    {var Account
     Description: Account name.}

    var
      Account: string;

    {type TScreenPoint, TMapPoint
     Description: Aliases for TPoint; Screen for the x,y of the physical
       monitor screen and Map for the x,y coordinates of the world map.}

    type
      TMapPoint = TPoint;
      TPercentPoint = TPoint;
      TScreenPoint = TPoint;

    {type TFarm, TFarmArray
     Description: Information about a target to 'farm'.}

    { TFarm = record
        Level : integer;
        CoordsXY : TMapPoint;
      end;}

    { TFarmArray = array of TFarm;}
      TFarmArray = TPointArray;

    {type TCity
     Description: Set of information for each city.}

      TCity = record
        Name : string;
        CoordsXY : TMapPoint;
        RallySpotXY : TScreenPoint;
        FarmList: TFarmArray;
      end;
      TCityArray = Array of TCity;

    var
      Cities: TCityArray;

    {const Troop Select Editbox Constants
     Description: Constants for use with selecting troop edit boxes
     in rally and barracks.}

    const
      EB_Worker = 1;        EB_Warrior = 2;
      EB_Scout = 3;         EB_Pikeman = 4;
      EB_Swordman = 5;      EB_Archer = 6;
      EB_Cavalry = 7;       EB_Cataphract = 8;
      EB_Transporter = 9;   EB_Ballista = 10;
      EB_BatteringRam = 11; EB_Catapult = 12;

    {const View Select Constants
     Description: Constants for use with switching views.}

      VS_Town = 1;
      VS_City = 2;
      VS_Map = 3;

    {const Window Constants
     Description: Constants for use with opening and closing windows.}

      W_RallySpot = 1;
      W_RallySpot_March = 2;

    {const System Message Constants
     Description: System messages that have to be acknowledged.}

      SM_MarchSuccessful = 1;

    {const Keyboard Constants
     Description: Constants for use with sending keystrokes.}

       DN_ARROW = 40;

    {procedure PercentToScreenPoint(PercentPoint, ScreenPoint: TScreenPoint);
     Description: Convert screen percentage point to physical client screen point.}

    procedure PercentToScreenPoint(PercentPoint: TMapPoint; var ScreenPoint: TScreenPoint);
      var
        w, h: Integer;
      begin
        GetClientDimensions(w, h);
        ScreenPoint.x := Round(PercentPoint.x * w / 100);
        ScreenPoint.y := Round(w * 7 * PercentPoint.y / 1200);
      end;

    {procedure ScreenToPercentPoint(ScreenPoint, PercentPoint: TScreenPoint);
     Description: Convert physical client screen point to screen percentage point.}

    procedure ScreenToPercentPoint(ScreenPoint, PercentPoint: TScreenPoint);
      var
        w, h: integer;
      begin
        GetClientDimensions(w, h);
        PercentPoint.x := Round(ScreenPoint.x * 100 / w);
        PercentPoint.y := Round((ScreenPoint.y * 100)/(w * 7 / 12));
      end;

    {function PointToString(Pt: TPoint): string;
     Description: Convert TPoint to TString.}

    function PointToString(Pt: TPoint): string;
      begin
        Result := Format('(%d, %d)', [Pt.x, Pt.y]);
      end;

    {function StringToPoint(s: tstring): TPoint;
     Description: Convert TString to TPoint.}

    function StringToPoint(s: string): TPoint;
      var
        re: TRegExp;
        x, y: integer;
      begin
        re := TRegExp.Create
        re.InputString := s;
        re.Expression := '[0-9]{1,3}';
        if re.ExecPos(1) then
          x := StrToInt(re.Match[0]);
        if re.ExecNext then
          y := StrToInt(re.Match[0]);
        re.Free
        Result := Point(x, y);
      end;

    {procedure AddPoint(var TPA: TPointArray; const ToAdd: TPoint);
     Description: Add TPoint to end of TPointArray.}

    procedure AddPoint(var TPA: TPointArray; const ToAdd: TPoint);
      begin
        setLength(TPA, length(TPA)+1);
        TPA[length(TPA)-1] := ToAdd
      end;

    {function StringToTPA(s: string): TPointArray;
     Description: Convert TString to TPoint.}

    function StringToTPA(s: string): TPointArray;
      var
        re: TRegExp;
        TPA:TPointArray;
      begin
        re := TRegExp.Create;
        re.Expression := '([0-9]{1,3},\x20?[0-9]{1,3})';
        re.InputString := s;
        if(re.ExecPos(1)) then
          begin
            repeat
              AddPoint(TPA,  StringToPoint(re.Match[0]));
              re.ExecNext;
            until (re.Match[0]='');
          end;
        re.Free
        Result := TPA;
      end;

    {procedure ClickLeft(ScreenPoint: TScreenPoint, NumberClicks: integer);
     Description: Click the left mouse button # of times.}

    procedure ClickLeft(ScreenPoint: TScreenPoint; NumberClicks: integer);
       var
         i: integer;
       begin
         with ScreenPoint do
           begin
           MoveMouse(x, y);
           for i := 1 to NumberClicks do
             begin
               ClickMouse(x, y, mouse_Left);
               if i < NumberClicks then
                 Wait(10+Random(10));
             end;
           end;
       end;

    {procedure SelectView(VS_View: integer);
     Description: Switch the view.}

    procedure SelectView(VS_View: integer);
      var
        Peb, Seb: TScreenPoint;
      begin
        with Peb do
          case VS_View of
            VS_Town: x := 50;
            VS_City: x := 0;
            VS_Map:  x := 0;
          end;
        Peb.y := 2;
        PercentToScreenPoint(Peb, Seb);
        ClickLeft(Seb, 1);
      end;

    {procedure OpenWindow(W_Wndw: integer);
     Description: Switch the view.}

    procedure OpenWindow(W_Wndw: integer);
      var
        Peb, Seb: TScreenPoint;
      begin
        case W_Wndw of
          W_RallySpot: Peb := Point(60, 38);
          W_RallySpot_March: Peb := Point(29, 33);
        end;
        PercentToScreenPoint(Peb, Seb);
        ClickLeft(Seb, 1);
      end;

    {procedure SelectCity(CityNumber: integer);
     Description: Select city 1 - 10.}

    procedure SelectCity(CityNumber: integer);
      var
        Peb, Seb : TScreenPoint;
      begin
        with Peb do
          case CityNumber of
             1: y := 39;
             2: y := 46;
             3: y := 51;
             4: y := 58;
             5: y := 64;
             6: y := 70;
             7: y := 75;
             8: y := 82;
             9: y := 88;
            10: y := 94;
          end;
        Peb.x := 76;
        PercentToScreenPoint(Peb, Seb);
        ClickLeft(Seb, 1);
      end;

    {procedure AppendTCA(var TCA: TCityArray; Const ToAppend: TCity);
     Description: Select city 1 - 10.}

    procedure AppendTCA(var TCA: TCityArray; Const ToAppend: TCity);
      begin
        SetLength(TCA, Length(TCA)+1);
        TCA[Length(TCA)-1] := ToAppend;
      end;

    {procedure SelectTroopMarchEB(troop: integer);
     Description: Select troop edit box.}

    procedure SelectTroopMarchEB(troop: integer);
      var
        Peb, Seb : TScreenPoint;
      begin
        with Peb do
          begin
            x := 33 - (troop mod 2 * 16);
            case troop of
              EB_Worker:       y := 27;
              EB_Warrior:      y := 27;
              EB_Scout:        y := 33;
              EB_Pikeman:      y := 33;
              EB_Swordman:     y := 39;
              EB_Archer:       y := 39;
              EB_Cavalry:      y := 45;
              EB_Cataphract:   y := 45;
              EB_Transporter:  y := 50;
              EB_Ballista:     y := 50;
              EB_BatteringRam: y := 56;
              EB_Catapult:     y := 56;
            end;
          end;
        PercentToScreenPoint(Peb, Seb);
        ClickLeft(Seb, 2);
      end;

    {procedure SelectMarchXCoordEB;
     Description: Select X coord edit box.}

    procedure SelectMarchXCoordEB;
      var
        Seb : TScreenPoint;
      begin
        PercentToScreenPoint(Point(48, 15), Seb);
        ClickLeft(Seb, 2);
      end;

    {procedure SelectMarchYCoordEB;
     Description: Select Y coord edit box.}

    procedure SelectMarchYCoordEB;
      var
        Seb : TScreenPoint;
      begin
        PercentToScreenPoint(Point(53, 15), Seb);
        ClickLeft(Seb, 2);
      end;

    {procedure SelectHeroCB;
     Description: Select hero combo box.}

    procedure SelectHeroCB;
      var
        sp : TScreenPoint;
      begin
        PercentToScreenPoint(Point(62, 24), sp);
        ClickLeft(sp, 1);
      end;

    {procedure SelectMissionCB;
     Description: Select mission combo box.}

    procedure SelectMissionCB;
      var
        sp : TScreenPoint;
      begin
        PercentToScreenPoint(Point(62, 19), sp);
        ClickLeft(sp, 1);
      end;

    {procedure SelectMarchOK;
     Description: Select march 'OK' button.}

    procedure SelectMarchOK;
      var
        sp : TScreenPoint;
      begin
        PercentToScreenPoint(Point(61, 70), sp);
        ClickLeft(sp, 1);
      end;

    {procedure AcknowledgeSysMsg(SM_Msg: integer);
     Description: Click the 'ok' button for a particular system message.}

    procedure AcknowledgeSysMsg(SM_Msg: integer);
      var
        Peb, Seb: TScreenPoint;
      begin
        case SM_Msg of
          SM_MarchSuccessful: Peb := Point(37, 47);
        end;
        PercentToScreenPoint(Peb, Seb);
        ClickLeft(Seb, 1);
      end;

    {procedure LoadSettings(SettingsFile: string);
     Description: Load saved account settings.}

    procedure LoadSettings(SettingsFile: string);
      var
        i: integer;
        Section: string;
        NoMoreCities: boolean;
        tmpCity: TCity;
      begin
        i := 1;
        NoMoreCities := False;
        if FileExists(SettingsFile) then
          begin
            writeln(format('+%s+',[stringofchar('-',40)]));
            Account := ReadINI('Main', 'Account', SettingsFile);
            writeln(format('| Loading account: %-21s |', [Account]));
            repeat
              tmpCity.Name := ReadINI('City'+IntToStr(i), 'Name', SettingsFile);
              if(tmpCity.Name = '') Then
                NoMoreCities := True
              else
                with tmpCity do
                  begin
                    Section := 'City'+IntToStr(i);
                    writeln(format('|  ..Loading city: %-21s |',[Name]));
                    CoordsXY := StringToPoint(ReadINI(Section, 'Coords', SettingsFile));
                    RallySpotXY := StringToPoint(ReadINI(Section, 'Rally', SettingsFile));
                    FarmList := StringToTPA(ReadINI(Section, 'NPC_Array', SettingsFile));
                    AppendTCA(Cities, tmpCity);
                    Inc(i)
                  end;
            until NoMoreCities
            writeln(format('| Finished loading settings. %-11s |', [' ']));
            writeln(format('+%s+',[stringofchar('-',40)]));
          end
        else
          writeln( 'Settings file not found.' ); //add setup editor here!!
      end;

     // Main
    var
      i, j: integer;

    begin
      ClearDebug;
      LoadSettings(ScriptPath + 'startup.ini'); //Change to ini file name!
      writeln(format('+%s+',[StringOfChar('-',40)]));
      writeln(format('| Starting farm sequence. %14s |', [' ']));
      writeln(format('+%s+',[StringOfChar('-',40)]));
      ActivateClient;
      Wait(2000);
      if (IsTargetValid = false) then
        begin
          writeln('Target invalid, terminiating script.');
          TerminateScript;
        end;
      for i := 0 to (length(Cities) - 1) do
        with Cities[i] do
          begin
            writeln(format('Farming %d from city %s.', [length(FarmList), Name]));
            SelectCity(i+1); //Select city 1..10
            Sleep(1000);
            SelectView(VS_Town);  //Select town view
            Sleep(1000);
            OpenWindow(W_RallySpot);
            Sleep(1000);
            OpenWindow(W_RallySpot_March); //Select march
            Sleep(1000);
            SelectMissionCB; //Select mission combobox
            Sleep(1000);
            SendKeys('A'); //Attack
            SelectTroopMarchEB(EB_Transporter);
            Sleep(1000);
            SendKeys('400'); //<-- Number of transporters to send.
            SelectTroopMarchEB(EB_Ballista);
            Sleep(1000);
            SendKeys('450'); //<-- Number of ballistae to send.
            for j := 0 to (length(FarmList) - 1) do
              begin
                writeln(format('[%d/%d] %s',
                  [j+1,length(FarmList),PointToString(FarmList[j])]));
                SelectMarchXCoordEB;
                Sleep(1000);
                SendKeys(format('%d', [FarmList[j].x]));
                SelectMarchYCoordEB;
                Sleep(1000);
                SendKeys(format('%d', [FarmList[j].y]));
                Wait(1000);
                SelectHeroCB; //Select hero
                Sleep(1000);
                KeyDown(DN_ARROW);
                Sleep(1000);
                KeyUp(DN_ARROW);
                Wait(1000);
                SelectMarchOK;
                Wait(1000);
                AcknowledgeSysMsg(SM_MarchSuccessful);
                Wait(1000);
              end
          end;
      writeln(format('+%s+',[stringofchar('-',40)]));
      writeln(format('| Finished farm sequence. %14s |', [' ']));
      writeln(format('+%s+',[stringofchar('-',40)]));
    end.

    Almost forgot! I wrote a piece of code to retrieve the cursor x,y and convert it to a percentage. Why a percentage? That way you don't have to search for the x,y coords every time you use a different computer and monitor!

    Simba Code:
    program FindXYPercentage;
    { Instructions:
      Drag client select target over client, place cursor where you want, and
      press [F9] to run.}


    const
      CR  = #$0D;
      LF  = #$0A;
      CRLF = CR + LF;
    var
      w, h, x, y: integer;
      Output: string;
    begin
      GetClientDimensions(w, h);
      GetMousePos(x, y);
      Output := Format('Client dimensions are: %dw x %dh.%s'
        +'Actual x,y are: (%d, %d).%s'
        +'Percentage x, y of screen are: (%d%s, %d%s).',
        [w,h,CRLF,x,y,CRLF,Round(x * 100 / w),'%',Round((y * 100)/(w * 7 / 12)),'%']);
      ShowMessage(Output);
      WriteLn(Output);
    end.

    (Please comment.)
    Last edited by EGM; 11-10-2010 at 01:03 AM. Reason: Added Script

  2. #2
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Yeah, you can post it here.

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
  •