Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: server scripts (download)

  1. #1
    neorej16
    neorej16 is offline
    neorej16's Avatar


    Join Date
    Jul 2009
    Location
    Mechelen, Belgium
    Age
    21
    Posts
    169
    Country: Belgium

    Default server scripts (download)

    I'm currently using the attached scripts for my RoRnet_2.37 server. They're now free to use without attribution. I hope that this encourages more people to start experimenting with scripts

    How to set up
    Warning: this is not a replacement text for the server setup tutorial. Please read it first: Server_Setup_Tutorial
    1. Download the attachment and extract the zip archive in a new folder somewhere. In the following steps, I'll call this new folder your 'working directory'.
    2. Download the official binaries from here: http://sourceforge.net/projects/rors...9.zip/download and extract them to the 'bin' folder of your working directory.
    3. [optional] Edit the settings in the 'settings' folder of your working directory.
    4. Double click 'server_LAN.bat' for a LAN server or 'server_INET.bat' for an Internet server.


    How to configure the scripts
    1. Open 'resources/scripts/exampleScript.as' with a text editor.
    2. Add '//' in front of the lines that you want to disable.


    Script files included
    • chatManager.as: Manages the chat (command handling, flood filter, word filter etc) by means of a chatManager class and several plugins for it.
    • gameScriptWrapper.as: Provides a wrapper for the server.cmd function and has a gameScriptManager class that will handle incoming game commands and clientside events (0.39 only!) and this file also has a terrainFileLoader that allows you to modify the terrain. An example of this is included for nhelens.terrn (terrain file: resources/scripts/storage/nhelens_terrn.asdata, note the special syntax (but the default terrn syntax will work as well, the syntax that I used is just more error proof (in my opinion))). In theory, you could use the terrainFileLoader to change a race track every 10 minutes (or even change the whole terrain if you're using mesh terrains), but it might give collision problems.
    • localstorage.as: A serverside implementation of the clientside localstorage class.
    • profanityFilter.as: A file containing profanity filtering functions and the wordlist for them.
    • utils.as: This file has various functions and constants that will be used by various other files.
    • terrainEditor.as: This file allows you to edit terrains while playing online (so all changes are visible for all players), but I've mainly included it as an extra example, as it messes up the collision system. (need to fix that in the client)


    Data files included
    • nhelens_terrn.asdata: My terrain edits for nhelens.
    • chatPlugin_gotoCommand.asdata: Some positions for the !goto command on nhelens.


    Warnings
    • Use of these script files or any other files attached to this post is at your own risk. Using script files might change the system resource usage of the server.


    Feel free to ask help in this thread if problems arise.
    Attached Files Attached Files
    Last edited by neorej16; 04-22-12 at 08:48 PM. Reason: Updated attachment

  2. 2 users found this post helpful: dogy, tdev
  3. #2
    EBs Servers
    EBs Servers is offline
    EBs Servers's Avatar
    Join Date
    Dec 2011
    Location
    this
    Posts
    248
    Country: United States

    Default Re: server scripts (download)

    says my RORSERVER.exe is missing?

  4. #3
    Creak
    Creak is offline
    Creak's Avatar


    Join Date
    Dec 2010
    Location
    Oberbayern
    Age
    20
    Posts
    1,558
    Country: Germany

    Default Re: server scripts (download)

    You haven't downloaded the official binaries, have you?

  5. #4
    neorej16
    neorej16 is offline
    neorej16's Avatar


    Join Date
    Jul 2009
    Location
    Mechelen, Belgium
    Age
    21
    Posts
    169
    Country: Belgium

    Default Re: server scripts (download)

    Quote Originally Posted by EBs Servers View Post
    says my RORSERVER.exe is missing?
    Hmm, strange.
    It works here if the rorserver.exe file is in the correct location (bin/rorserver.exe).
    Anyway, if you're sure that you have downloaded the files from sourceforge and that the files in the correct position, then you can download the attached alternative .bat files here, which don't check for the existence of rorserver.exe before trying to start it.
    Attached Files Attached Files

  6. #5
    EBs Servers
    EBs Servers is offline
    EBs Servers's Avatar
    Join Date
    Dec 2011
    Location
    this
    Posts
    248
    Country: United States

    Default Re: server scripts (download)

    Quote Originally Posted by neorej16 View Post
    Hmm, strange.
    It works here if the rorserver.exe file is in the correct location (bin/rorserver.exe).
    Anyway, if you're sure that you have downloaded the files from sourceforge and that the files in the correct position, then you can download the attached alternative .bat files here, which don't check for the existence of rorserver.exe before trying to start it.
    Thanks everything works correctly now

  7. one user found this post helpful: neorej16
  8. #6
    neorej16
    neorej16 is offline
    neorej16's Avatar


    Join Date
    Jul 2009
    Location
    Mechelen, Belgium
    Age
    21
    Posts
    169
    Country: Belgium

    Default Re: server scripts (download)

    I received a private message today, in which someone asked for some more information about scripting. As there's actually not a lot documentation about how to write a script from scratch, I've decided to put an extra example here. (and the private messaging system doesn't allow messages with more than 5000 characters, which is the main reason why I put it here ).

    The language which you use for your scripts is AngelScript. The syntax and default functions of the class are explained here (in combination with the wiki page).

    The scripting implementation of the Rigs of Rods server is event-based, which means that you'll be able to execute code when certain events happen. The current available events on the server are: the server starts (main), a new player joins the server (playerAdded), a player leaves the server (playerDeleted), a player says something in the chat (playerChat), the client of a player sends a script message (gameCmd) and a sixth event that just happens every 200 milliseconds (frameStep).

    At each of those events, you can execute code. Here's a very simple example that just shows a chat message to all players on the playerAdded event:
    PHP Code:
    // The main event, we don't need this at the moment, but the script won't work without it being defined
    void main() {}

    // The playerAdded event
    void playerAdded(int uid)
    {
        
    server.say("A new player joined the server."TO_ALLFROM_HOST);

    You can execute that script by simply putting it in a text file with extension .as, and specify the file as scriptfile in the server configuration.

    The next step in our simple script would be to add the username to the message. We can do this using the string server.getUserName(int uid) function:
    PHP Code:
    void main() {}
    void playerAdded(int uid)
    {
        
    // Create a new variable holding the username
        
    string name server.getUserName(uid);
        
        
    // And add the name to the message
        
    server.say("Player " name " joined the server."TO_ALLFROM_HOST);

    That's still a very simple example. More complicated would be to hold statistics of usernames. We can do this by using a dictionary object as global variable. A dictionary object can store information and retrieve it again, based on a name (so, like a dictionary). So we're just going to store a simple number ('int') for every username that joins the server, and every time that we see the username again, we increase the counter by 1. (so the first time that the user joins, the counter will be 1, the second time that the user joins, the counter will be 2, etc).
    PHP Code:
    // Create our dictionary as global variable
    dictionary userJoinStats();

    // The main function, we don't need this at the moment, but the script won't work without it being defined
    void main() {}

    // This function will get called when a player joins the game
    void playerAdded(int uid)
    {
        
    // Create a new variable holding the username
        
    string name server.getUserName(uid);
        
        
    // Get the amount of times that we've seen this player before
        
    int timesSeen;
        if( 
    not userJoinStats.get(nametimesSeen) )
        {
            
    timesSeen 0;
        }
        
        
    // As the player just joined, we have to increase our timesSeen counter by 1
        
    timesSeen += 1;
        
        
    // And we store the updated value of our counter
        
    userJoinStats.set(nametimesSeen);
        
        
    // And instead of showing a global message, we'll now show a private message to this user.
        // The message will be different, depending on whether this is the first time that this user joined the server.
        
    if(timesSeen==1)
            
    server.say("Welcome " name ", thank you for deciding to check out our server!"uidFROM_HOST);
        else
            
    server.say("Welcome back " name ", this is the " timesSeen "th time that you joined our server :D"uidFROM_HOST);

    That's already quite a useful script Just as example, I'll also add a chat command now, that will allow you to see how many times a certain player joined the server:
    PHP Code:
    // Create our dictionary as global variable
    dictionary userStats();

    // The main function, we don't need this at the moment, but the script won't work without it being defined
    void main() {}

    // This function will get called when a player joins the game
    void playerAdded(int uid)
    {
        
    // Create a new variable holding the username
        
    string name server.getUserName(uid);
        
        
    // Get the amount of times that we've seen this player before
        
    int timesSeen;
        if( 
    not userStats.get(nametimesSeen) )
        {
            
    timesSeen 0;
        }
        
        
    // As the player just joined, we have to increase our timesSeen counter by 1
        
    timesSeen += 1;
        
        
    // And we store the updated value of our counter
        
    userStats.set(nametimesSeen);
        
        
    // And instead of showing a global message, we'll now show a private message to this user.
        // The message will be different, depending on whether this is the first time that this user joined the server.
        
    if(timesSeen==1)
            
    server.say("Welcome " name ", thank you for deciding to check out our server!"uidFROM_HOST);
        else
            
    server.say("Welcome back " name ", this is the " timesSeen "th time that you joined our server :D"uidFROM_HOST);
    }

    // The playerChat event that will happen at every chat message
    int playerChat(int uidstring msg)
    {
        
    // Split the message on spaces
        
    array<string>@ arguments msg.split(" ");
        
        
    // We need at least 1 argument in our message
        
    if(arguments.length()>=1)
        {
            
    // We only need to do something if the first word in the message is the command (first word = argument 0)
            
    if( arguments[0] == "!seen" )
            {
                
    // For this command, we'll need at least 2 arguments in the message (the command itself, and a uid)
                
    if(arguments.length()<2)
                {
                    
    server.say("!seen shows join statistics of a certain user."uidFROM_SERVER);
                    
    server.say("Usage:   !seen <uid>"uidFROM_SERVER);
                    
    server.say("Example: !seen 152"uidFROM_SERVER);
                }
                else
                {
                    
    // The second word should be the unique identifier of the user of whom we want to get the statistics of
                    
    int buid parseInt(arguments[1]);
                    
                    
    // Get the username that matches the unique identifier
                    
    string name server.getUserName(buid);
                    
                    
    // The getUserName function returns something empty when the requested uid is not online
                    
    if(name=="")
                    {
                        
    server.say("!seen shows join statistics of a certain user."uidFROM_SERVER);
                        
    server.say("Usage:   !seen <uid>"uidFROM_SERVER);
                        
    server.say("Example: !seen 152"uidFROM_SERVER);
                    }
                    else
                    {
                        
    // Get the amount of times that we've seen the player before
                        
    int timesSeen;
                        if( 
    not userStats.get(nametimesSeen) )
                        {
                            
    timesSeen 0;
                        }
                        
                        
    // And show it as output to the user that requested it
                        
    server.say("User " name " (" buid ") has been seen " timesSeen " times on this server."uidFROM_SERVER);
                    }
                }
            }
        }
        
        
    // You can change broadcasting levels using this function, but here, we'll change nothing by returning BROADCAST_AUTO
        
    return BROADCAST_AUTO;

    So, we now have user statistics that will allow you to find out which usernames are commonly used on your server. Using the localStorage.as file from the first post in this thread, we'll be able to keep the statistics stored across sessions. The localStorage object is very similar to the dictionary object, but the localStorage object can also load and save the data to a file.
    PHP Code:
    // Include the localStorage file
    #include "localStorage.as"

    // Create our dictionary as global variable
    localStorage userStats("userJoinStatistics.asdata");

    // The main function, we don't need this at the moment, but the script won't work without it being defined
    void main() {}

    // This function will get called when a player joins the game
    void playerAdded(int uid)
    {
        
    // Create a new variable holding the username
        
    string name server.getUserName(uid);
        
        
    // Get the amount of times that we've seen this player before
        
    int timesSeen;
        if( 
    not userStats.get(nametimesSeen) )
        {
            
    timesSeen 0;
        }
        
        
    // As the player just joined, we have to increase our timesSeen counter by 1
        
    timesSeen += 1;
        
        
    // And we store the updated value of our counter
        
    userStats.set(nametimesSeen);
        
        
    // Save the statistics
        
    userStats.save();
        
        
    // And instead of showing a global message, we'll now show a private message to this user.
        // The message will be different, depending on whether this is the first time that this user joined the server.
        
    if(timesSeen==1)
            
    server.say("Welcome " name ", thank you for deciding to check out our server!"uidFROM_HOST);
        else
            
    server.say("Welcome back " name ", this is the " timesSeen "th time that you joined our server :D"uidFROM_HOST);
    }

    // The playerChat event that will happen at every chat message
    int playerChat(int uidstring msg)
    {
        
    // Split the message on spaces
        
    array<string>@ arguments msg.split(" ");
        
        
    // We need at least 1 argument in our message
        
    if(arguments.length()>=1)
        {
            
    // We only need to do something if the first word in the message is the command (first word = argument 0)
            
    if( arguments[0] == "!seen" )
            {
                
    // For this command, we'll need at least 2 arguments in the message (the command itself, and a uid)
                
    if(arguments.length()<2)
                {
                    
    server.say("!seen shows join statistics of a certain user."uidFROM_SERVER);
                    
    server.say("Usage:   !seen <uid>"uidFROM_SERVER);
                    
    server.say("Example: !seen 152"uidFROM_SERVER);
                }
                else
                {
                    
    // The second word should be the unique identifier of the user of whom we want to get the statistics of
                    
    int buid parseInt(arguments[1]);
                    
                    
    // Get the username that matches the unique identifier
                    
    string name server.getUserName(buid);
                    
                    
    // The getUserName function returns something empty when the requested uid is not online
                    
    if(name=="")
                    {
                        
    server.say("!seen shows join statistics of a certain user."uidFROM_SERVER);
                        
    server.say("Usage:   !seen <uid>"uidFROM_SERVER);
                        
    server.say("Example: !seen 152"uidFROM_SERVER);
                    }
                    else
                    {
                        
    // Get the amount of times that we've seen the player before
                        
    int timesSeen;
                        if( 
    not userStats.get(nametimesSeen) )
                        {
                            
    timesSeen 0;
                        }
                        
                        
    // And show it as output to the user that requested it
                        
    server.say("User " name " (" buid ") has been seen " timesSeen " times on this server."uidFROM_SERVER);
                    }
                }
            }
        }
        
        
    // You can change broadcasting levels using this function, but here, we'll change nothing by returning BROADCAST_AUTO
        
    return BROADCAST_AUTO;

    So, now you have a system that will keep track of usernames. Possible further additions that you can make:
    • Allow the !seen command to search on names instead of unique identifiers.
    • Add the relative time when a user was last seen.
    • Keep track of how much time a user spends on the server.
    • Allow the script to be used by multiple running servers (use the servername or server port to create seperate filenames for each server)
    • ...


    Just for the record (to keep this on topic ), here's the script rewritten as chat plugin for the script wrappers earlier in this thread:
    • chatPlugin_joinStats.as
      PHP Code:
      #include "utils.as"
      #include "chatManager.as"

      void chatPlugin_joinStats_seenCommand(chatMessagecmd)
      {
          
      chatPlugin_joinStatsobj;
          
      cmd.argument.retrieve(@obj);
          
      obj.callback_seenCommand(cmd);
      }

      class 
      chatPlugin_joinStats
      {
          
      // Create our dictionary as global variable
          
      localStorageuserStats;
          
          
      // A reference to the chat manager
          
      chatManagerchtmngr;
          
          
      // internal flag
          
      bool registered;
          
          
          
      chatPlugin_joinStats(chatManager_chtmngr)
          {
              @
      chtmngr = @_chtmngr;

              
      // Register the callbacks
              
      chtmngr.addCommand("seen", @chatPlugin_joinStats_seenCommand, @any(@this), trueAUTH_ALL);
              
      server.setCallback("playerAdded""playerAdded", @this);
              
              
      // Load the statistics file
              
      @userStats = @localStorage("userJoinStatistics.asdata");
              
              
      registered true;
          }

          ~
      chatPlugin_joinStats()
          {
              
      destroy();
          }

          
      void destroy()
          {
              if(
      registered)
              {
                  
      chtmngr.removeCommand("seen");
                  
      server.deleteCallback("playerAdded""playerAdded", @this);
                  
      registered false;
              }
          }
          
          
      // This function will get called when a player joins the game
          
      void playerAdded(int uid)
          {
              
      // Create a new variable holding the username
              
      string name server.getUserName(uid);
              
              
      // Get the amount of times that we've seen this player before
              
      int timesSeen;
              if( 
      not userStats.get(nametimesSeen) )
              {
                  
      timesSeen 0;
              }
              
              
      // As the player just joined, we have to increase our timesSeen counter by 1
              
      timesSeen += 1;
              
              
      // And we store the updated value of our counter
              
      userStats.set(nametimesSeen);
          
              
      // Save the statistics
              
      userStats.save();
              
              
      // And instead of showing a global message, we'll now show a private message to this user.
              // The message will be different, depending on whether this is the first time that this user joined the server.
              
      if(timesSeen==1)
                  
      server.say("Welcome " name ", thank you for deciding to check out our server!"uidFROM_HOST);
              else
                  
      server.say("Welcome back " name ", this is the " timesSeen "th time that you joined our server :D"uidFROM_HOST);
          }

          
      void callback_seenCommand(chatMessagecmsg)
          {
              
      // We need at least 1 argument and that argument needs to be a number
              
      if(cmsg.emsgLen<|| !isNumber(cmsg.emsg[1]))
              {
                  
      cmsg.privateGameCommand.message("!seen shows join statistics of a certain user.""information.png"30000.0ftrue);
                  
      cmsg.privateGameCommand.message("Usage:   !seen <uid>",                           "information.png"30000.0ftrue);
                  
      cmsg.privateGameCommand.message("Example: !seen 152",                             "information.png"30000.0ftrue);
                  return;
              }
              
              
      // The second word should be the unique identifier of the user of whom we want to get the statistics of
              
      int buid parseInt(cmsg.emsg[1]);
                          
              
      // Get the username that matches the unique identifier
              
      string name server.getUserName(buid);
                          
              
      // The getUserName function returns something empty when the requested uid is not online
              
      if(name=="")
              {
                  
      cmsg.privateGameCommand.message("!seen shows join statistics of a certain user.""information.png"30000.0ftrue);
                  
      cmsg.privateGameCommand.message("Usage:   !seen <uid>",                           "information.png"30000.0ftrue);
                  
      cmsg.privateGameCommand.message("Example: !seen 152",                             "information.png"30000.0ftrue);
                  return;
              }
              
              
      // Get the amount of times that we've seen the player before
              
      int timesSeen;
              if(!
      userStats.get(nametimesSeen))
                  
      timesSeen 0;
              
              
      // And show it as output to the user that requested it
              
      cmsg.privateGameCommand.message("User " name " (" buid ") has been seen " timesSeen " times on this server.""chart_bar.png"30000.0ftrue);
          }

    • your script file
      PHP Code:
      #include "chatManager.as"
      #include "chatPlugin_joinStats.as"

      chatManager chatSystem();
      chatPlugin_joinStats joinStats(@chatSystem);
      void main() {} 


    (also, I've just updated the attachment of the first post, as there was a small bug in the localStorage.as file (line 262)).

  9. 3 users found this post helpful: EBs Servers, PenguinvilleBus1120, tdev
  10. #7
    EBs Servers
    EBs Servers is offline
    EBs Servers's Avatar
    Join Date
    Dec 2011
    Location
    this
    Posts
    248
    Country: United States

    Default Re: server scripts (download)

    Quote Originally Posted by neorej16 View Post
    I received a private message today, in which someone asked for some more information about scripting. As there's actually not a lot documentation about how to write a script from scratch, I've decided to put an extra example here. (and the private messaging system doesn't allow messages with more than 5000 characters, which is the main reason why I put it here ).

    The language which you use for your scripts is AngelScript. The syntax and default functions of the class are explained here (in combination with the wiki page).

    The scripting implementation of the Rigs of Rods server is event-based, which means that you'll be able to execute code when certain events happen. The current available events on the server are: the server starts (main), a new player joins the server (playerAdded), a player leaves the server (playerDeleted), a player says something in the chat (playerChat), the client of a player sends a script message (gameCmd) and a sixth event that just happens every 200 milliseconds (frameStep).

    At each of those events, you can execute code. Here's a very simple example that just shows a chat message to all players on the playerAdded event:
    << php >>
    You can execute that script by simply putting it in a text file with extension .as, and specify the file as scriptfile in the server configuration.

    The next step in our simple script would be to add the username to the message. We can do this using the string server.getUserName(int uid) function:
    << php >>

    That's still a very simple example. More complicated would be to hold statistics of usernames. We can do this by using a dictionary object as global variable. A dictionary object can store information and retrieve it again, based on a name (so, like a dictionary). So we're just going to store a simple number ('int') for every username that joins the server, and every time that we see the username again, we increase the counter by 1. (so the first time that the user joins, the counter will be 1, the second time that the user joins, the counter will be 2, etc).
    << php >>

    That's already quite a useful script Just as example, I'll also add a chat command now, that will allow you to see how many times a certain player joined the server:
    PHP Code:
    // Create our dictionary as global variable
    dictionary userStats();

    // The main function, we don't need this at the moment, but the script won't work without it being defined
    void main() {}

    // This function will get called when a player joins the game
    void playerAdded(int uid)
    {
        
    // Create a new variable holding the username
        
    string name server.getUserName(uid);
        
        
    // Get the amount of times that we've seen this player before
        
    int timesSeen;
        if( 
    not userStats.get(nametimesSeen) )
        {
            
    timesSeen 0;
        }
        
        
    // As the player just joined, we have to increase our timesSeen counter by 1
        
    timesSeen += 1;
        
        
    // And we store the updated value of our counter
        
    userStats.set(nametimesSeen);
        
        
    // And instead of showing a global message, we'll now show a private message to this user.
        // The message will be different, depending on whether this is the first time that this user joined the server.
        
    if(timesSeen==1)
            
    server.say("Welcome " name ", thank you for deciding to check out our server!"uidFROM_HOST);
        else
            
    server.say("Welcome back " name ", this is the " timesSeen "th time that you joined our server :D"uidFROM_HOST);
    }

    // The playerChat event that will happen at every chat message
    int playerChat(int uidstring msg)
    {
        
    // Split the message on spaces
        
    array<string>@ arguments msg.split(" ");
        
        
    // We need at least 1 argument in our message
        
    if(arguments.length()>=1)
        {
            
    // We only need to do something if the first word in the message is the command (first word = argument 0)
            
    if( arguments[0] == "!seen" )
            {
                
    // For this command, we'll need at least 2 arguments in the message (the command itself, and a uid)
                
    if(arguments.length()<2)
                {
                    
    server.say("!seen shows join statistics of a certain user."uidFROM_SERVER);
                    
    server.say("Usage:   !seen <uid>"uidFROM_SERVER);
                    
    server.say("Example: !seen 152"uidFROM_SERVER);
                }
                else
                {
                    
    // The second word should be the unique identifier of the user of whom we want to get the statistics of
                    
    int buid parseInt(arguments[1]);
                    
                    
    // Get the username that matches the unique identifier
                    
    string name server.getUserName(buid);
                    
                    
    // The getUserName function returns something empty when the requested uid is not online
                    
    if(name=="")
                    {
                        
    server.say("!seen shows join statistics of a certain user."uidFROM_SERVER);
                        
    server.say("Usage:   !seen <uid>"uidFROM_SERVER);
                        
    server.say("Example: !seen 152"uidFROM_SERVER);
                    }
                    else
                    {
                        
    // Get the amount of times that we've seen the player before
                        
    int timesSeen;
                        if( 
    not userStats.get(nametimesSeen) )
                        {
                            
    timesSeen 0;
                        }
                        
                        
    // And show it as output to the user that requested it
                        
    server.say("User " name " (" buid ") has been seen " timesSeen " times on this server."uidFROM_SERVER);
                    }
                }
            }
        }
        
        
    // You can change broadcasting levels using this function, but here, we'll change nothing by returning BROADCAST_AUTO
        
    return BROADCAST_AUTO;

    So, we now have user statistics that will allow you to find out which usernames are commonly used on your server. Using the localStorage.as file from the first post in this thread, we'll be able to keep the statistics stored across sessions. The localStorage object is very similar to the dictionary object, but the localStorage object can also load and save the data to a file.
    PHP Code:
    // Include the localStorage file
    #include "localStorage.as"

    // Create our dictionary as global variable
    localStorage userStats("userJoinStatistics.asdata");

    // The main function, we don't need this at the moment, but the script won't work without it being defined
    void main() {}

    // This function will get called when a player joins the game
    void playerAdded(int uid)
    {
        
    // Create a new variable holding the username
        
    string name server.getUserName(uid);
        
        
    // Get the amount of times that we've seen this player before
        
    int timesSeen;
        if( 
    not userStats.get(nametimesSeen) )
        {
            
    timesSeen 0;
        }
        
        
    // As the player just joined, we have to increase our timesSeen counter by 1
        
    timesSeen += 1;
        
        
    // And we store the updated value of our counter
        
    userStats.set(nametimesSeen);
        
        
    // Save the statistics
        
    userStats.save();
        
        
    // And instead of showing a global message, we'll now show a private message to this user.
        // The message will be different, depending on whether this is the first time that this user joined the server.
        
    if(timesSeen==1)
            
    server.say("Welcome " name ", thank you for deciding to check out our server!"uidFROM_HOST);
        else
            
    server.say("Welcome back " name ", this is the " timesSeen "th time that you joined our server :D"uidFROM_HOST);
    }

    // The playerChat event that will happen at every chat message
    int playerChat(int uidstring msg)
    {
        
    // Split the message on spaces
        
    array<string>@ arguments msg.split(" ");
        
        
    // We need at least 1 argument in our message
        
    if(arguments.length()>=1)
        {
            
    // We only need to do something if the first word in the message is the command (first word = argument 0)
            
    if( arguments[0] == "!seen" )
            {
                
    // For this command, we'll need at least 2 arguments in the message (the command itself, and a uid)
                
    if(arguments.length()<2)
                {
                    
    server.say("!seen shows join statistics of a certain user."uidFROM_SERVER);
                    
    server.say("Usage:   !seen <uid>"uidFROM_SERVER);
                    
    server.say("Example: !seen 152"uidFROM_SERVER);
                }
                else
                {
                    
    // The second word should be the unique identifier of the user of whom we want to get the statistics of
                    
    int buid parseInt(arguments[1]);
                    
                    
    // Get the username that matches the unique identifier
                    
    string name server.getUserName(buid);
                    
                    
    // The getUserName function returns something empty when the requested uid is not online
                    
    if(name=="")
                    {
                        
    server.say("!seen shows join statistics of a certain user."uidFROM_SERVER);
                        
    server.say("Usage:   !seen <uid>"uidFROM_SERVER);
                        
    server.say("Example: !seen 152"uidFROM_SERVER);
                    }
                    else
                    {
                        
    // Get the amount of times that we've seen the player before
                        
    int timesSeen;
                        if( 
    not userStats.get(nametimesSeen) )
                        {
                            
    timesSeen 0;
                        }
                        
                        
    // And show it as output to the user that requested it
                        
    server.say("User " name " (" buid ") has been seen " timesSeen " times on this server."uidFROM_SERVER);
                    }
                }
            }
        }
        
        
    // You can change broadcasting levels using this function, but here, we'll change nothing by returning BROADCAST_AUTO
        
    return BROADCAST_AUTO;

    So, now you have a system that will keep track of usernames. Possible further additions that you can make:
    • Allow the !seen command to search on names instead of unique identifiers.
    • Add the relative time when a user was last seen.
    • Keep track of how much time a user spends on the server.
    • Allow the script to be used by multiple running servers (use the servername or server port to create seperate filenames for each server)
    • ...


    Just for the record (to keep this on topic ), here's the script rewritten as chat plugin for the script wrappers earlier in this thread:
    • chatPlugin_joinStats.as
      PHP Code:
      #include "utils.as"
      #include "chatManager.as"

      void chatPlugin_joinStats_seenCommand(chatMessagecmd)
      {
          
      chatPlugin_joinStatsobj;
          
      cmd.argument.retrieve(@obj);
          
      obj.callback_seenCommand(cmd);
      }

      class 
      chatPlugin_joinStats
      {
          
      // Create our dictionary as global variable
          
      localStorageuserStats;
          
          
      // A reference to the chat manager
          
      chatManagerchtmngr;
          
          
      // internal flag
          
      bool registered;
          
          
          
      chatPlugin_joinStats(chatManager_chtmngr)
          {
              @
      chtmngr = @_chtmngr;

              
      // Register the callbacks
              
      chtmngr.addCommand("seen", @chatPlugin_joinStats_seenCommand, @any(@this), trueAUTH_ALL);
              
      server.setCallback("playerAdded""playerAdded", @this);
              
              
      // Load the statistics file
              
      @userStats = @localStorage("userJoinStatistics.asdata");
              
              
      registered true;
          }

          ~
      chatPlugin_joinStats()
          {
              
      destroy();
          }

          
      void destroy()
          {
              if(
      registered)
              {
                  
      chtmngr.removeCommand("seen");
                  
      server.deleteCallback("playerAdded""playerAdded", @this);
                  
      registered false;
              }
          }
          
          
      // This function will get called when a player joins the game
          
      void playerAdded(int uid)
          {
              
      // Create a new variable holding the username
              
      string name server.getUserName(uid);
              
              
      // Get the amount of times that we've seen this player before
              
      int timesSeen;
              if( 
      not userStats.get(nametimesSeen) )
              {
                  
      timesSeen 0;
              }
              
              
      // As the player just joined, we have to increase our timesSeen counter by 1
              
      timesSeen += 1;
              
              
      // And we store the updated value of our counter
              
      userStats.set(nametimesSeen);
          
              
      // Save the statistics
              
      userStats.save();
              
              
      // And instead of showing a global message, we'll now show a private message to this user.
              // The message will be different, depending on whether this is the first time that this user joined the server.
              
      if(timesSeen==1)
                  
      server.say("Welcome " name ", thank you for deciding to check out our server!"uidFROM_HOST);
              else
                  
      server.say("Welcome back " name ", this is the " timesSeen "th time that you joined our server :D"uidFROM_HOST);
          }

          
      void callback_seenCommand(chatMessagecmsg)
          {
              
      // We need at least 1 argument and that argument needs to be a number
              
      if(cmsg.emsgLen<|| !isNumber(cmsg.emsg[1]))
              {
                  
      cmsg.privateGameCommand.message("!seen shows join statistics of a certain user.""information.png"30000.0ftrue);
                  
      cmsg.privateGameCommand.message("Usage:   !seen <uid>",                           "information.png"30000.0ftrue);
                  
      cmsg.privateGameCommand.message("Example: !seen 152",                             "information.png"30000.0ftrue);
                  return;
              }
              
              
      // The second word should be the unique identifier of the user of whom we want to get the statistics of
              
      int buid parseInt(cmsg.emsg[1]);
                          
              
      // Get the username that matches the unique identifier
              
      string name server.getUserName(buid);
                          
              
      // The getUserName function returns something empty when the requested uid is not online
              
      if(name=="")
              {
                  
      cmsg.privateGameCommand.message("!seen shows join statistics of a certain user.""information.png"30000.0ftrue);
                  
      cmsg.privateGameCommand.message("Usage:   !seen <uid>",                           "information.png"30000.0ftrue);
                  
      cmsg.privateGameCommand.message("Example: !seen 152",                             "information.png"30000.0ftrue);
                  return;
              }
              
              
      // Get the amount of times that we've seen the player before
              
      int timesSeen;
              if(!
      userStats.get(nametimesSeen))
                  
      timesSeen 0;
              
              
      // And show it as output to the user that requested it
              
      cmsg.privateGameCommand.message("User " name " (" buid ") has been seen " timesSeen " times on this server.""chart_bar.png"30000.0ftrue);
          }

    • your script file
      << php >>


    (also, I've just updated the attachment of the first post, as there was a small bug in the localStorage.as file (line 262)).
    BTW, Do you know if the Server Auto restart goes under the script file if it fails to run? because i get "heartbeat faliures" i dont know why

  11. #8
    graysonk95
    graysonk95 is offline
    graysonk95's Avatar
    Join Date
    Jul 2010
    Location
    C:\Program Files (x86)\Rigs of Rods\rigsofrods.exe
    Age
    18
    Posts
    414
    Country: United States

    Default Re: server scripts (download)

    I can't get the included scripts to work, the server says "Unknown error while adding a new script from file"


    Nevermind, I probably should have opened it to check if everything was set up right first.
    Last edited by graysonk95; 05-20-12 at 01:48 PM.

  12. #9
    neorej16
    neorej16 is offline
    neorej16's Avatar


    Join Date
    Jul 2009
    Location
    Mechelen, Belgium
    Age
    21
    Posts
    169
    Country: Belgium

    Default Re: server scripts (download)

    Quote Originally Posted by EBs Servers View Post
    BTW, Do you know if the Server Auto restart goes under the script file if it fails to run? because i get "heartbeat faliures" i dont know why
    There are 2 possible types of script failures:
    - The server failed to load/parse the script => the server will run as if there was no script
    - An error occurs during script execution => An exception will be logged in the logfile, but the server will continue calling script events.
    The script should never cause the server to shut down or crash.

    The heartbeat failures have to do with the communication with the master server.
    Every minute, a rorserver reports to the master server a list of online players. As long as the master server receives this report every minute, your server will stay in the serverlist.
    The heartbeat failure means that something went wrong while sending the report to the master server. Basicly, this will usually mean that you couldn't connect to the master server or that the connection was broken while sending the report (or while waiting for the response).

    So, if you get heartbeat failures, then there may be a problem with your connection or the connection of the master server. If the connection problem persists, then your rorserver will shut down (which will happen after 5 consequent heartbeat failures), but this has nothing to do with the scripts.

  13. #10
    EBs Servers
    EBs Servers is offline
    EBs Servers's Avatar
    Join Date
    Dec 2011
    Location
    this
    Posts
    248
    Country: United States

    Default Re: server scripts (download)

    PHP Code:
    automatically restart crashed servers  the rorserver init script will check if a server is running before starting it upThus its safe to just execute
     /
    etc/init.d/rorserver start via a cron jobIt will just start a server, if its process is not running anymore (crashed). 
    Like A Bau5

  14. #11
    dogy
    dogy is offline
    dogy's Avatar
    Join Date
    Jun 2011
    Posts
    48
    Country: United States

    Talking Re: server scripts (download)

    Just a quick question: Is it possible to run the server with parental controls? Because I keep getting this message:Click image for larger version. 

Name:	Capture.PNG 
Views:	309 
Size:	45.2 KB 
ID:	355332
    ---UPDATE---
    Also a compliment: I tried make a server about 7 months ago and failed because I didn't get what the heck the wiki was telling me, then i saw this and i completely understand now. Thanks for your help!
    Last edited by dogy; 11-24-12 at 06:54 PM.

  15. one user found this post helpful: neorej16
  16. #12
    neorej16
    neorej16 is offline
    neorej16's Avatar


    Join Date
    Jul 2009
    Location
    Mechelen, Belgium
    Age
    21
    Posts
    169
    Country: Belgium

    Default Re: server scripts (download)

    Quote Originally Posted by dogy View Post
    Just a quick question: Is it possible to run the server with parental controls? Because I keep getting this message:Click image for larger version. 

Name:	Capture.PNG 
Views:	309 
Size:	45.2 KB 
ID:	355332
    ---UPDATE---
    Also a compliment: I tried make a server about 7 months ago and failed because I didn't get what the heck the wiki was telling me, then i saw this and i completely understand now. Thanks for your help!
    The root error is the "message does not contain a body". This is probably caused by your firewall or router, but I've never encountered this problem myself, so I'm not sure what would fix it.

  17. one user found this post helpful: dogy
  18. #13
    anonymous1
    anonymous1 is offline
    anonymous1's Avatar

    Join Date
    May 2011
    Posts
    2,883
    Country: United States

    Default Re: server scripts (download)

    Quote Originally Posted by dogy View Post
    Message does not appear to contain a body
    Please make sure that your terrain name doesn't contain any spaces. If you're not using the servergui, then also make sure that your server name doesn't contain spaces.

    Source: Server_Setup_Tutorial#Troubleshooting.

  19. one user found this post helpful: EBs Servers
  20. #14
    EBs Servers
    EBs Servers is offline
    EBs Servers's Avatar
    Join Date
    Dec 2011
    Location
    this
    Posts
    248
    Country: United States

    Default Re: server scripts (download)

    For example: China town will result in a fail...
    China_Town is the correct server name
    You have to use the "_" symbol when using a space between the name


    Quote Originally Posted by neorej16 View Post
    The root error is the "message does not contain a body". This is probably caused by your firewall or router, but I've never encountered this problem myself, so I'm not sure what would fix it.
    Like A Bau5

  21. #15
    dogy
    dogy is offline
    dogy's Avatar
    Join Date
    Jun 2011
    Posts
    48
    Country: United States

    Arrow Re: server scripts (download)

    Quote Originally Posted by EBs Servers View Post
    For example: China town will result in a fail...
    China_Town is the correct server name
    You have to use the "_" symbol when using a space between the name
    I did all that already. Like neorej16 said: "This is probably caused by your firewall or router, but I've never encountered this problem myself,..." its probably because of the Parental Controls which the firewall is probably blocking it. Also hear is the full message(NOTE: 2 Images):Click image for larger version. 

Name:	Capture.PNG 
Views:	305 
Size:	96.9 KB 
ID:	355391Click image for larger version. 

Name:	Capture2.PNG 
Views:	296 
Size:	15.7 KB 
ID:	355390

    - - - Updated - - -

    So it is probably the Parental Controls with the Firewall.

  22. #16
    EBs Servers
    EBs Servers is offline
    EBs Servers's Avatar
    Join Date
    Dec 2011
    Location
    this
    Posts
    248
    Country: United States

    Default Re: server scripts (download)

    Quote Originally Posted by dogy View Post
    I did all that already. Like neorej16 said: "This is probably caused by your firewall or router, but I've never encountered this problem myself,..." its probably because of the Parental Controls which the firewall is probably blocking it. Also hear is the full message(NOTE: 2 Images):Click image for larger version. 

Name:	Capture.PNG 
Views:	305 
Size:	96.9 KB 
ID:	355391Click image for larger version. 

Name:	Capture2.PNG 
Views:	296 
Size:	15.7 KB 
ID:	355390

    - - - Updated - - -

    So it is probably the Parental Controls with the Firewall.
    Okay. You need to port forward. Make an exception in your firewall to let the Program run and host the server.
    Find the External IP of the hosting computer.
    Paste it into the server cmd file
    Make sure you select the Host ip internal to use and create the port with.
    Like A Bau5

  23. #17
    dogy
    dogy is offline
    dogy's Avatar
    Join Date
    Jun 2011
    Posts
    48
    Country: United States

    Angry Re: server scripts (download)

    Quote Originally Posted by EBs Servers View Post
    Okay. You need to port forward. Make an exception in your firewall to let the Program run and host the server.
    Find the External IP of the hosting computer.
    Paste it into the server cmd file
    Make sure you select the Host ip internal to use and create the port with.
    How would you port forward a computer with no router but a modem. Because i tried to port forward it but failed because it would not give me any access through the modem.

  24. #18
    anonymous1
    anonymous1 is offline
    anonymous1's Avatar

    Join Date
    May 2011
    Posts
    2,883
    Country: United States

    Default Re: server scripts (download)

    Quote Originally Posted by dogy View Post
    How would you port forward a computer with no router but a modem. Because i tried to port forward it but failed because it would not give me any access through the modem.
    Modems don't need port forwarding. Port forwarding allow a router to pass a Public IP address. You need a broadband line, allowing you to port forward your router.

  25. #19
    dogy
    dogy is offline
    dogy's Avatar
    Join Date
    Jun 2011
    Posts
    48
    Country: United States

    Question Re: server scripts (download)

    Quote Originally Posted by anonymous1 View Post
    Modems don't need port forwarding. Port forwarding allow a router to pass a Public IP address. You need a broadband line, allowing you to port forward your router.
    What do you mean by a broadband line? Also i did some exploring and i was told i had to make my ip static also, when i did that i got this:
    Click image for larger version. 

Name:	Capture.PNG 
Views:	28 
Size:	49.7 KB 
ID:	360394Click image for larger version. 

Name:	Capture1.PNG 
Views:	32 
Size:	34.4 KB 
ID:	360395

  26. #20
    JDM
    JDM is offline
    JDM's Avatar
    Join Date
    Apr 2012
    Location
    In a house
    Age
    14
    Posts
    1,129
    Country: Canada

    Default Re: server scripts (download)

    These are some of the best scripts i used Thanks
    "If you love life, don't waste time, for time is what life is made up of." Bruce Lee

  27. one user found this post helpful: neorej16

Similar Threads

  1. what blender scripts do you need for uv mapping?
    By jcb in forum Content Support
    Replies: 3
    Last Post: 08-18-11, 01:10 AM
  2. !!!custom sound scripts!!!
    By Eminox in forum Role Playing Chat
    Replies: 13
    Last Post: 01-03-11, 01:30 PM
  3. Blender scripts
    By Bcazbobby in forum Mod tech
    Replies: 4
    Last Post: 11-16-10, 10:19 PM
  4. sound scripts
    By wishrightnow in forum Content Support
    Replies: 1
    Last Post: 09-10-10, 11:45 PM
  5. i need help installing the scripts
    By De@thSheep in forum Mod tech
    Replies: 5
    Last Post: 01-06-09, 12:32 AM

Posting Permissions



About Rigs of Rods

    Rigs of Rods is a unique soft body physics simulator.


Some Tools


Partners

SourceForge.net

Follow us

Twitter youtube Facebook RSS Feed


impressum