Page 1 of 2 12 LastLast
Results 1 to 25 of 30

Thread: Adding MultiPlayer

  1. #1
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default Adding MultiPlayer

    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
    Hup Holland Hup!

  2. #2
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

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

  3. #3
    Join Date
    Jun 2007
    Posts
    152
    Mentioned
    4 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks. This tutorial could help alot.

  4. #4
    Join Date
    Feb 2007
    Posts
    169
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

  5. #5
    Join Date
    Dec 2006
    Location
    Sweden
    Posts
    10,812
    Mentioned
    3 Post(s)
    Quoted
    16 Post(s)

    Default

    Thanks..!


    Send SMS messages using Simba
    Please do not send me a PM asking for help; I will not be able to help you! Post in a relevant thread or make your own! And always remember to search first!

  6. #6
    Join Date
    Oct 2006
    Posts
    1,071
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

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

  7. #7
    Join Date
    Jun 2007
    Posts
    26
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks Alot I really neede a good resource on muiltplayer

  8. #8
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

  9. #9
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Yay!
    Interested in C# and Electrical Engineering? This might interest you.

  10. #10
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Thanks all!

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

  11. #11
    Join Date
    Mar 2007
    Posts
    3,681
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Boreas View Post
    Thank you so much. Now there is no excuse for member apps having bad multiplayer.
    he he 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

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

  12. #12
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    Thanks all!

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

  13. #13
    Join Date
    Jun 2006
    Location
    USA
    Posts
    428
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

  14. #14
    Join Date
    Jun 2006
    Location
    Tennessee, USA
    Posts
    2,603
    Mentioned
    1 Post(s)
    Quoted
    46 Post(s)

    Default

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

    GJ

  15. #15
    Join Date
    May 2007
    Location
    NSW, Australia
    Posts
    2,823
    Mentioned
    3 Post(s)
    Quoted
    25 Post(s)

  16. #16
    Join Date
    Jul 2007
    Location
    UK
    Posts
    307
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    Nice Tutorial :P

  17. #17
    Join Date
    Oct 2006
    Posts
    702
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thanks for taking the effort. clearly explained. =]
    "For it is not what goes into your mouth that will defile you; rather, it is what comes out of your mouth that defiles you." - Jesus of Nazareth

  18. #18
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    No problem
    Hup Holland Hup!

  19. #19
    Join Date
    Aug 2007
    Posts
    282
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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!

  20. #20
    Join Date
    Aug 2007
    Posts
    34
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

    So thanks alot.

  21. #21
    Join Date
    Dec 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thanks that helped!

  22. #22
    Join Date
    Dec 2007
    Posts
    20
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

  23. #23
    Join Date
    Jan 2008
    Location
    Frankfurt, Germany
    Posts
    742
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Finally! Was about time I understood how to effectivly use multi-player! Thanks a lot!
    There is nothing right in my left brain and there is nothing left in my right brain.

  24. #24
    Join Date
    Dec 2007
    Location
    Los Angeles, California
    Posts
    606
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

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

  25. #25
    Join Date
    Dec 2007
    Location
    Wizzup?'s boat
    Posts
    1,013
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

    Code:
     if (bEnJaasPost=GraveDigging) then Reply(' Sorry =[ ');
    @xraye....Which is line 119?
    Project: Welcome To Rainbow

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Multiplayer help
    By Raskolnikov in forum OSR Help
    Replies: 3
    Last Post: 09-11-2008, 06:44 PM
  2. multiplayer
    By havoc928 in forum OSR Help
    Replies: 4
    Last Post: 09-13-2007, 01:57 AM
  3. adding multiplayer to a tut runner
    By RudeBoiAlex in forum OSR Help
    Replies: 4
    Last Post: 04-29-2007, 06:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •