PDA

View Full Version : Scripting: Starting a Step Ahead



Sir R. M8gic1an
01-04-2009, 12:36 PM
Welcome, welcome all

Starting a Step Ahead!

I'm sure we all would like to script faster. I know i would, spend fewer days on making one script, getting there faster. Well, just very recently i learnt we can. All those repetitive things such as random finding, antiban, multiplayer, they're mostly the same code in all scripts, but it's still a pain in the ass to copy and paste it around. So how can we do it?

http://i39.tinypic.com/2ebxzk9.jpg

that is perhaps one of the most useful things in scar. Save as Default, allows you to make a script, and whenever you open scar, that's the script that shows up.

So, what could we put as Default? well, Antiban, AntiRandoms, DeclarePlayers, ...

Maybe More, what separates two perfect woodcutters? it's features. Maybe we could add those in?

WorldSwitcher, Resting, Progress Report, Debug, Intro, AutoResponder.

and that's already a big part of the script to have ahead of you. Maybe you dont know how to generalize these things... let me show you my own examples.


{================================================= =============================]
[================================================== ============================]
[ RM Default Script ]
[ By: Rasta Magician ]
[================================================== ============================]
[ Features ]
[================================================== ============================]
[ 1. Debug ]
[ 2. AntiRandoms ]
[ 3. AntiBan ]
[ 4. Multiplayer ]
[ 5. Resting ]
[ 6. Progress Report ]
[ 7. Local Control ]
[ 8. Responder ]
[ 9. ]
[================================================== ============================]
[ Description ]
[================================================== ============================]
[ ]
[ ]
[ ]
[ ]
[ ]
[================================================== ============================]
[ How To Use ]
[================================================== ============================]
[ ]
[ ]
[ ]
[================================================== ============================]
[ Credits ]
[================================================== ============================]
[ SRL Team ]
[================================================== ============================]
[ RM Script by Rasta Magician ]
[================================================== ============================]
[================================================== ============================}


that took me a heel lot of a time to make! but now i will always have it, and my scripts will always have an introduction this good, no matter how lazy i feel!

Right after that i setup all the constants that i will need:

program RMScript;
{.include srl/srl.scar}

Const
WorkTime = (10*60*1000); //10 mins
RestTime = (3*60*1000); //3 mins
UseDebug = True;
UseResponder = True;
SaveProggyToFile = True;

ScriptName = 'RM Default Script';
Version = '1.0';

var
Rested, Worked, Loads:integer;
ProggyStr: string;


and then i put the debugging function a need. I use DebugTPA by Wizzup? and my own debug function:


//Used for debugging and finding errors
Procedure RMDebug(s:string);
var name:string;
begin
if not UseDebug then exit;
try name := Players[CurrentPlayer].Name +' : '; except name:= '' end;
writeln(name+TheTime+' - '+s);
end;


and as you can see i commented on the function, which is a very good habit but is a complete pain in the ass, and i think most scripters would agree to that.

Then i have my responder all set up, and then i added a procedure which i think is definetely worht looking at; My SwitchPlayers Procedure.


//switching palyers, or in case of jsut one player making it rest
// "not playing" for a while decreases the chance of getting a lot of randoms
procedure SwitchPlayers;
begin
if PlayersActive > 1 then
NextPlayer(LoggedIn)
else
if TimeFromMark(Worked) >= (WorkTime + Random(15*60*1000)) then
begin
if not LoggedIn then exit;
LogOut;
RMDebug('resting....');
wait(RestTime);
LoginPlayer;
Inc(Rested);
MarkTime(Worked);
end;
end;


First thing it does is check how many players are active, if there is more than one if does NextPlayer(LoggedIn). this is perfect, because i always LogOut my players if something went wrong and i include If not LoggedIn then exit; in my script. So i log them out, in the mainloop it goes all the way down to SwitchPlayers and it runs smoothly. if the last player was logged out (something went wrong) it exits and it will terminate the scipt (in the main loop)

if there is only one player active it wil start doing rests, which is a commonly used feature in the runescape of today.

Finally i have my progress report, which is strange, how can you generalize a Progress Report? Well, i do have Version and ScriptName constants, i put them there for a reason!


