PDA

View Full Version : The making of your first script.



Vinyl Scratch
08-20-2012, 12:21 AM
Hey guys. I'm gonna teach you how to make your first Runescape script. It's going to be A very in-depth tutorial on the basic functions for scripting. We won't use TPAs, don't worry.

To start, we're going to open Simba. I'm going to help you set it up, if you haven't already.


Start by opening Simba, then go to View>Extensions. You'll get a window like this one:
http://puu.sh/WVEg

You're going to double click Assosiate.sex, Extension.sex, and SRL.sex. (Someone correct me if I'm wrong, please. )
Anyway.. Your window'll look like this:
http://puu.sh/WVMi

Does it look like that? [y/n]
Non-Retorical.

Good. Now, close that, and Simba.
Now, go to tools>update.
Click force update, just to make sure.
then close Simba again.

y we cloz Simba so much?
So that it "refreshes" Simba.
ohkee.

So.. You SHOULD have something like this:
{$DEFINE SMART}
{$I SRL/SRL.Simba}

Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := '';
Pass := '';
Pin := '';
WorldInfo := [27, 42, 45, 46, 48, 52, 59, 70, 72, 78, 79, 87, 104, 115, 117];
BoxRewards := ['XP','xp','lamp'];
LampSkill := Skill_Slayer;
Active := True;
end;
end;

begin
{$IFDEF SMART}
{$IFDEF SIMBAMAJOR980}
Smart_Server := 72;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ELSE}
SRL_SixHourFix := True;
Smart_FixSpeed := True;
{$ENDIF}
{$ENDIF}

DeclarePlayers;
SetupSRL;
end.

If not, then it'll be:
program new;
begin
end.

I'm going to explain from top to bottom what everything is.
Starting with the program new;
This tell the interpreter, in this case, Simba, that it's a program. The "new" is the name of the program. you have to have the semicolon to signify the end of that line. k. That's done.

Now, for the weird curly-bracketed stuff.
{$DEFINE smart}
That's to get SMART to open. (Simba Minimizing Autoing Thing, as I like to call it.)
{$i SRL/SRL.simba}
This? This is for including SRL. (Simba Resorce Library, as I also like to call it.)
You need this to script.. unless you want to write all of your own functions. I would stick to using this, though. Now, you have all of this in your script. Wat do? Well, you need a main loop!
wat be a main l00p?
It's what makes the script run. You don't have it, and your procedures in it, your script won't work. You'll either get errors, or your script won't do anything.

Well, your main loop looks like this: begin
end.

Now, you know what it does. Wanna make it work? Type "writeln('Does it work?');" into it, and click run. (the green button!)
You'll see your text pop up in the debug box. Happy? Good.

Take that out. You don't need it anymore.

Now, go to the space between the main loop and your weird curly bracketed thing.

Type "procedure". It'll look like this:
procedure

Did it look like that?
Good.

Now, type a name for it.
Since this is going to be a 2 procedure script, you can name it what you like. I'm going to name it "attack" because we're going to make it attack something. In this tutorial, Goblins. Ok, you have a name, right?

Good, good.
Now, you're going to want to add a variable.
type "var"
You'll see it get big and black.
var
See?

Good. Now, press enter. Then either press Tab once, or space twice. This is called indention. You use this to have good standards in coding, and so your code is readable.

Now, type "x, y: Integer;"
It'll show up like this:
var
x,y: Integer;

This is declaring x, and y, as an integer. Now, an integer holds a number. You need to assign those variables to a number. Now, you aren't going to go x:= 83;
y:= 94;
because those are static. We need them to be assigned by a function.
anyway... after that, press enter, and the backspace button. Now, type begin.
It'll get Big and black.
Like this:
begin
k? good.

So, we're going to use an if...then statement. What this does is says, If I find the object, then go to the next line.

So, what we're going to do is type if FindObjCustom(x, y, ['uptext', 'uptext'], [color, color, color], 7); then

See there?
Get the uptext, which, in this case would be 'ttack', 'oblin'
Then your color. Pick a color from the goblin.

That 7? That's the tolerance. You use tolerance to keep to that color, and only go out a certain amount of shades.

Now, what to do if it finds it.

press enter.
type begin
press space two times.
then, we're going to use a case ... of statement
So, you're code'll look like this:
Ok, I'm going to use Simba tags from here on out, because It's getting annoying doing all of the different color tags.

