SRL Archive - OSR Intermediate Scripting Tutorials

Adding MultiPlayer


nielsie95

2007-07-02 06:02:08

Hello and welcome to the tutorial


Adding MultiPlayer
by Nielsie95




MultiPlayer is the base and power of SRL. Running multiple characters after eachother. If one player messes up, you still have other players running! :)
With RC it's even possible to 'reset' your players while running. This way, with multiplayer, you could practicly run forever! :)

In this (small) tutorial you are going to learn how you add MultiPlayer to your script.




NextPlayer

The base of the playerswitching in SRL is NextPlayer.
There are 2 possible options to use it with:

[BANANA]NextPlayer ( True ) - This will switch players and will leave the current player active.

NextPlayer ( False ) - This will switch players and will switch the current player to not active.[/BANANA]


But that's not all!



If you know how to use NextPlayer then you're not done yet!
If you just would use NextPlayer at any random position in a script it could mess up, because the player is for example at the wrong location. That's why you need 1 constant spot to switch players: your mainloop.

Let's take this mainloop for example:

begin
SetupSRL;
ActivateClient;
DeclarePlayers;

repeat
repeat
ChopThis;
WalkHere;
WalkThere;
ChopAgain;
WalkBack;
Bank;
until (Loads >= LoadsToDo) or (not LoggedIn)

NextPlayer(True);
until False;
end.

This will run your mainloop until the loads are done or until you are not loggedin. If it passed that, it will switch players and run the mainloop again. This is the base of player switching.

But what if it messes up during walking? Or it gets a random? The player will mess up and the player needs to be switched.. Now it will just run along, thinking the player is still active. That's why you need to:



Adjust your procedures

If the script messes up somewhere, you need to switch players. You can't do this while you're in the middle of a procedure (only your mainloop)!

You need to set your player false and log him out if he messes up:


procedure WalkToThere;
begin
if not LoggedIn then Exit;
RadialWalk(RoadColor, 0, 90, 50, 1, 1);
RadialWalk(RoadColor, 0, 90, 50, 1, 1);
if FindSymbol(x, y, 'Mining spot') then Mouse(x, y, 1, 1, True) else
begin // if it doesn't find the symbol (if it messes up)
Players[CurrentPlayer].Active := False; // Set your player to false!!
Players[CurrentPlayer].Loc := 'Walking to there';
LogOut; // Log him out!!
Exit; // Exit the procedure, so it wont continue!!
end;
FFlag(0);
end;

You can see that I try to walk the road and then try to find a miningsymbol.
If it doesn't find it (only then), it means I screwed it: the player needs to be switched!

[BANANA]I set him inactive, I logout and I exit the procedure.[/BANANA]
Now after this it will still try to continue with other procedures, to avoid this:

add [BANANA]if not LoggedIn then Exit[/BANANA] to every (!!)procedure / function in your script!

This way it will scroll down the mainloop and do nothing, because it's not loggedin. When it reaches the until, it will break out because we're not loggedin. After that it will switch players, but it will switch the player to true again (NextPlayer ( True )). To avoid this, change NextPlayer to:

NextPlayer(Players[CurrentPlayer].Active).

If the player is not active; it wil stay false, but if the player is active; it will stay active! :)




Conclusion

Wrong:

procedure WalkToThere;
begin
RadialWalk(RoadColor, 0, 90, 50, 1, 1);
RadialWalk(RoadColor, 0, 90, 50, 1, 1);
if FindSymbol(x, y, 'Mining spot') then Mouse(x, y, 1, 1, True) else
begin
NextPlayer(False);
end;
FFlag(0);
end;

Correct:


procedure WalkToThere;
begin
if not LoggedIn then Exit;
RadialWalk(RoadColor, 0, 90, 50, 1, 1);
RadialWalk(RoadColor, 0, 90, 50, 1, 1);
if FindSymbol(x, y, 'Mining spot') then Mouse(x, y, 1, 1, True) else
begin // if it doesn't find the symbol (if it messes up)
Players[CurrentPlayer].Active := False; // Set your player to false!!
Players[CurrentPlayer].Loc := 'Walking to there';
LogOut; // Log him out!!
Exit; // Exit the procedure, so it wont continue!!
end;
FFlag(0);
end;

and the correct mainloop:


begin
SetupSRL;
ActivateClient;
DeclarePlayers;

repeat
repeat
ChopThis;
WalkHere;
WalkThere;
ChopAgain;
WalkBack;
Bank;
until (Loads >= LoadsToDo) or (not LoggedIn)

NextPlayer(Players[CurrentPlayer].Active);
until False;
end.


I hope my language wasn't too bad to read.. :)
If it wasn't: thanks for reading,

Nielsie95

Boreas

2007-07-02 09:06:01

Thank you so much. Now there is no excuse for member apps having bad multiplayer.

Garrett

2007-07-02 09:10:15

Thanks. This tutorial could help alot.

stuckman

2007-07-02 11:07:27

thanks for this, i could never understand why my multiplayer got runtime errors and this is almost certainly the fix!

Harry

2007-07-02 11:13:12

Thanks..!

Tim0suprem0

