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:
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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