PDA

View Full Version : Adding MultiPlayer



nielsie95
07-02-2007, 10:02 AM
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:

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.



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!

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

add if not LoggedIn then Exit 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
07-02-2007, 01:06 PM
Thank you so much. Now there is no excuse for member apps having bad multiplayer.

Garrett
07-02-2007, 01:10 PM
Thanks. This tutorial could help alot.

stuckman
07-02-2007, 03:07 PM
thanks for this, i could never understand why my multiplayer got runtime errors and this is almost certainly the fix!

Harry
07-02-2007, 03:13 PM
Thanks..!

Tim0suprem0
07-02-2007, 03:43 PM
Wow thanks! I thought I understood multiplayer, but evidently I didnt! This helps me out a lot.

Sinfulend
07-02-2007, 07:01 PM
Thanks Alot I really neede a good resource on muiltplayer

Wanted
07-02-2007, 08:09 PM
Nice Tutorial, would you mind adding other methods as well?

Smartzkid
07-02-2007, 08:33 PM
Yay!

nielsie95
07-02-2007, 08:58 PM
Thanks all! :)

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

Hugolord
07-02-2007, 09:01 PM
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
07-02-2007, 09:19 PM
Thanks all! :)

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

Post # 9 (http://www.villavu.com/forum/showthread.php?t=8609) ;)

Abyssal
07-02-2007, 09:49 PM
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
07-03-2007, 12:31 AM
Very good tut nielsie. You explained everything extremely nice and clear, so that their can be no confusion.

GJ :D

BobboHobbo
07-09-2007, 01:24 AM
:) Now i know a little more, thanks.

cathering_
07-28-2007, 11:59 AM
Nice Tutorial :P

oliver1205
07-31-2007, 01:40 AM
thanks for taking the effort. clearly explained. =]

nielsie95
08-01-2007, 09:52 AM
No problem :)

dvdcrayola
08-03-2007, 11:49 PM
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
09-21-2007, 07:48 PM
Very good tutorial, helped me to get the hang of multiplayer.

So thanks alot.

tyler1993
12-08-2007, 12:39 PM
thanks that helped!

imskate182
12-19-2007, 04:26 AM
thank you so much this is exactly what i needed :D
now im gona try to add multyplayer to my script:)

Pure1993
02-08-2008, 10:04 PM
Finally! Was about time I understood how to effectivly use multi-player! Thanks a lot! :D

XRaye
04-19-2008, 08:19 PM
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
05-14-2008, 07:43 AM
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
05-14-2008, 10:46 AM
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
07-30-2008, 08:40 PM
Nice tut, Now I can start putting multiplayer on my scripts

Negaal
08-05-2008, 06:38 AM
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
08-13-2008, 04:07 PM
Ooohh nice tut. I've never done multiplayer properly before :D shhh!

YoHoJo
09-18-2009, 09:50 AM
Perfect, sweet and simple. This helped me out a lot, thanks Nielsie <3.