//Progress report
procedure Proggy;
var JX2:integer;
begin
ClearReport;
AddToReport('[====== '+Padr(ScriptName+' '+Version, 27)+' ======]');
AddToReport('[ By Rasta Magician ]');
AddToReport('[=========================================]');
AddToReport('[ ' + Padr('Written ' + (TheTime) + ' on ' + (TheDate(3)) + '.', 40) + ']')
AddToReport('[ '+ Padr(TimeRunning, 40)+']');
AddToReport('[ ' + Padr('Players: ' + IntToStr(PlayersActive), 40) + ']');
AddToReport('[ ' + Padr('Current Player: ' + Players[CurrentPlayer].Nick, 40) + ']');
AddToReport('[ '+ Padr('Loads: '+IntToStr(Loads), 40)+']');
AddToReport('[ '+Padr('Rested: '+IntToStr(Rested), 40)+']');
AddToReport('[==================== RM =================]');

ProggyStr := '';
ProggyStr := ProggyStr + chr(13) + ('[====== '+Padr(ScriptName+' '+Version, 27)+' ======]');
ProggyStr := ProggyStr + chr(13) + ('[ By Rasta Magician ]');
ProggyStr := ProggyStr + chr(13) + ('[=========================================]');
ProggyStr := ProggyStr + chr(13) + ('[ ' + Padr('Written ' + (TheTime) + ' on ' + (TheDate(3)) + '.', 40) + ']');
ProggyStr := ProggyStr + chr(13) + ('[ ' + Padr('Players: ' + IntToStr(PlayersActive), 40) + ']');
ProggyStr := ProggyStr + chr(13) + ('[ '+ Padr('Loads: '+IntToStr(Loads), 40)+']');
ProggyStr := ProggyStr + chr(13) + ('[ '+Padr('Rested: '+IntToStr(Rested), 40)+']');
ProggyStr := ProggyStr + chr(13) + ('[==================== RM =================]');

if SaveProggyToFile then
begin
JX2 := ReWriteFile(ScriptPath + ScriptName, False);
WriteFileString(JX2, ' ');
CloseFile(JX2);
AddToReport('Progress report saved to: ' + ScriptPath + ScriptName + ' ' + Version + '.txt');
end;
writeln(ProggyStr);
Disguise(' A: '+IntToStr(PlayersActive) + '/' + IntToStr(PlayersActive) +
' Loads: ' + IntToStr(Loads));
end;


the Padr command will ensure that the design looks just right, and i turns out like this thanks to it:


[====== RM Default Script 1.0 ======]
[ By Rasta Magician ]
[=========================================]
[ Written 01:28:01 PM on 04-01-09. ]
[ 0 Seconds ]
[ Players: 0 ]
[ Loads: 0 ]
[ Rested: 0 ]
[==================== RM =================]


and finally the mainloop :)


begin
ActivateClient;
SetupSRL;
DeclarePlayers;
LoginPlayer;
MarkTime(Worked);
repeat
if not LoggedIn or AllPlayersInactive then exit;
Proggy;
SwitchPlayers;
until(false)
writeln(TheTime);
end.


and that concludes my small tutorial. my Default script is at least one day's work, which i no longer have to do every time i start a script:)

~RM

Torrent of Flame
01-04-2009, 12:39 PM
Well your padr part will help me, I've always wanted to know to make a sexy progress report like that :D

Magiic
01-04-2009, 03:28 PM
well, maybe not a days work, plus if you only make runescape scripts it's useful otherwise it's a waste of time as you just make a seperate script with that and copy/paste it in for a runescape script. not saving it as defualt, otherwise good tutorial.

Sir R. M8gic1an
01-05-2009, 07:11 PM
for some annoying reason when i browse the tutorials thread i don't find my own tutorial on it....


edit: o.O i got tut cup! thank you to whoever gave it to me :D

~RM

Naum
01-05-2009, 07:12 PM
It's catigorised Alphabetically. Good Job btw :)

Torrent of Flame
01-05-2009, 07:15 PM
for some annoying reason when i browse the tutorials thread i don't find my own tutorial on it....


edit: o.O i got tut cup! thank you to whoever gave it to me :D

~RM

Congratulations!