PDA

View Full Version : How To Make A Simple PowerMiner



Blumblebee
12-10-2008, 11:12 PM
How To Make A Simple PowerMiner

+rep if you like it

Table Of Contents

Introduction
Creating the Script
Failsafes
Extra's
Tips and tricks





Introduction

Ok, So you think you know a thing or two about scripting, but not sure how to impliment those ideas into an actual script? This Tutorial will contain, Cases, Arrays, strings, for-do loops, while loops, antiban, antirandoms, and more! We'll be putting all those ideas together into one basic script. I'll try to go slow, and explain things the best that i can. So, lets get started.


Creating The Script

First off all, you must aways add srl to any script, so we'll start with that.
program New;
{.include SRL/SRL.scar}

begin
SetupSRL;
end.

is what your script should now be looking like. So, First of all, We better get some declare players in there eh? so lets make our script look something like this...

program New;
{.include SRL/SRL.scar}

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

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

begin
SetupSRL;
end.

Now we're rolling, you can add more players if you like, but im too lazy :p Alright, so now we've got that, lets toss in an antiban now. so under declare players, we want to create a new procedure, called antiban; (Dur) lets amke it ook something like this...
procedure AntiBan;
begin
if (not (LoggedIn)) then
Exit;
case Random(60) of
0: RandomRClick;
1: GameTab(1 + Random(12));
2: PickUpMouse;
3: RandomMovement;
4: BoredHuman;
end;
end;