2007-07-02 11:43:54

Wow thanks! I thought I understood multiplayer, but evidently I didnt! This helps me out a lot.

Sinfulend

2007-07-02 15:01:39

Thanks Alot I really neede a good resource on muiltplayer

Wanted

2007-07-02 16:09:33

Nice Tutorial, would you mind adding other methods as well?

Smartzkid

2007-07-02 16:33:19

Yay!

nielsie95

2007-07-02 16:58:46

Thanks all! :)

@Ice: What methods do you mean? I could add RandomNextPlayer, but I don't want to complicate it too much. :)

Hugolord

2007-07-02 17:01:32

From: Boreas
Thank you so much. Now there is no excuse for member apps having bad multiplayer.

he he :D :duh: sorry abotu my app Boreas =S

Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas, Boreas, boreas,


just testing if its really true if that gets your attention :D

@t Nielsie nice TUT a lil late (cz of my app) but GREAT!!

Wanted

2007-07-02 17:19:28

From: nielsie95
Thanks all! :)

@Ice: What methods do you mean? I could add RandomNextPlayer, but I don't want to complicate it too much. :)


Post # 9 ;)

Abyssal

2007-07-02 17:49:03

Bah, right after I posted mine I saw yours!

Sorry about that, mine took while to write and yours wasn't at the top, or I didn't see it.

Mjordan

2007-07-02 20:31:18

Very good tut nielsie. You explained everything extremely nice and clear, so that their can be no confusion.

GJ :D

BobboHobbo

2007-07-08 21:24:54

:) Now i know a little more, thanks.

cathering_

2007-07-28 07:59:13

Nice Tutorial :P

oliver1205

2007-07-30 21:40:04

thanks for taking the effort. clearly explained. =]

nielsie95

2007-08-01 05:52:00

No problem :)

dvdcrayola

2007-08-03 19:49:13

good tutorial!
helped me a lot.

but maybe you should add the declareplayers procedure and mention that you have to have that?

and maybe the possible things you can put in declareplayers to fit with your script? i think that would help me, and probably others

thanks!

Dr Feelgood

2007-09-21 15:48:07

Very good tutorial, helped me to get the hang of multiplayer.

So thanks alot.

tyler1993

2007-12-08 07:39:21

thanks that helped!

imskate182

2007-12-18 23:26:57

thank you so much this is exactly what i needed :D
now im gona try to add multyplayer to my script:)

Pure1993

2008-02-08 17:04:37

Finally! Was about time I understood how to effectivly use multi-player! Thanks a lot! :D

XRaye

2008-04-19 16:19:47

I get this error 'Line 119: [Error] (12898:1): Identifier expected in script…' when i do this…

procedure ChopWillow;
begin
if not LoggedIn then Exit;
FindRandoms;
if ( TreeToCut = 'Willow' ) Or ( TreeToCut = 'willow' ) then
begin
if FindObjCustom(x, y, ['Wil', 'low'], [3108448, 1986630], 5) then
begin
Wait(30 + Random(20));
Mouse(x, y, 3, 3, True);
Wait(7000 + Random(700));
else (THIS IS LINE 119)
begin // if it doesn't find the symbol (if it messes up)
Players[CurrentPlayer].Active := False; // Set your player to false!!
Players[CurrentPlayer].Loc := 'Walking to there';
LogOut; // Log him out!!
Exit; // Exit the procedure, so it wont continue!!
end;
end;
end;
end;

benjaa

2008-05-14 03:43:34

Just what I was looking for :)
Ive been trying to work it out for a while
Clear tut, nice work

 if (bEnJaasPost=GraveDigging) then Reply(' Sorry =[ '); 

@xraye….Which is line 119?

nielsie95

2008-05-14 06:46:09

Thank you :)


xraye: I don't know if you figured it out yet, but you misplaced the end:

procedure ChopWillow;
begin
if not LoggedIn then Exit;
FindRandoms;
if ( TreeToCut = 'Willow' ) Or ( TreeToCut = 'willow' ) then
begin
if FindObjCustom(x, y, ['Wil', 'low'], [3108448, 1986630], 5) then
begin
Wait(30 + Random(20));
Mouse(x, y, 3, 3, True);
Wait(7000 + Random(700));
end
else (THIS IS LINE 119)
begin // if it doesn't find the symbol (if it messes up)
Players[CurrentPlayer].Active := False; // Set your player to false!!
Players[CurrentPlayer].Loc := 'Walking to there';
LogOut; // Log him out!!
Exit; // Exit the procedure, so it wont continue!!
end;
end;
end;

Ghostman

2008-07-30 16:40:59

Nice tut, Now I can start putting multiplayer on my scripts

Negaal

2008-08-05 02:38:31

Wow this helped me:) I did Nextplayer(loggedin)(when I scripted) instead of (players[cp].active)…so if player was logged out, that meant something was wrong..but your solution is 100% better:)

Haha..funny..

Metagen

2008-08-13 12:07:45

Ooohh nice tut. I've never done multiplayer properly before :D shhh!

YoHoJo

2009-09-18 05:50:36

Perfect, sweet and simple. This helped me out a lot, thanks Nielsie <3.