case Random(2) of
0: begin
MMouse(x, y, 3, 3); //this moves the mouse to the coord, with a randomness of 3 on both the x, and y axises.
Clickmouse2(true); //left clicks the mouse
end; //ends the begin statement that you started.
1: begin
MMouse(x, y, 3, 3);
Clickmouse2(false); //right clicks the mouse.
WaitOptionMulti(['ttack', 'oblin'], 300); waits for the option menu to show up, and then clicks.
end; //ends the begin statement.
end; //you have to end the case statement, too.

to make sure you don't get lost, this is what your script should look like so far:
{$DEFINE SMART}
{$I SRL/SRL.Simba}

Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := '';
Pass := '';
Pin := '';
WorldInfo := [27, 42, 45, 46, 48, 52, 59, 70, 72, 78, 79, 87, 104, 115, 117];
BoxRewards := ['XP','xp','lamp'];
LampSkill := Skill_Slayer;
Active := True;
end;
end;

procedure attack;
var
x, y: Integer;
begin
if FindObjCustom(x, y, ['ttack', 'oblin'], [5482390, 7834647, 9827484], 7) then
case Random(2) of
0: begin
MMouse(x, y, 3, 3);
Clickmouse2(true);
end;
1: begin
MMouse(x, y, 3, 3);
Clickmouse2(false);
Waitoptionmulti(['ttack', 'oblin'], 300);
end;
end;
end;


begin
end.

If your script looks like that, then you're doing good.

Now, We need to check if it's in combat, right? Yes. So, You're going to add if Didredclick then
That'll make the attack procedure look like this:

case Random(2) of
0: begin
MMouse(x, y, 3, 3);
Clickmouse2(true);
if DidRedClick then
Wait(10000);
end;
1: begin
MMouse(x, y, 3, 3);
Clickmouse2(false);
WaitOptionMulti(['ttack', 'oblin'], 300);
if DidRedClick then
Wait(10000);
end;
end;

Now, we're going to setup the main loop.
Y'know, the begin..end. thing

Well, First, you're going to add (if it isn't already there.)

begin
{$IFDEF SMART}
SRL_SixHourFix := True;
Smart_FixSpeed := True;
{$ENDIF}
DeclarePlayers;
SetupSRL; //sets up SRL.
LogInPlayer; //Logs the player in
end.

Now, you're going to want to add your procedure into it. So, add the NAME ONLY into the main loop.
it'll look like this:

{$IFDEF SMART}
SRL_SixHourFix := True;
Smart_FixSpeed := True;
{$ENDIF}
DeclarePlayers;
SetupSRL;
Attack;
end.

There you go. Now it'll find the goblin, and
kill it.

But it'll only kill only one.

Wha.. Why?!
Because, there's no loop.
But it's called the main loop?
Think of it as a group on friends. There's always that one who won't shutup. He's the loop inside of your friends. That's what you're creating now.

So, just put

repeat
Attack;
until(not(loggedIn);


Now it'll loop until you are logged out, then it'll terminate the script. Now, you've made your first successful script! Good Job!

Footy
08-20-2012, 12:37 AM
I'd suggest writing the whole tut on word, then posting it all at once. Other then that, it looks good so far.

Vinyl Scratch
08-20-2012, 12:39 AM
I would do that, but I needed to test the colors, to make sure they were working.

Sin
08-20-2012, 12:40 AM
Nice :)

P1ng
08-20-2012, 12:42 AM
Overall nice guide, but seeing as this is a setup for writing a RuneScape script there is no reason to make the scripts backwards compatible anymore as an older version of Simba and the SRL include will not working with current runescape.

Change this:
{$IFDEF SMART}
{$IFDEF SIMBAMAJOR980}
Smart_Server := 72;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ELSE}
SRL_SixHourFix := True;
Smart_FixSpeed := True;
{$ENDIF}
{$ENDIF}

To this:
{$IFDEF SMART}
SRL_SixHourFix := True;
Smart_FixSpeed := True;

Joe
08-20-2012, 12:54 AM
Overall nice guide, but seeing as this is a setup for writing a RuneScape script there is no reason to make the scripts backwards compatible anymore as an older version of Simba and the SRL include will not working with current runescape.

Change this:
{$IFDEF SMART}
{$IFDEF SIMBAMAJOR980}
Smart_Server := 72;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ELSE}
SRL_SixHourFix := True;
Smart_FixSpeed := True;
{$ENDIF}
{$ENDIF}

