Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
Sign in to follow this  
BryceTheCoder

Power Miner

Recommended Posts

Power Miner

Download + More info here: https://phgsosrs.createaforum.com/scripts/power-miner

Needs the OSI2 include to run. (File -> Includes Manager -> OSI2)

 

This is version 1.0 code: (please don't copy this into scar. Download the latest version via the links. This code may be out-of-date)

{$DEFINE RS07}
{$I OSI\OSI.scar}
{

Created by: BryceTheCoder

}

var
  topleftX, topleftY, botrightX, botrightY : Integer;
  topleft2X, topleft2Y, botright2X, botright2Y : Integer;
  xxColor, xxTol, oresMined, oreXp, pickSlot : Integer;
  searchLx, searchLy, searchRx, searchRy : Integer;
  cantFind : Integer;
  xxHue: Extended;
  xxSat: Extended;
  oreType, style : String;
  Form1_1: TForm;
  Label1: TLabel;
  Label2: TLabel;
  Label3: TLabel;
  Label4: TLabel;
  Button1: TButton;
  ComboBox1: TComboBox;
  ComboBox2: TComboBox;
  Edit1: TEdit;
  
const
  TheComputerCatchesOnFire = false;
  tVer = 'v1.0';

procedure ShowStats;
var
  xp : Integer;
begin
  xp := oresMined * oreXp;
  ClearDebug;
  writeln('=================== [ Power Miner ] ===================');
  writeln('You have mined: ' + IntToStr(oresMined) + ' ores!');
  writeln('Which gained you: ' + IntToStr(xp) + ' exp!');
  writeln('=================== [ created by BryceTheCoder ] ===================');  
  writeln('');
end;

procedure StartButton(sender: TObject);
begin
  oreType := ComboBox1.Text;
  style := ComboBox2.Text;
  pickSlot := StrToInt(Edit1.Text);
  Form1_1.Modalresult := mrOK;
end;

procedure CudntFind;
begin
  inc(cantFind);
  if (cantFind > 50) then
  begin
    ClearDebug;
    writeln('');
    writeln('');
    writeln('[Power Miner] Terminated the script because I cannot find any ores...');
    writeln('');
    writeln('');
    TerminateScript;
  end;
end;

procedure Form1_1_Init;
begin
  with Form1_1 do
  begin
    Form1_1 := CreateForm;
    Label1 := TLabel.Create(Form1_1);
    Label2 := TLabel.Create(Form1_1);
    Label3 := TLabel.Create(Form1_1);
    Label4 := TLabel.Create(Form1_1);
    Button1 := TButton.Create(Form1_1);
    ComboBox1 := TComboBox.Create(Form1_1);
    ComboBox2 := TComboBox.Create(Form1_1);
    Edit1 := TEdit.Create(Form1_1);
    with Form1_1 do
    begin
      Left := 527;
      Top := 129;
      BorderIcons := [biSystemMenu];
      BorderStyle := bsSingle;
      Caption := 'Created by: BryceTheCoder';
      ClientHeight := 217;
      ClientWidth := 382;
      Color := clWindow;
      Font.Charset := DEFAULT_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -11;
      Font.Name := 'Tahoma';
      Font.Style := [];
      OldCreateOrder := False;
      PixelsPerInch := 96;
    end;
    with Label1 do
    begin
      Parent := Form1_1;
      Left := 32;
      Top := 8;
      Width := 319;
      Height := 49;
      Caption := 'Power Miner - ' + tVer;
      Font.Charset := ANSI_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -37;
      Font.Name := 'Tempus Sans ITC';
      Font.Style := [fsBold];
      ParentFont := False;
    end;
    with Label2 do
    begin
      Parent := Form1_1;
      Left := 48;
      Top := 68;
      Width := 82;
      Height := 17;
      Caption := 'Ore to Mine:';
      Font.Charset := ANSI_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -13;
      Font.Name := 'Tempus Sans ITC';
      Font.Style := [fsBold];
      ParentFont := False;
    end;
    with Label3 do
    begin
      Parent := Form1_1;
      Left := 228;
      Top := 68;
      Width := 61;
      Height := 17;
      Caption := 'Playstyle:';
      Font.Charset := ANSI_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -13;
      Font.Name := 'Tempus Sans ITC';
      Font.Style := [fsBold];
      ParentFont := False;
    end;
    with Label4 do
    begin
      Parent := Form1_1;
      Left := 32;
      Top := 142;
      Width := 110;
      Height := 17;
      Caption := 'Slot Pickaxe is in:';
      Font.Charset := ANSI_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -13;
      Font.Name := 'Tempus Sans ITC';
      Font.Style := [fsBold];
      ParentFont := False;
    end;
    with Button1 do
    begin
      Parent := Form1_1;
      Left := 5;
      Top := 176;
      Width := 373;
      Height := 37;
      Caption := 'Start Bot!';
      Font.Charset := ANSI_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -15;
      Font.Name := 'Tempus Sans ITC';
      Font.Style := [];
      ParentFont := False;
      TabOrder := 0;
      OnClick := @StartButton;
    end;
    with ComboBox1 do
    begin
      Parent := Form1_1;
      Left := 20;
      Top := 87;
      Width := 137;
      Height := 25;
      Font.Charset := ANSI_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -13;
      Font.Name := 'Tempus Sans ITC';
      Font.Style := [];
      ParentFont := False;
      TabOrder := 1;
      Text := 'What ore to mine?';
      Items.Add('Iron');
    end;
    with ComboBox2 do
    begin
      Parent := Form1_1;
      Left := 168;
      Top := 87;
      Width := 193;
      Height := 25;
      Font.Charset := ANSI_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -13;
      Font.Name := 'Tempus Sans ITC';
      Font.Style := [];
      ParentFont := False;
      TabOrder := 2;
      Text := 'What playstyle?';
      Items.Add('Extremely Focused');
      Items.Add('Focused but I AFK sometimes');
      Items.Add('I AFK a ton');
    end;
    with Edit1 do
    begin
      Parent := Form1_1;
      Left := 144;
      Top := 139;
      Width := 25;
      Height := 23;
      Font.Charset := ANSI_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -13;
      Font.Name := 'Tempus Sans ITC';
      Font.Style := [];
      ParentFont := False;
      TabOrder := 3;
      Text := '-1';
    end;
  end;
end;

procedure Form1_1_SafeInit;
var
  v: TVariantArray;
begin
  SetLength(v, 0);
  ThreadSafeCall('Form1_1_Init', v);
end;

function Form1_1_ShowModal: Boolean;
begin
  Result := Form1_1.ShowModal = mrOk;
end;

function Form1_1_SafeShowModal: Boolean;
var
  v: TVariantArray;
begin
  SetLength(v, 0);
  Result := ThreadSafeCall('Form1_1_ShowModal', v);
end;
  
procedure SetupOreColors;
begin
  if (oreType = 'Iron') then
  begin
    oreXp := 35;
    xxColor := 2042181;
    xxTol := 9;
    xxHue := 0.08;
    xxSat := 0.27;  
  end;
end;

function btc_InRangeE(value, minimum, maximum: Extended): Boolean;
begin
  Result := ((value >= minimum) and (value <= maximum));
end;

function btc_PercentToValue(percent, source: Extended): Extended;
begin
  if (percent <> 0) then
    Result := ((Extended(percent) / 100) * Extended(source))
  else
    Result := 0.0;
end;

function btc_CountPixelsBx(area: TBox): Integer;
begin
  if ((area.X1 > area.X2) or (area.Y1 > area.Y2)) then                              
    Result := -1
  else
    Result := Integer(((area.X2 - area.X1) + 1) * ((area.Y2 - area.Y1) + 1));
end;

procedure btc_Sleep(MS: Integer);
var
  t: Integer;  
  k: Byte; 
begin
  t := GetSystemTime;
  k := CharToVKey('s');  
  repeat
    try
      if (GetCurrentKeyState(VK_CONTROL) and GetCurrentKeyState(VK_MENU) and GetCurrentKeyState(k)) then
        TerminateScript;
    except
    end;
    Wait(0);
  until ((GetSystemTime - t) > MS); 
end;

function btc_TIAMatch(TIA1, TIA2: TIntArray): Integer;
var
  i, m: Integer;
begin
  Result := 0;
  m := Min(High(TIA1), High(TIA2));
  for i := 0 to m do
    if (TIA1[i] = TIA2[i]) then
      Inc(Result);
end;

function btc_AnimationPercentEx(XS, YS, XE, YE, minTime, maxTime: Integer; minPixelShiftPercent: Extended): Boolean;
var        
  bx: TBox;
  m, l, r: Integer;   
  p: TPointArray; 
  a, b: TIntArray;
begin
  if btc_InRangeE(minPixelShiftPercent, 0, 100) then
  begin                
    bx := Box(XS, YS, XE, YE);
    r := Round(btc_PercentToValue(minPixelShiftPercent, btc_CountPixelsBx(bx)));
    p := TPAFromBox(bx);
    b := GetColors(p);
    l := Length(b);
    btc_Sleep(minTime); 
    m := GetSystemTime;
    repeat          
      a := GetColors(p);
      Result := ((l - btc_TIAMatch(b, a)) >= r);
      SetLength(a, 0);
      btc_Sleep(0);  
    until (Result or ((GetSystemTime - m) >= maxTime));
    SetLength(p, 0);     
    SetLength(b, 0);   
  end else
    Result := False;
end;

function isAnimating(): Boolean;
begin
//btc_AnimationPercentEx(239, 162, 254, 176, 250, 1000, 42.0);
 Result := btc_AnimationPercentEx(250, 153, 269, 181, 250, 600, 25.0);
end;

procedure SetupConfig;
begin
  Mouse(675,482,8,8,true);
  waitRR(70,100); 
  Mouse(572,227,13,13,true);
  waitRR(70,100);
  Mouse(704,306,4,4,true);
  waitRR(70,100);
  Mouse(644,187,7,7,true); 
end;

procedure SetupSearch1;
var
  del : LongInt;
begin
 ClearDebug;
 wait(1000);
 Writeln('[Search Area 1]');
 Writeln('>>> Please click the top-left of the search area <<<');
 PickColor(del, topleftX, topleftY);
 ClearDebug;
 wait(1000);
 ClearDebug;
 Writeln('[Search Area 1]');
 Writeln('>>> Please click the bottom-right of the search area <<<');
 PickColor(del, botrightX, botrightY);
 ClearDebug;
 wait(1000);
end;

procedure SetupSearch2;
var
  del : LongInt;
begin
 ClearDebug;
 Writeln('[Search Area 2]');
 Writeln('>>> Please click the top-left of the search area <<<');
 PickColor(del, topleft2X, topleft2Y);
 ClearDebug;
 wait(1000);
 ClearDebug;
 Writeln('[Search Area 2]');
 Writeln('>>> Please click the bottom-right of the search area <<<');
 PickColor(del, botright2X, botright2Y);
 ClearDebug;
 wait(1000);
end;

procedure MineOre;
var
  x,y : Integer;
begin
  cantFind := 0;
  if (random(11) = 1) then
  begin
    GetMousePos(x,y);
    Mouse(x,y,0,0,false);
    waitRR(35,100);
    ChooseOption('Mine');
    if (random(4) = 1) then
    begin
      MMouse(377,219,300,300);
    end; 
  end else
  begin
    GetMousePos(x,y);
    Mouse(x,y,0,0,true);
    if (random(4) = 1) then
    begin
      MMouse(377,219,300,300);
    end;
  end;
  writeln('[Power Miner] Found ore.');
  waitRR(1500, 1900);
  if random(33) = 1 then
  begin
    MouseBox(563, 172, 589, 200, ClickLeft);//stats 
    MouseBox(680, 210, 732, 235, MoveTo);
    waitRR(1, 999);
    if random(4) = 1 then
    begin
      MouseBox(680, 210, 732, 235, MoveTo);  
    end;
    if (style = 'Extremely Focused') then
    begin
      waitRR(999, 2345);  
    end else
    begin
      waitRR(999, 9999);
    end;
    MouseBox(631, 174, 655, 198, ClickLeft);//inv  
  end else
  begin
    if (style = 'I AFK a ton') then
    begin
      if random(5) = 1 then
      begin
        MMouse(-50,-50,40,40);
        waitRR(1234, 10000);
      end;  
    end;
    if (style = 'Focused but I AFK sometimes') then
    begin
      if random(10) = 1 then
      begin
        MMouse(-50,-50,40,40);
        waitRR(1234, 10000);
      end; 
    end;
  end;  
end;

procedure AlterSearchArea;
begin
  if (topleft2X = 0) then
  begin
    searchLx := topleftX;
    searchLy := topleftY;
    searchRx := botrightX;
    searchRy := botrightY;
    exit;
  end;
  if (searchLx = topleftX) then
  begin
    searchLx := topleft2X;
    searchLy := topleft2Y;
    searchRx := botright2X;
    searchRy := botright2Y;
    writeln('[Power Miner] Looking in area2 now.');
    exit;
  end;
  if (searchLx = topleft2X) then
  begin
    searchLx := topleftX;
    searchLy := topleftY;
    searchRx := botrightX;
    searchRy := botrightY;
    writeln('[Power Miner] Looking in area1 now.');
    exit;
  end;   
end;

procedure FindOre;
var
 x,y: Integer;
begin
 if not(isAnimating()) then
 begin
   AlterSearchArea;
   ColorToleranceSpeed(2);
   SetColorspeed2Modifiers(xxHue, xxSat);  
   if FindColorTol(x, y, xxColor, searchLx, searchLy, searchRx, searchRy, xxTol) then
   begin
     MMouse(x, y, 3, 3);
     waitRR(30,100);
     if UpTextContains('Mine') then
     begin
       MineOre;
       waitRR(123, 456);
     end else
     begin
       CudntFind;
       FindOre;
     end;

   end else
   begin
     CudntFind;
   end;
 end else
 begin
   if random(25) = 1 then
   begin
     GetMousePos(x,y);
     MMouse(x,y,155,155);
     waitRR(123, 1234);  
   end;
   if (style = 'I AFK a ton') then
   begin
     waitRR(123, 7777);  
   end; 
   if (style = 'Extremely Focused') then
   begin
     waitRR(123, 456);   
   end; 
 end; 
end;

procedure ClosedForm;
begin
  ShowMessage('Bot terminated!');
  TerminateScript;
  ClearDebug;
end;

procedure StartForm;
begin
  Form1_1_SafeInit;
  if Form1_1_SafeShowModal then
  begin
    FreeForm(Form1_1);
  end else
  begin
    ClosedForm;
    FreeForm(Form1_1);
  end;
end;

procedure SetupEverything;
begin
  SetupOSI;
  SetupOreColors;
  //SetupConfig;
  SetupSearch1;
  SetupSearch2;
    searchLx := topleftX;
    searchLy := topleftY;
    searchRx := botrightX;
    searchRy := botrightY;
  MouseBox(631, 174, 655, 198, ClickLeft);//inv 
end;

function TempInvFull: Boolean;
var
  x,y : Integer;
begin
   ColorToleranceSpeed(2);
   SetColorspeed2Modifiers(0.06, 0.14);  
   if FindColorTol(x, y, 4086127, 691, 434, 720, 457, 8) then
   begin
     result := true;  
   end else
   begin
     result := false;
   end;
end;

procedure ShiftDropAll;
var
  i : Integer;
  itms : TIntegerArray;
begin
  writeln('[Power Miner] Dropping all ores.');
  itms := GetDropPattern(random(6));
  VKeyDown(16);
  for i := 0 to 27 do
     begin
     if (itms[i] = pickSlot) then Continue;
     MouseBox(GetInvSlotBounds(itms[i]).X1, GetInvSlotBounds(itms[i]).Y1, GetInvSlotBounds(itms[i]).X2, GetInvSlotBounds(itms[i]).Y2, ClickLeft);      
     end;
  VKeyUp(16);
end; 

procedure Bot;
begin
  repeat
    FindOre;
  until TempInvFull;
  oresMined := oresMined + 28;
  writeln('[Power Miner] Inventory is full.');
  ShiftDropAll;
  ShowStats;  
end;



begin
  StartForm;
    
  SetupEverything;
  oresMined := 0;
  writeln('[Power Miner] Started at ' + TimeToStr(Time));
  repeat
    Bot;  
  until TheComputerCatchesOnFire;
  
end.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...