SRL Archive - First Scripts

first simple powerminer -- comments?


zildjohn01

2008-05-02 21:22:29

Here it is, first draft, I ran it through one load (on tin) and it worked okay. Didn't get any randoms to test tho. Let me know what you think. If it fails at least try changing my colors before complaining :D

Instructions: Just locate your character anywhere where the new (veined) rocks are visible, and sit back and enjoy. Doesn't matter where the pick is. I tested it with tin in the Varrock east mines.

Uncommon feature – drops ore by DTM instead of blindly 1 through 28. I had a bunch of gems and money and crap in my inv and it kept those but dropped the ore. (h)

EDIT: second run through it failed to drop two of the ores… hmm. still no randoms.

{*******************************************************************************
*************************** zildjohn01's Powerminer ****************************
********************************************************************************
* Weapon of choice: SCAR 3.15 / SRL 4.16 *
********************************************************************************
* Description: *
* The ubiquitous obligatory n00b powerminer *
********************************************************************************
* Instructions: *
* Low detail, 32-bit, highest brightness, crosshairs * *
* Set players and consts. *
* Run and enjoy. *
*******************************************************************************}

program PowerMiner;
{.include SRL\SRL.scar}

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

Players[0].Name := 'ialmostforgot';
Players[0].Pass := 'toerase';
Players[0].Nick := 'myrealaccountlol';
Players[0].Strings[0] := 'tin'; // type of rock to mine
Players[0].Strings[1] := 'N'; // direction to run during fight
Players[0].Integers[0] := 5; // loads per logon
Players[0].Active := true;

CheckUserNicks;
end;

