Left 4 Dead 2

Left 4 Dead 2

Not enough ratings
(MSC) (Programming) How to auto load your own MSC Scripts.
By [FoRcE]army_guy3
This guide will explain how to use the new MSC subscript auto load system.
   
Award
Favorite
Favorited
Unfavorite
What is this for?
This guide is for programmers who want to know about auto loading your MSC subscripts into the Master Script Controller. This method requires the user to also be subscribed to the Master Script Controller. Remember to place the MSC as a required addon when you upload your addon or your subscribes won't know.

https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2203978515

The new update gave us the ability to add specific script files into our VPK files without conflicting. This is great but at the same time not so great as it's all loading into the same scope. Scripts are going to conflict as they try to use the same functions. The MSC corrects this by putting each MSC sub script into its own space and carrying these functions to each of them.
How to auto load sub scripts
Step 1:

We need a VPK to avoid the file conflicting with others.

Step 2:

Set up your vpk structure and name your main script file MSC_UNIQUENAME_GOES_HERE.nut:

Example:
MSC_AG3_MyScript
MSC_kevin_slayall


Keep in mind that this script name must be unique from other script names or it will conflict with them. I recommend using a prefix with your signature.

This file should go in scripts/vscripts/ directory.

Step 3:

Next we need to include the file that is going to be executed by the game.

Create a new file called "scriptedmode_addon.nut"

This file will be automatically executed by the game when your vpk addon is run. This is what we will use to load our script into the MSC system.

Step 4:

Inside this file put the following code:

MSC_LoadScript("MSC_AG3_MyScript", {});

This code should point to your main script WITHOUT .nut extension. In my case it was "MSC_AG3_MyScript".

Step 5:

Compile your vpk and place it in your addons directory.
Result
Your script should now auto load into the MSC system. Keep in mind that some functions are different from normal use in mutations to allow reverse compatiblity for future updates by the MSC.
Troubleshooting
If your script does not load then:

Make sure you placed the files into the correct directories in your VPK
Make sure the VPK is active ingame.
Make sure the script is using the proper script functions for use with the MSC.
Make sure your "scriptedmode_addon.nut" file is in the proper directory.
Make sure your "scriptedmode_addon.nut" is named exactly this.
Make sure your "scriptedmode_addon.nut" file is pointing to your main script file.
Make sure your main script file is in the same VPK directory as your "scriptedmode_addon.nut" file.