[Server Scripting] Lutra's Server Script

Discussion in 'Server and Client Scripting' started by Lutra, Jun 3, 2010.

  1. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    PO v1 Version

    Full Script Link: http://pokemonperfect.co.uk/serverscript.txt

    Auto-Update Script Link: http://pokemonperfect.co.uk/webcallscript.txt

    Instructions

    PO v2 Version

    Info: https://github.com/Jakilutra/Lutra-s-Pokemon-Online-Supplements/wiki/PO-Server-Scripts

    N.B. originally a tournament script that developed into a server script. Now, a new server script is in development.

    I will also tweet my decisions regarding the development of the script.
     
    Last edited: Nov 21, 2012
  2. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Wow, thanks a lot.

    I still see the influence of NB scripts.

    Instead of doing a whole lot of if / else, use something like

    Code (javascript):
    1.  
    2. if (commandpart[0] == "xxxx") {
    3.    ....
    4.    return;
    5. }
    6. if (commandpart[0] == "yyyy") {
    7.    ....
    8.    return;
    9. }
    10. if (commandpart[0] == "zzzz") {
    11.    ....
    12.    return;
    13. }
    14.  
    and

    Code (javascript):
    1.  
    2. if (tourmode == 0) {
    3.    sys.sendMessage(src, "A tournament is not running");
    4.    return;
    5. }
    6. if (tourmembers.indexOf(tourmembername) in tourmembers) {
    7.    sys.sendMessage(src, "You're already registered");
    8.    return;
    9. }
    10. ...
    11.  
     
  3. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    But really, I think I will use this in beta server (if you don't mind :))
     
  4. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Sure. Is there any use for else then (at all)?
     
  5. Elements

    Elements BOOMER SOONER Forum Moderator Server Staff Forum Moderator Server Staff

    Joined:
    May 9, 2010
    Messages:
    1,195
    Likes Received:
    48
    PO Trainer Name:
    Elements
    I have no experience with javascript, but I want to throw this idea/suggestion out...well question mostly. Is it possible to be able to input tournament participants into a tourney? Say you have a forum tournament sign up and you only want the people who signed up for the tournament on the forums to participate. Is there a way to create this?

    Edit: Awesome script though, Lutra. Everyone is going to use it lol.
     
  6. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    That's a very good suggestion. I probably should have made that when I was testing the display of the rounds xd. I'll do it after all the essential things are done. What do you think is the best format for the command?
     
  7. Elements

    Elements BOOMER SOONER Forum Moderator Server Staff Forum Moderator Server Staff

    Joined:
    May 9, 2010
    Messages:
    1,195
    Likes Received:
    48
    PO Trainer Name:
    Elements
    I think like '/inputplayer' would be efficient (if it is not already used).
     
  8. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Ok

    here are my tweaks

    Code (javascript):
    1. afterBattleEnded: function(winner, loser){
    2.           if (tourmode == 2){
    3.                     this.tourneyBattleEnd(sys.name(winner), sys.name(loser));
    4.           }
    5. }
    6. ,
    7.  
    8. disqualify: function(src,name) {
    9.     var index = tourmembers.indexOf(name);
    10.    
    11.     if (index == -1) {
    12.         sys.sendMessage(src, name + " isn't in the tournament.");
    13.         return;
    14.     }
    15.    
    16.     if (index %2 == 0) {
    17.         var opponent = tourmembers[index+1];
    18.         if (opponent == "*bye") {
    19.             sys.sendMessage(src, name + " got a bye.");
    20.             return;
    21.         }
    22.         if (tourbattlers.indexOf(name) == -1) {
    23.             tourbattlers.push(name);
    24.             tourbattlers.push(opponent);
    25.         }
    26.         sys.sendAll("~~Server~~: " + name + " was disqualified from the tournament!");
    27.         this.tourneyBattleEnd(opponent, name);
    28.     } else {
    29.         var opponent = tourmembers[index - 1];
    30.         sys.sendAll("~~Server~~: " + name + " was disqualified from the tournament!");
    31.         if (tourbattlers.indexOf(name) == -1) {
    32.             tourbattlers.push(name);
    33.             tourbattlers.push(opponent);
    34.         }
    35.         this.tourneyBattleEnd(opponent, name);
    36.     }
    37.    
    38. }
    39. ,
    40.  
    41. tourneyBattleEnd : function(winnername, losername)
    42. {
    43.     var tourloser = tourbattlers.indexOf(losername)
    44.     if (tourloser in tourbattlers && tourlosers.indexOf(losername) == -1){
    45.               tourlosers.push(losername)
    46.               tourbattlers.splice(tourloser,1);
    47.               var tourwinner = tourbattlers.indexOf(winnername)
    48.               tourbattlers.splice(tourwinner,1);
    49.               tourbattles++;
    50.               if (tourcurrentnumber % 2 == 1 && tourbattles == tourcurrentnumber/2 -0.5){
    51.                         tourmembers.splice(tourcurrentnumber,1);
    52.                         tourcurrentnumber = tourcurrentnumber/2 + 0.5;
    53.                         this.roundpairing();
    54.                         return;
    55.               }
    56.               if (tourcurrentnumber % 2 == 0 && tourbattles == tourcurrentnumber/2){
    57.                         if (tourcurrentnumber == 2){
    58.                                   tourmode = 0;
    59.                                   sys.sendAll("");    
    60.                                   sys.sendAll(border);
    61.                                   sys.sendAll("");
    62.                                   sys.sendAll("THE WINNER OF THE TOURNAMENT IS : " + winnername);
    63.                                   sys.sendAll("");
    64.                                   sys.sendAll("*** Congratulations, " + winnername + ", on your success!");
    65.                                   sys.sendAll("");
    66.                                   sys.sendAll(border);
    67.                                   sys.sendAll("");
    68.                                   return;
    69.                         }
    70.                         if (tourcurrentnumber > 2){
    71.                                   tourcurrentnumber = tourcurrentnumber/2;
    72.                                   this.roundpairing();
    73.                                   return;
    74.                         }
    75.  
    76.               }
    77.               sys.sendAll("");
    78.               sys.sendAll(border);
    79.               sys.sendAll("*** A tournament match has been completed!");
    80.               sys.sendAll("");
    81.               sys.sendAll("~~Server~~: " + winnername + " advances to the next round:");
    82.               sys.sendAll("~~Server~~: " + losername + " is out of the tournament.");
    83.               sys.sendAll("");
    84.               sys.sendAll("*** " + Math.floor(tourcurrentnumber/2 - tourbattles) + " more match(es) to be completed in this round!");
    85.               sys.sendAll(border);
    86.               sys.sendAll("");    
    87.     }
    88. }
    Basically when a mod use the dq command, call this.dq(src, nameOfTheDqdPlayer) -- only works when the guy is in a pairing, or battling.
    Also the problem of someone fighting multiple times and screwing over the tourney system is fixed.

    Though my dq solution is ugly, it's just a temporary fix until you make something better :)
     
  9. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Thanks very much for that coyotte :)

    I've added that tourneyBattleEnd function. I'll change that if else structure tomorrow and work on dqplayer and sub in.

    Edit: Replaced the if else.
     
    Last edited: Jun 4, 2010
  10. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Noticed I forgot to add one check after a battle ends, to avoid the problem of duplicate battles.

    The correct fix is:

    Code (text):
    1. tourneyBattleEnd : function(winnername, losername)
    2. {
    3.     var tourloser = tourbattlers.indexOf(losername)
    4.     if (tourloser in tourbattlers && tourlosers.indexOf(losername) == -1 && tourlosers.indexOf(winnername) == -1){
    (The previous version would work ok if the previous loser still lost that match, but not if he won it)
     
  11. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    Lutra, I know this wont really make a good stand alone script, so could you maybe split it into parts that can be added into other scripts easier when you post the next version?
     
  12. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Updated with some minor changes. I'm in the process of doing the disqualify command.

    Well the priority is to aim it for people who just want to copy and paste everything. It'd make it harder for those people if each event etc. was separated. Plus it would reduce my willingness to update the post if I have to edit every part. I know it's not easy updating your own script when this is updated every time, but please bear with it for the time being.
     
  13. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Just so you know:

    Code (text):
    1. afterBattleEnded: function(winner, loser,  desc){
    2.           if  (tourmode == 2 &&  desc != "tie"){
    3.                     this.tourneybattleend(sys.name(winner),  sys.name(loser));
    4.           }
    5. }

    To avoid problems with ties
     
  14. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Ok thanks coyotte, I added that. I've modified the round display so that the winner of any match is now displayed with brackets around them. :)

    I've also made a member separate to tourneybattleend just for increasing battles in rounds called roundincrease - as well as improving the display for that.

    The disqualify command is a bit annoying to do. That's why I'm trying to do easy bits first.
     
    Last edited: Jun 5, 2010
  15. Erebos

    Erebos Banned

    Joined:
    May 6, 2010
    Messages:
    743
    Likes Received:
    0
    I could not find anything similar in your scripts as I looked through them, but then, I'm not very experienced with Javascript - but the addition of a /dropout command would be very useful, since currently you have to get someone to disqualify you if you need to leave. (it should work both before the tournament starts and during it.)
     
  16. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    I'll do a /leave command after the disqualify and sub-in.
     
  17. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Ok done most of /disqualify, the only thing I haven't taken into account yet is disqualifying a bye opponent in the case of 3 players - so that the final becomes the match in that round for those other two players.

    Edit: There's also the problem of the message displayed when two people facing each other both get disqualified.

    Let me know if there are any other problems.
     
    Last edited: Jun 5, 2010
  18. eric the espeon

    eric the espeon is an espeon.

    Joined:
    Apr 21, 2010
    Messages:
    854
    Likes Received:
    1
    It would be great to have a command which returned a list of unfinished matches. It's hard to find who needs DQing in a large tourney otherwise.
     
  19. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    As well as having brackets around the winner? I've done that already. It's just coyotte hasn't updated yet. I do admit in massive tournaments, even the scanning through the bracketed winners becomes a pain. But the largest tournament size is 64 atm, so I'm not sure that's a very big deal yet.
     
  20. eric the espeon

    eric the espeon is an espeon.

    Joined:
    Apr 21, 2010
    Messages:
    854
    Likes Received:
    1
    It's not very practical to keep track of who has done their matches and who has not in a 64 man tournament with an active chat, if you could just put something like /matches and get a list of matches that are not finished it would be cool. Then you know who to talk to, and can DQ those last few people who tend to hold it up. Do you mean you've got a command that tells the state of all matches, including the finished ones? If yes, that'd work fine.
     
  21. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    This is how it is at the moment. Given the only match won here is when Lutra beat Lutra4.

    (22:35:02) *** Round 1 ***

    (22:35:02) »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»:
    (22:35:02) Lutra4 VS (Lutra)
    (22:35:02) Lutra2 VS Lutra3
    (22:35:02) »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»:
     
  22. eric the espeon

    eric the espeon is an espeon.

    Joined:
    Apr 21, 2010
    Messages:
    854
    Likes Received:
    1
    great, that will help a lot when it's live.

    Edit: Could you make it differentiate between doubles and singles?
     
  23. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Well singles and doubles should have their own tiers really. I think it should be the server's responsibility to enforce singles/doubles in that tier. Although the limitations of the tier system of the simulator are to blame too. I just don't want to add something that could be irrelevant. coyotte can include whatever modifications he wants in the beta server scripts though.
     
  24. Tiger

    Tiger New Member

    Joined:
    Jun 6, 2010
    Messages:
    10
    Likes Received:
    0
    Sorry, I use Google translator.
    I would like to use the script on my server, and wanted to ask if I can use it? I would also like to change him so that he is German.
     
  25. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Sure. It's for everyone :)
     
  26. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    Very Nice Script!
    I just wanted to show my appreciation, and test if my signature is working <.<
     
  27. Steve

    Steve Active Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    491
    Likes Received:
    45
    Indeed it is.

    By the way, you spelt variable wrong in your signature.
     
  28. eric the espeon

    eric the espeon is an espeon.

    Joined:
    Apr 21, 2010
    Messages:
    854
    Likes Received:
    1
    If it could do something like send a PM to players who had not started their matches after 2-3 mins saying "Are you here? Please play <player> and reply to this PM to confirm your activity." (and maybe say PM a mod if they need help) and if only one replied within a reasonable length of time DQ the other it would help to reduce mod involvement a lot. I don't know if it's possible to have the server PM people currently though.

    Other than that, one more command would be handy (though not vital by any means), being able to sub someone in would be great. Like /replace <player1> <player2> would replace player 1 with player 2, this would help if if there has been an error (incorrect dq, someone slipping through the rules, glitch in the script) and be good as an extra control for mods.

    Really brilliant script, this thing is responsible for most of the activity in the main chat round the clock.
     
  29. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Yeah, you can't currently have the server pm people. And I'll be doing a sub in/out command very soon btw. I just want to try to sort out the bugs first and do some other easy bits.

    Edit: I've got rid of the bracketed s in "spot(s)" when they join and the bracketed es in "match(es)" when the number of matches left are shown. If there's 1, it will now say "spot" and "match" and everyone else is "spots" and "matches".
     
    Last edited: Jun 7, 2010
  30. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Could you, if you have times, do different things:

    - When someone has a battle coming in a tourney, prevent him to battle anyone else, or to battle in the wrong tier
    - Show the list of the matches in the round, separating battles that are done and battles that are still going on


    Also one thing, i often saw stuff like that in your code:

    Code (text):
    1. condition ? do this : do that
    That's not what the '?' ':' operator was designed for. If you do that you might as well do if/else

    For example in your code, you have

    Code (text):
    1.  
    2.           var  roundstring;
    3.           tourcurrentnumber ==  2 ? roundstring = "*** Final Round  of " + tourtier.toUpperCase() + " Tournament ***" : roundstring =  "*** Round " + roundnumber + " of " +  tourtier.toUpperCase() + " Tournament ***"
    4.           send(roundstring);
    5.  
    That's an unnatural way of using the ternary '?' operator.

    You might want to do that instead:

    Code (text):
    1.  
    2.       var roundstring = tourcurrentnumber ==  2 ? "*** Final Round  of " + tourtier.toUpperCase() + " Tournament ***" :   "*** Round " + roundnumber + " of " +  tourtier.toUpperCase() + " Tournament ***";
    3.       send(roundstring);
    4.  
    Because doing assignations within the operator is unnatural. And as you can see you can use the result of the operator to do the assignation, and that's more understandable too.

    Anyway, kudos for making this script :)
     
  31. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Thanks, updated with the more efficient code. I'll do the force tourney battle as an tournament administrator option that is saved. The options will say like it is turned off by default, do this command to turn it on. I'll be doing the /viewmatchstatus as completed matches at the top, ongoing matches in the middle and matches not started at the bottom.
     
  32. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    ok, cool.
     
  33. zeroality

    zeroality Artificial Insanity

    Joined:
    Apr 22, 2010
    Messages:
    1,378
    Likes Received:
    1
    Shouldn't it restrict tournament participants from being able to start battles players other than their tournament opponent? Just had a round held up because we were waiting for a player to finish a battle with someone else so his opponent could challenge him.

    Also why is the /dq command case-sensitive?
     
  34. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Look 2 or 3 posts up for the 1st paragraph.

    For the 2nd, you're referring to a modified version of this tournament script.
     
  35. eric the espeon

    eric the espeon is an espeon.

    Joined:
    Apr 21, 2010
    Messages:
    854
    Likes Received:
    1
    I tend to just tell tourney players to quit their other battle or get DQed, but it is slightly annoying.
     
  36. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Updated with the command to view the status of matches! :)

    I've called it just /viewmatches
     
  37. genuzzu

    genuzzu New Member

    Joined:
    Jun 8, 2010
    Messages:
    19
    Likes Received:
    0
    If i type:
    !tour overused 12
    It make this error:
    Sorry, the server does not recognise the overuser tier.
     
  38. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    you typed in !tour overuser 12, apparently
     
  39. genuzzu

    genuzzu New Member

    Joined:
    Jun 8, 2010
    Messages:
    19
    Likes Received:
    0
    Oh, tank you. It was te problem.
     
  40. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Fixed the space in tiers bug and also an error with the /viewmatches display. Did the force tourbattle option. :)

    Suggestions to implement list:

    - Fix the bugs associated with 2 players facing each other being removed and then do "leave" command.
    - "Subin/out" command.
    - "Add player" command and "freeze sign-ups" command.
     
    Last edited: Jun 10, 2010