const
TotalRounds = 5;
{********** D O N ' T T O U C H B E L O W T H I S L I N E ***********}
SYSTEM_LAG = 1000; // higher for slower PCs
DEBUGGING = true; // useless crap to clutter debug box
ORE_TIN = $9898a4; ORE_COPPER = $48719d; ORE_IRON = $2d3b60;

var OreDTM : Integer;

procedure Outs(s : String); begin
writeLn('Player ' + IntToStr(CurrentPlayer) + ': ' + s);
end;

procedure OutD(s : String); begin
if(DEBUGGING) then Outs(s);
end;

procedure Anti; begin
LampSkill := 'mining';
FindNormalRandoms;
if FindFight then
RunAway(Players[CurrentPlayer].Strings[1], false, 3, 10000 + random(8000));
end;

function FirstFreeInvSlot : Integer; begin
for Result := 1 to 28 do
if not ExistsItem(Result) then
Exit;
Result := 0; // my script handles this condition elsewhere
end;

function AllInactive : Boolean;
var i : Integer; begin
Result := true;
for i := 0 to HowManyPlayers do
if Players[i].Active then
Result := false;
end;

function OreInSlot(i : Integer) : Boolean;
var x, y : Integer; b : TBox; begin
if not ExistsItem(i) then Exit;
b := InvBox(i);
Result := FindDTM(OreDTM, x, y, b.x1, b.y1, b.x2, b.y2)
end;

procedure DropOres;
var i : Integer; begin
OutD('Dropping all ore.');
for i := 1 to 28 do
if OreInSlot(i) then begin
OutD('Dropping inv #' + IntToStr(i));
DropItem(i);
end;
end;

function DoPlayer : Boolean;
var x, y, i, oreColor, failures, slot : Integer; begin
case Lowercase(Players[CurrentPlayer].Strings[0]) of
'tin': oreColor := ORE_TIN;
'copper' : oreColor := ORE_COPPER;
'iron' : oreColor := ORE_IRON;
else begin
Result := false;
Outs('Unknown rock type ''' + Players[CurrentPlayer].Strings[0] + '''.');
Exit;
end end;

//DropOres; // start fresh
if InvFull then begin
Outs('No room for more ore. Lighten yer load.');
Result := false;
Exit;
end;

repeat
repeat
slot := FirstFreeInvSlot;
OutD('First free slot: ' + IntToStr(slot));
if FindColorSpiralTolerance(x, y, ORE_TIN, MSX1, MSY1, MSX2, MSY2, 10) then begin
MMouse(x, y, 20, 20);
if not IsUpTextMultiCustom(['ine', 'ock']) then // Mine Rocks
MMouse(x, y, 5, 5);
if not IsUpTextMultiCustom(['ine', 'ock']) then // Mine Rocks
MMouse(x, y, 2, 2);
if not IsUpTextMultiCustom(['ine', 'ock']) then // Mine Rocks
MMouse(x, y, 0, 0);
if IsUpTextMultiCustom(['ine', 'ock']) then begin // Mine Rocks
//GetMousePos(x, y);
OutD('Clicking rock...');
repeat
case random(100) of
0: begin
Mouse(x, y, 0, 0, false);
ChooseOption('ospec'); // Prospect
Wait(2300 + random(1200));
if random(1) = 0 then begin // oops i meant "mine"
Mouse(x, y, 0, 0, false);
ChooseOption('ine');
end else
Mouse(x, y, 0, 0, true);
end;
1, 2, 3, 4, 5, 6: begin
Mouse(x, y, 0, 0, false);
ChooseOption('ine'); // Mine
end else
Mouse(x, y, 0, 0, true);
end;
Wait(1000 + random(500));
Anti;
for i := 0 to 8 + random(3) do begin
Wait(800 + random(400));
if ExistsItem(slot) then
Break;
end;
until ExistsItem(slot);
OutD('Ore successfully mined.');
end else begin
Outs('failed to click on ore...');
failures := failures + 1;
Wait(2000 + random(3000));
end;
end else begin
Outs('failed to find ore...');
failures := failures + 1;
Wait(5000 + random(4000));
end;
if(failures > 2) then begin
Outs('failed 3 times, switching players');
Result := false;
Exit;
end;
until InvFull;
DropOres;
Players[CurrentPlayer].Integers[90] := Players[CurrentPlayer].Integers[90] + 1;
if Players[CurrentPlayer].Integers[90] >= Players[CurrentPlayer].Integers[0] then begin
Outs('Finished all loads. Next account.');
NextPlayer(true);
Exit;
end else
Outs('Load finished. Keep on truckin...');
until false;
end;

begin
SetupSRL;
OreDTM := DTMFromString('78DA637460626008646440058C48249036264' +
'28D2D508D070135EE40352E04D40402D5781350E30B541346408D' +
'0B504D34A61A11643536F8CD61036200E7C904E0');
ClearDebug;
writeLn('************* zildjohn01''s Powerminer **************');
DeclarePlayers;

ActivateClient;
Wait(SYSTEM_LAG);
if not LoggedIn then LoginPlayer;

repeat
Wait(SYSTEM_LAG);
if not LoggedIn then NextPlayer(false);
NextPlayer(DoPlayer);
until AllInactive;
Outs('Future proggy here');
end. // yeah I should have freed the DTM, i know.....

Scias307

2008-05-03 19:31:22

you know i actually tested it out, and it was a awsome script (for a first i mean, but what do you expect eh?) but it ran very well, i couldn't get a prog report, but overall nice, i did get one random event, and it failed to do it, i got pinball, but overall a very good script…

zildjohn01

2008-05-05 20:12:06

Thanks. No other comments? Is it that bad? I'm gonna work on it more (restructure, add proggies, etc) once exams are over. Either that or start something completely new lol

Also, should I attach the script instead of pasting it in the message?

Lancelot074

2008-05-05 21:26:36

repeat
case random(100) of
0: begin
Mouse(x, y, 0, 0, false);
ChooseOption('ospec'); // Prospect
Wait(2300 + random(1200));
if random(1) = 0 then begin // oops i meant "mine"
Mouse(x, y, 0, 0, false);
ChooseOption('ine');
end else
Mouse(x, y, 0, 0, true);
end;
1, 2, 3, 4, 5, 6: begin
Mouse(x, y, 0, 0, false);
ChooseOption('ine'); // Mine
end else
Mouse(x, y, 0, 0, true);
end;
Wait(1000 + random(500));
Anti;
for i := 0 to 8 + random(3) do begin
Wait(800 + random(400));
if ExistsItem(slot) then
Break;
end;

So like 90% of the time the script won't click the rock?
You might wanna change that around.

Nava2

2008-05-06 16:29:25

Just some tips:

Couldn't this:
procedure Outs(s : String); begin
writeLn('Player ' + IntToStr(CurrentPlayer) + ': ' + s);
end;

procedure OutD(s : String); begin
if(DEBUGGING) then Outs(s);
end;

be:

procedure Outs(s : String); 
begin
if not Debugging then Exit;
writeLn('Player ' + IntToStr(CurrentPlayer) + ': ' + s);
end;

Just removed a procedure.


Just read the comments below:
begin
SetupSRL;
OreDTM := DTMFromString('78DA637460626008646440058C48249036264' +
'28D2D508D070135EE40352E04D40402D5781350E30B541346408D' +
'0B504D34A61A11643536F8CD61036200E7C904E0');
ClearDebug;
writeLn('************* zildjohn01''s Powerminer **************');
DeclarePlayers;

ActivateClient;
Wait(SYSTEM_LAG);
if not LoggedIn then LoginPlayer;

repeat
Wait(SYSTEM_LAG);
if not LoggedIn then NextPlayer(false);
NextPlayer(DoPlayer); // Confused...
until AllInactive; // Isn't this an infinite loop? if so.. thats a no no!
Outs('Future proggy here');
end. // yeah I should have freed the DTM, i know..... <- Glad you know it! :)

All in all, confused me a lot. Check your standards but I look forward to more from you. Your mining procedure confused the hell out of me… it seems jumbled.

Hope I helped and I'm using your idea of finding the ore to end the mining procedure… I didn't like using my waits :D.

Nava2

zildjohn01

2008-05-06 20:37:12

From: lancelot074
So like 90% of the time the script won't click the rock?
You might wanna change that around.


Where are you getting that from? Did you run it? Out of random(100), 1% is prospect (oops) then mine, 6% are right click mine, and the rest are left click.

From: Nava2
Just removed a procedure.

I'm actually gonna consolidate those both into procedure Outs(level : Integer, text : String). Some stuff needs to display even with debugging off.

NextPlayer(DoPlayer); // Confused...
DoPlayer returns true if successful, or false if lost/randomed/failed. So NextPlayer(true) if we're still good, NextPlayer(false) if lost etc. I haven't gotten lost yet (lol) but I'm pretty sure this works.

until AllInactive; // Isn't this an infinite loop? if so.. thats a no no!
It loops until all players are set to false. Is that still bad?

From: Nava2
All in all, confused me a lot. Check your standards but I look forward to more from you. Your mining procedure confused the hell out of me… it seems jumbled.

Hope I helped and I'm using your idea of finding the ore to end the mining procedure… I didn't like using my waits :D.


Yeah, I come from a background of other programming languages so delphi is still kinda weird for me, I'm still trying to squeeze C++ code into delphi syntax. Makes perfect sense to me :rolleyes: Anyways, I'm planning to break that up into more layers of procedures (along the lines of DoPlayer, MiningLoop, GetOneOre). Hopefully that'll be enough.

And hey, you can't steal my ideas! jk :D

P1nky

2008-05-06 20:54:35

here i standarded it ill look into it later sister is mad atm

{*******************************************************************************
*************************** zildjohn01's Powerminer ****************************
********************************************************************************
* Weapon of choice: SCAR 3.15 / SRL 4.16 *
********************************************************************************
* Description: *
* The ubiquitous obligatory n00b powerminer *
********************************************************************************
* Instructions: *
* Low detail, 32-bit, highest brightness, crosshairs * *
* Set players and consts. *
* Run and enjoy. *
*******************************************************************************}

Program PowerMiner;
{.include SRL\SRL.scar}

Procedure DeclarePlayers;
Begin
NumberOfPlayers(1);
CurrentPlayer := 0;

Players[0].Name := 'ialmostforgot';
Players[0].Pass := 'toerase';
Players[0].Nick := 'myrealaccountlol';
Players[0].Strings[0] := 'tin'; // type of rock to mine
Players[0].Strings[1] := 'N'; // direction to run during fight
Players[0].Integers[0] := 5; // loads per logon
Players[0].Active := true;

CheckUserNicks;
End;

Const
TotalRounds = 5;
{********** D O N ' T T O U C H B E L O W T H I S L I N E ***********}
SYSTEM_LAG = 1000; // higher for slower PCs
DEBUGGING = true; // useless crap to clutter debug box
ORE_TIN = $9898A4; ORE_COPPER = $48719D; ORE_IRON = $2D3B60;

Var OreDTM: Integer;

Procedure Outs(s: String); Begin
writeLn('Player ' + IntToStr(CurrentPlayer) + ': ' + s);
End;

Procedure OutD(s: String); Begin
If (DEBUGGING) Then Outs(s);
End;

Procedure Anti; Begin
LampSkill := 'mining';
FindNormalRandoms;
If FindFight Then
RunAway(Players[CurrentPlayer].Strings[1], false, 3, 10000 + random(8000));
End;

Function FirstFreeInvSlot: Integer; Begin
For Result := 1 To 28 Do
If Not ExistsItem(Result) Then
Exit;
Result := 0; // my script handles this condition elsewhere
End;

Function AllInactive: Boolean;
Var i: Integer; Begin
Result := true;
For i := 0 To HowManyPlayers Do
If Players[i].Active Then
Result := false;
End;

Function OreInSlot(i: Integer): Boolean;
Var x, y: Integer; b: TBox; Begin
If Not ExistsItem(i) Then Exit;
b := InvBox(i);
Result := FindDTM(OreDTM, x, y, b.x1, b.y1, b.x2, b.y2)
End;

Procedure DropOres;
Var i: Integer; Begin
OutD('Dropping all ore.');
For i := 1 To 28 Do
If OreInSlot(i) Then Begin
OutD('Dropping inv #' + IntToStr(i));
DropItem(i);
End;
End;

Function DoPlayer: Boolean;
Var x, y, i, oreColor, failures, slot: Integer; Begin
Case Lowercase(Players[CurrentPlayer].Strings[0]) Of
'tin': oreColor := ORE_TIN;
'copper': oreColor := ORE_COPPER;
'iron': oreColor := ORE_IRON;
Else Begin
Result := false;
Outs('Unknown rock type ''' + Players[CurrentPlayer].Strings[0] + '''.');
Exit;
End End;

//DropOres; // start fresh
If InvFull Then Begin
Outs('No room for more ore. Lighten yer load.');
Result := false;
Exit;
End;

Repeat
Repeat
slot := FirstFreeInvSlot;
OutD('First free slot: ' + IntToStr(slot));
If FindColorSpiralTolerance(x, y, ORE_TIN, MSX1, MSY1, MSX2, MSY2, 10) Then Begin
MMouse(x, y, 20, 20);
If Not IsUpTextMultiCustom(['ine', 'ock']) Then // Mine Rocks
MMouse(x, y, 5, 5);
If Not IsUpTextMultiCustom(['ine', 'ock']) Then // Mine Rocks
MMouse(x, y, 2, 2);
If Not IsUpTextMultiCustom(['ine', 'ock']) Then // Mine Rocks
MMouse(x, y, 0, 0);
If IsUpTextMultiCustom(['ine', 'ock']) Then Begin // Mine Rocks
//GetMousePos(x, y);
OutD('Clicking rock...');
Repeat
Case random(100) Of
0: Begin
Mouse(x, y, 0, 0, false);
ChooseOption('ospec'); // Prospect
Wait(2300 + random(1200));
If random(1) = 0 Then Begin // oops i meant "mine"
Mouse(x, y, 0, 0, false);
ChooseOption('ine');
End Else
Mouse(x, y, 0, 0, true);
End;
1, 2, 3, 4, 5, 6: Begin
Mouse(x, y, 0, 0, false);
ChooseOption('ine'); // Mine
End Else
Mouse(x, y, 0, 0, true);
End;
Wait(1000 + random(500));
Anti;
For i := 0 To 8 + random(3) Do Begin
Wait(800 + random(400));
If ExistsItem(slot) Then
Break;
End;
Until ExistsItem(slot);
OutD('Ore successfully mined.');
End Else Begin
Outs('failed to click on ore...');
failures := failures + 1;
Wait(2000 + random(3000));
End;
End Else Begin
Outs('failed to find ore...');
failures := failures + 1;
Wait(5000 + random(4000));
End;
If (failures > 2) Then Begin
Outs('failed 3 times, switching players');
Result := false;
Exit;
End;
Until InvFull;
DropOres;
Players[CurrentPlayer].Integers[90] := Players[CurrentPlayer].Integers[90] + 1;
If Players[CurrentPlayer].Integers[90] >= Players[CurrentPlayer].Integers[0] Then Begin
Outs('Finished all loads. Next account.');
NextPlayer(true);
Exit;
End Else
Outs('Load finished. Keep on truckin...');
Until false;
End;

Begin
SetupSRL;
OreDTM := DTMFromString('78DA637460626008646440058C48249036264' +
'28D2D508D070135EE40352E04D40402D5781350E30B541346408D' +
'0B504D34A61A11643536F8CD61036200E7C904E0');
ClearDebug;
writeLn('************* zildjohn01''s Powerminer **************');
DeclarePlayers;

ActivateClient;
Wait(SYSTEM_LAG);
If Not LoggedIn Then LoginPlayer;

Repeat
Wait(SYSTEM_LAG);
If Not LoggedIn Then NextPlayer(false);
NextPlayer(DoPlayer);
Until AllInactive;
Outs('Future proggy here');
End. // yeah I should have freed the DTM, i know.....

go ahead rep me

Nava2

2008-05-06 21:58:49

From: P1NKY
here i standarded it ill look into it later sister is mad atm



go ahead rep me


You over standardized it. Four spaces!?

Back on topic:

I did use your idea btw. Works well, but I wrote my own procedure etc. The until all players false should probably have more failsafes. The more Failsafes the better! It makes your script run forever… or close to it ;).

Try using a max time procedure or something along those lines to end your script as well as having the option of all players false.

I set up a whole procedure dedicated to failsafes:

DO NOT USE WITH OUT CREDITING:
{*******************************************************************************
function FailSafes:Boolean;
By: Nava2
Description: Checks if maximum values have been met. Returns true if they are met.
Script then writes Final Player Report and exits;
Also checks for minor failsafes:
Checks if Logged in;
Checks FindPick;
*******************************************************************************}

function FailSafes:Boolean;
begin
NDB('FailSafes (Begin)');
Result := False;

if (TMaxTime > 0) and (TMaxTime <= ((GetTimeRunning div 1000) div 60)) then
begin
Players[CurrentPlayer].Loc := 'Maximum Time Reached.';
NDB('FailSafes (Time)');
FinalPlayerReport;
Result := True;
Exit;
end;

if (TMaxLoads > 0) and (TMaxLoads <= Loads) then
begin
Players[CurrentPlayer].Loc := 'Maximum Loads Completed.';
NDB('FailSafes (Loads)');
FinalPlayerReport;
Result := True;
Exit;
end;

if (TMaxOres > 0) and (TMaxOres <= Ores) then
begin
Players[CurrentPlayer].Loc := 'Maximum amount of Ores mined.';
NDB('FailSafes (Ores)');
FinalPlayerReport;
Result := True;
Exit;
end;

if not LoggedIn then
begin
Players[CurrentPlayer].Loc := 'Not logged in.';
NDB('FailSafes (LogIn)');
LoginPlayer;
Result := True
while not LoggedIn do Wait(500+random(250));
if LoggedIn then Result := false;
Exit;
end;

if not FindPick then
begin
Players[CurrentPlayer].Loc := 'Could not attach pick head.';
NDB('FailSafes (FindPick)');
FinalPlayerReport;
Result := True;
Exit;
end;

end;

I just posted that as an example of what works; please don't use that. Feel free to model one after that and credit! :) Also, look at the standards.. Most are covered in there I believe.

Good Luck!

Nava2