To this:
{$IFDEF SMART}
SRL_SixHourFix := True;
Smart_FixSpeed := True;

Ping got to it first.
I would also add that you should enable DTM editor as well.

Overall superb guide. Youre a wonderful person in the community :)

Vinyl Scratch
08-20-2012, 01:22 AM
Thanks guys! I'll change it now! I worked REALLY hard on this one! Glad you guys like it!

It's completely finished now, too!

Sin
08-20-2012, 01:24 AM
Great, don't let the haters get to you ;)

NKN
08-20-2012, 01:27 AM
Might wanna fix that Simba tag in the middle. ;)

Vinyl Scratch
08-20-2012, 01:40 AM
Might wanna fix that Simba tag in the middle. ;)

Done! Thanks for pointing that out, I didn't notice it. Lol.

I do all of my bbcode tags manually.

What should be my next tutorial, guys?

Nebula
08-20-2012, 02:53 AM
I guess this would be a good guide for someone who doesn't have simba installed yet and doesn't know what case statements are but isn't told what they do who also has old backwards compatible plugins that they wish to use and also needs an explaination of how to use begin and end?

Vinyl Scratch
08-20-2012, 03:07 AM
Not even going to start a flame war. Ignored.

Nebula
08-20-2012, 03:09 AM
Oh sorry man didn't mean to start any friction (http://villavu.com/forum/showthread.php?t=88500) between us.

riwu
08-20-2012, 01:16 PM
Not even going to start a flame war. Ignored.

Oh sorry man didn't mean to start any friction (http://villavu.com/forum/showthread.php?t=88500) between us.

It's all about being tactful.
Sometimes, if you choose to correct some1 arrogantly, even if you are right, you will not be well-received.

I must admit that at times i might also neglect it and sounded harsh, so we should all learn together to live in harmony. After all, we are here to make friends, not enemies.

@Nebula, i understand how you may feel offended, but sometimes you should just take criticisms positively (even if they sound rude) and not hold a grudge. Learning to forgive and forget is a virtue ;)

And let us look up to and learn from saints like yohojo, wizzup and many other ssrl and mods, never seen them rude to anyone. :thumbsup:


On topic, haven't read through it but for the effort alone u deserve some rep :)

yonku_shankz
08-20-2012, 06:05 PM
nice guide im learning how to script right now this helped me..one thing tho

case Random(1) of

wont this just return the 0th case all the time shouldn't it be.

case Random(2) of

if you want it to left click and right click?

also i would like some help in finding a monster/npc not in a fight and then click that how do i start with that?

Vinyl Scratch
08-20-2012, 07:09 PM
You could check for the HP bar. I believe there's a Bitmap in SRL for that.

And, thanks for letting me know about the case random(1) of thing. Fixed it.

yonku_shankz
08-20-2012, 08:07 PM
You could check for the HP bar. I believe there's a Bitmap in SRL for that.

And, thanks for letting me know about the case random(1) of thing. Fixed it.

figured as much but any idea how to start that? i only started scripting for simba as of yesterday lol :duh:

Vinyl Scratch
08-20-2012, 08:25 PM
You're going to want to load a bitmap of it. Go take a screenshot of the think you're needing, and anything around that needs to be colored black. Not the item itself, but what's around the item.

litoris
08-20-2012, 09:11 PM
Yonku, you should check out Narcle's fighter. He looks for the HP bar in a designated area before attacking.

Vinyl Scratch
08-20-2012, 09:26 PM
^

What he's saying is look at Narcle's code, and see how he handled finding the HP bar.
Then re-create it your own way.

yonku_shankz
08-20-2012, 09:26 PM
Yonku, you should check out Narcle's fighter. He looks for the HP bar in a designated area before attacking.

thanks ill be looking into that

HolyWord
08-21-2012, 12:56 AM
[Error] (26:58): Type mismatch at line 25
Compiling failed.

I keep on getting this... Its the line with the FindObjCustom
"if FindObjCustom(x, y, ['ttack', 'oblin'], 5482390, 7) then"
I don't get it :/

NKN
08-21-2012, 01:05 AM
Put [] arround 5482390

HolyWord
08-21-2012, 01:10 AM
Put [] arround 5482390

:D Shoulda thought of that... Thanks dude!

Vinyl Scratch
08-22-2012, 04:42 AM
You know that isn't a color of the goblins, right?

It's just a random number I made up. Lol.