thats a very simple antiban, most of which the procedures are quite self explainitory, RandomRClick, obiously, it rightclicks somewhere on the rs screen. Gametab(1 + Random(12)); wil go to one of the tabs outside the inv, we added a random on it, so it goes to a random tab. PickUpMouse, just moves the mouse around a bit, RandomMovement, moves the camera angles around, and bored human combines alot of those functions. (That was wordy, I apologize). Remember, theres tons of things you can do instead for an antiban. Hoverskill, mmouse(X + Random(250, Y + Random(250, 8, 8) something like that. (hoverskills parameters arent listed, if your interested in it, look in antiban.scar to find the parameters).

Mmkay, so next, i always like to do my antirandom procedure. But your going, hey blumblebee, all you gotta do is findnormalrandoms; even we know that! Well, I always like to add a few things to it, so i make a procedure, something like...

procedure FindRandoms;
begin
FindNormalRandoms;
if FindFight then
RunAway('n', True, 1, 3000);
end;

lets break it down Runaway now shall we. So pretty much, the procedure is best explained with this.{******************************************** ***********************************
procedure RunAway(dir: string; RunFar: Boolean; Action, WaitTime: Integer);
By: nielsie95 modified by ZephyrsFury
Description: Runs away in minimap related direction, based on north.
Dir can be 'N', 'E', 'S', 'W' or an angle in degrees (145, 93, 180, etc).
RunFar will run further than normal.
Action can be either 1, 2 or 3.
1: RunAway + Wait(WaitTime) + RunBack
2: RunAway + Wait(WaitTime)
3: RunBack
Note: WaitTime is in milliseconds!
************************************************** *****************************}

but explaining for our sake, 'n' is the direction we chose to run, 1 is the action we want to use (read above if your not understanding), and 3000 is our wait time, once we get away from the fight, if a fighting random is ever to occur.

Now then, lets continue.

you script should be looking something like this now.

program New;
{.include SRL/SRL.scar}

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

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

procedure AntiBan;
begin
if (not (LoggedIn)) then
Exit;
case Random(60) of
0: RandomRClick;
1: GameTab(1 + Random(12));
2: PickUpMouse;
3: RandomMovement;
4: BoredHuman;
end;
end;

procedure FindRandoms;
begin
FindNormalRandoms;
if FindFight then
RunAway('n', True, 1, 3000);
end;

begin
SetupSRL;
end.

Alrighty, lets make a kick ass mining procedure now! I always like to use srl functions, and for this we certainly could, but for the sake of understanding, and learning purposes we'll make this completly from scratch.


procedure MineOre;
var
X, Y: Integer;
begin
if FindColorSpiral(X, Y, RockColor, MSX1, MSY1, MSX2, MSY2) then
begin
mmouse( x, y, 4, 4 );
wait(80+rand0m(60));
if isuptext('ine') then
begin
GetMousePos(X, Y);
Wait(50+random(50));
Mouse(X, Y, 4, 4, True);
end;
end;
end;


very simple, yet effective. However, what if we dont want to just mine one color (this one is iron btw). This is where our knowledge of cases and global vars comes in handy! First, lets make a global variable, which is located at the top of the script and call it rockcolor, and set it to an integer. Should look something like...

var
RockColor: integer;

But we're not done, we want the user to choose what rock they want to mine, thus we have a const to make! under the var, make a constant called RockType, looking something like this const
RockType = '';

alright, so we got that layed out (Phew!) so now lets get back to buisness. Make a procedure called SetRock, to which we're going to impliment our skills with cases! Now then, lets drop something like this,

procedure SetRock;
begin
case lowercase(RockType) of
'copper':
'tin':
'iron':
end;
end;

so lets break it down again, we used our const "RockType" in a case, and in that case, we gave the options of copper, tin, and iron.
case lowercase(RockType) of
I dont get it blumblebee :/ why lowercase? We use lowercase() to allow us to make any string in all lowercases. This makes filling the script in easier for the user, as it doesnt require perfect capitalization when filling in the script.

So now we have our case, but nothing is in it! So lets get on that. Remeber that RockColor var we set before, wel its time to impliment that into our script, so lets enter this into the script,

procedure SetRock;
begin
case lowercase(RockType) of
'copper': RockColor := 4225488;
'tin': RockColor := 8027016;
'iron': RockColor := 2371405;
end;
end;

Awesome! Now that we have that set, only one last thing to adjust. Our mining procedure still isnt adjustable, so we must remove the current color we have in it, and set RockColor as our new color!

procedure MineOre;
var
X, Y: Integer;
begin
if FindColorSpiral(X, Y, RockColor, MSX1, MSY1, MSX2, MSY2) then
begin
mmouse( x, y, 4, 4 );
wait(80+rand0m(60));
if isuptext('ine') then
begin
GetMousePos(X, Y);
Wait(50+random(50));
Mouse(X, Y, 4, 4, True);
end;
end;
end;


mhkay, so script lets look at the whole script, and see how this babys doing.

program New;
{.include SRL/SRL.scar}

var
RockColor: integer;

const
RockType = '';

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

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

procedure AntiBan;
begin
if (not (LoggedIn)) then
Exit;
case Random(60) of
0: RandomRClick;
1: GameTab(1 + Random(12));
2: PickUpMouse;
3: RandomMovement;
4: BoredHuman;
end;
end;

procedure FindRandoms;
begin
FindNormalRandoms;
if FindFight then
RunAway('n', True, 1, 3000);
end;

procedure SetRock;
begin
case lowercase(RockType) of
'copper': RockColor := 4225488;
'tin': RockColor := 8027016;
'iron': RockColor := 2371405;
end;
end;

procedure MineOre;
var
X, Y: Integer;
begin
if FindColorSpiral(X, Y, RockColor, MSX1, MSY1, MSX2, MSY2) then
begin
mmouse( x, y, 4, 4 );
wait(80+rand0m(60));
if isuptext('ine') then
begin
GetMousePos(X, Y);
Wait(50+random(50));
Mouse(X, Y, 4, 4, True);
end;
end;
end;


begin
SetupSRL;
end.

damn thats sexy. Alright, so we have antirandoms, antiban, mining, and rock choosing. But, whats the point of Antirandoms and Antiban if we dont use them!? So lets make a whileMining Procedure, and make it look a little something like this,

procedure WhileMining;
var
C: Integer;
begin
if not (LoggedIn) then
Exit;
MarkTime(C);
begin
While (TimeFromMark(c) < MaxWait) do
begin
FindRandoms;
Wait(100+random(50));
AntiBan;
Wait(500+random(500));
end;
end;
end;

woah Blumblebee WTF dude, that makes NO sense. So Lets break it down...

procedure WhileMining;
var
C: Integer;
begin
if not (LoggedIn) then
Exit;
MarkTime(C); {Marks Time, So pretty much starts counting }
begin
While (TimeFromMark(c) < randomrange(4000, 8000) do {read below for a full explaination}
begin
FindRandoms;
Wait(100+random(50));
AntiBan;
Wait(500+random(500));
if FindBlackChatMessage('anage') then
Exit; {If it finds the chat message 'managed to mine an ore' then it exits the procedure, so it doesnt wait round all day }
end;
end;
end;

alright, so im guessing the While - Do part is confusing you eh. So lets take a look into it.

While (TimeFromMark(c) < 6000 do

remeber how we marked the time above it? It starts counting, and while the time its been counting is lower than 6000 (ms, so 6 seconds), it preforms everything underneath it ( in the procedure ), Including our antiban and randoms procedure.

So, now we can mine the ores, antiban, findrandoms, and have a sexy looking script, but we're still mising something...We need to drop all those ore's you'll be raking in. We could Simply put in, DropAll; , but what if someone has a pickaxe in their inv! We dont want that, so lets make it that we dont drop the first inv slot.

procedure Ore;
var
i: Integer;
begin
if not (LoggedIn) then Exit;
FindRandoms;
Gametab(4);
for i := 2 To 28 Do
begin
FindRandoms;
If ExistsItem(i) then
DropItem(i);
end;
end;

Alrighty, so again, we'll break it down, more indepth this time though.

for i := 2 To 28 Do { I is the variable we set, the for do loop we make i from being set from 2 to 28
(not 1 so that it wont go to the first inv slot) }
begin
FindRandoms;
If ExistsItem(i) then {remeber i is an integer (number) from 2 to 28, so it looks if theres something in that slot, }
DropItem(i); { if somethings there, then it drops the item }
end;

im hoping that explained a little, if i need to expand on it more, lemme know.

Now, its time for the mainloop, there's many ways to do them, but we're doing mine, so deal with it.

So lets mae a procedure called MainLoop, and lets throw some shit in it,

procedure MainLoop;
begin
if not LoggedIn then
LogInPlayer;
SetRock;
repeat
repeat
MineOre;
WhileMining;
until InvFull;
if invfull then
begin
DropOre;
end;
Until False
end;

now that we got that outa the way, in the begin end. (main execution lines) lets add our mainloop, making it look like...

begin
SetupSRL;
MainLoop;
end.

why did we make the mainloop procedure then? IMO it looks nicer, and easier to find to edit :)

so finally, our script should look like this...

program New;
{.include SRL/SRL.scar}

var
RockColor: integer;

const
RockType = '';

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

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

procedure AntiBan;
begin
if (not (LoggedIn)) then
Exit;
case Random(60) of
0: RandomRClick;
1: GameTab(1 + Random(12));
2: PickUpMouse;
3: RandomMovement;
4: BoredHuman;
end;
end;

procedure FindRandoms;
begin
FindNormalRandoms;
if FindFight then
RunAway('n', True, 1, 3000);
end;

procedure SetRock;
begin
case lowercase(RockType) of
'copper': RockColor := 4225488;
'tin': RockColor := 8027016;
'iron': RockColor := 2371405;
end;
end;

procedure MineOre;
var
X, Y: Integer;
begin
if FindColorSpiral(X, Y, RockColor, MSX1, MSY1, MSX2, MSY2) then
begin
mmouse( x, y, 4, 4 );
wait(80+rand0m(60));
if isuptext('ine') then
begin
GetMousePos(X, Y);
Wait(50+random(50));
Mouse(X, Y, 4, 4, True);
end;
end;
end;

procedure WhileMining;
var
C: Integer;
begin
if not (LoggedIn) then
Exit;
MarkTime(C);
begin
While (TimeFromMark(c)) < 6000 do
begin
FindRandoms;
Wait(100+random(50));
AntiBan;
Wait(500+random(500));
if FindBlackChatMessage('anage') then
Exit;
end;
end;
end;

procedure DropOre;
var
i: Integer;
begin
if not (LoggedIn) then Exit;
FindRandoms;
Gametab(4);
for i := 2 To 28 Do
begin
FindRandoms;
If ExistsItem(i) then
DropItem(i);
end;
end;

procedure MainLoop;
begin
if not LoggedIn then
LogInPlayer;
SetRock;
repeat
repeat
MineOre;
WhileMining;
until InvFull;
if invfull then
begin
DropOre;
end;
Until False
end;

begin
SetupSRL;
MainLoop;
end.

This script was for learning purposes, and if it doesnt work amazing, it was never meant to, so please dont tell me it only ran 1 load or something :/


Failsafes

Alright, so we're done our script, but if we look everything is procedures, and if stuff fails, the script isnt stopping. Thats why we add failsafes! functions, nexplayer, if not loggedin, ect are all ways to add failsafes.

Due to absolute lazyness, I'm going to show a coupld of examples with the script, but creating failsafes for the whole script is something im not doing.

so lets make our mining procedure with failsafes!!!!

function MineOre: Boolean; {Made this a Boolean, so we can use result as True/False}
var
X, Y, Tries: Integer;
begin
if Tries >= 5 then Nextplayer(False); {if the tries integer is over 5, it goes to the nexxt player}
if FindColorSpiral(X, Y, RockColor, MSX1, MSY1, MSX2, MSY2) then
begin
MMouse( x, y, 4, 4 );
wait(80+random(60));
if isuptext('ine') then
begin
GetMousePos(X, Y);
Wait(50+random(50));
Mouse(X, Y, 4, 4, True);
Result := True;
end;
if not Result then Inc(Tries); {Increases Tries (Tries + 1 in other words) }
end;
end;

Wow thats cool huh. So As you can see, failsafes allow for multiplayer, aswell as make the script run smoother.

(Will add more examples upon request)


Extras

wanna make a ballin' script. Set yourself apart from other scripters, well many extra features can make your script just awesome.

Things like autoresponders, proggie reports, gas detectors, broken pick detectors, and other things can make your script look nicer, and function better.

So, if we want to add a progress report to our script, theres a few things we need to add. First of all, we need to add a progressreport procedure! Lets make it simple yet stylish, and just overal sexy :P.

procedure ProgressReport;
begin
WriteLn('[Insert Name here] presents: The Awesome PowerMiner');
WriteLn('========================================= ==========');
WriteLn('Script Ran For: ' + TimeRunning);
WriteLn('Ores Mined/Dropped: ' + IntToStr(Mined));
WriteLn('========================================= ==========');
end;

erm hold up, whats intostr(Mined)? And Wtf is Mined!?

That just converts an integer into the string, and as for mined, thats a variable we havent added yet (but we're going to). So lets add another integer alongside RockColor, making it look something like

var
RockColor, Mined: integer;

but its not increasing ever? whats the point of that? So lets head over to our mainloop, and after dropores; add this,

procedure MainLoop;
begin
if not LoggedIn then
LogInPlayer;
SetRock;
repeat
Repeat
MineOre;
WhileMining;
until InvFull;
if invfull then
begin
DropOre;
Mined := Mined + 27;
end;
Until False
end;

so everytime the script drops ores, it increases mined by 27! (remeber because we dont drop slot 1).

(More Extras Upon Request)


Tips And Tricks

Alrighty, Tips and Tricks Time!

Tip 1: Try to keep Global Variables to a minimum, they slow the script down, and look nasty :( keep things as local as possible (looking back on our mining procedure, remeber how after the procedure mineore; there was a var X, Y: Integer. Those were Local Vars). Gobal vars should only be used for variables that need to be brought over from one porceudre to the next, like or mined and rockcolor variables, notice how they were used in more than one procedure.

Tip 2: Ask Questions! Rember, asking for help doesnt mean you cant script, or your not smart, it shows your abitily to learn. so Ask, Ask, Ask!!!

Tip 3: Standards are super important! Dont know what standards are...? Look in Bebe's tut kuz im too lazy :D.

Tip 4: Failsafes!!!!! Remeber, they are one of the most important parts of scripting, without them, we'd be nothing.




Well that was a mouthful, so if you learned something from that, then let me know :) if not, gimmi some feeback on what i didnt teach well, and ill expand. Its been swell, I learned alot (not really) and i hope you did too.

-Blumblebee

noidea
12-10-2008, 11:18 PM
NOOO! The your mineore procedure is messed up. here
procedure MineOre;
var
X, Y: Integer;
begin
if FindColorSpiral(X, Y, RockColor, MSX1, MSY1, MSX2, MSY2) then
begin
mmouse( x, y, 4, 4 );
wait(80+rand0m(60));
if isuptext('ine') then
begin
GetMousePos(X, Y);
Wait(50+random(50));
Mouse(X, Y, 4, 4, True);
end;
end;
end;

Blumblebee
12-10-2008, 11:19 PM
oops :/ haha mah bad, added, thanks for the save :p

D1zl3
12-10-2008, 11:35 PM
Pretty good, very descriptive. Expect more power miners now:P

Blumblebee
12-11-2008, 12:23 AM
Pretty good, very descriptive. Expect more power miners now:P

Thanks, and i hope so, means people are actually reading this :)

noidea
12-11-2008, 12:53 AM
Can you fix the MineOre procedure under Fail safes, just for nub safety. Thanks!

Blumblebee
12-11-2008, 12:55 AM
sigh im really lazy atm, but ill certainly do it :/

Edit: Done.

Exuvium
12-11-2008, 01:35 AM
So would you recommend this for a leacher? Lol. I just joined today and have been reading up on Scar. not yet into the programming yet. I've noticed alot of stuff like you can program wat ores to mine. is there a way to make it run to bank and bank the ores? and how about to go directly to a location? maybe through a teleport into rune essense?

D1zl3
12-11-2008, 03:56 AM
So would you recommend this for a leacher? Lol. I just joined today and have been reading up on Scar. not yet into the programming yet. I've noticed alot of stuff like you can program wat ores to mine. is there a way to make it run to bank and bank the ores? and how about to go directly to a location? maybe through a teleport into rune essense?

There are tons of miners that will bank, you just have to wait 1 week. Dont be a leach though.

Blumblebee
12-11-2008, 03:59 AM
walking is more complicated, so i just made my tut the very basics. If your interested in learning walking (ie. radial, ddtm, ect) then ook in intermediate tuts, and check to ZephryFurys.

lax_player16
12-11-2008, 08:10 AM
thanks i didnt think i wanted to try to script until reading this

Blumblebee
12-14-2008, 12:33 AM
thats good haha, im glad i inspired you (or you wanted to spam to 10 posts XD)

drum4crimson
12-14-2008, 02:10 AM
ok i was following along until the very end it said you added the

begin
DropOre;
Mined := Mined + 27;

well that was in my script the whole time.
so am i missing something?
btw huge help i <3 failsafes!! =D

Blumblebee
12-14-2008, 08:16 AM
alright, so mined is a variable, thus we need to increase it to add to the porgress report. Mined := Mined +27.

(i think i acidentally had that in the script the whole time, nice catch :p)

but im thinking you get the point, ill fix that up now :p

drum4crimson
12-14-2008, 11:21 PM
okey dokey, mucho gracias ;)

tls
12-22-2008, 09:48 PM
you forgot to put
DeclarePlayers;
in the mainloop...

teh_lulz
06-08-2009, 08:53 AM
I went out looking for a tutorial on MarkTime; and TimeFromMark; I didn't find one but that section of this tutorial explained it perfectly. I'm using it to time my antiban procedures between each of the course obstacles with my Ape Atoll Agility script, thanks Butt Pirate!

darkmind63
06-28-2009, 07:39 PM
Thank you for the nice tutorial.
very good i learned a lot from it :D

brad734
07-19-2009, 04:17 AM
correct me if im wrong but you said


procedure MineOre;
var
X, Y: Integer;
begin
if FindColorSpiral(X, Y, RockColor, MSX1, MSY1, MSX2, MSY2) then
begin
mmouse( x, y, 4, 4 );
wait(80+rand0m(60));
if isuptext('ine') then
begin
GetMousePos(X, Y);
Wait(50+random(50));
Mouse(X, Y, 4, 4, True);
end;
end;
end;

the


wait(80+rand0m(60));

should be


wait(80+random(60));

?? the random was spelt rand0m with an 0 not an o.:D:D