Are you a fan of Left 4 Dead 2 and want to add in your own map-specific SI models? Look no further! In this guide, we’ll discuss the v-script method and its advantages and disadvantages, as well as provide step-by-step instructions on how to create your own replacements. Get ready to enhance your gaming experience with these simple techniques!
Introduction
This is the method used in my mod, linked below.
https://steamcommunity.com/sharedfiles/filedetails/?id=3164287213
Why This Method?
- Has little to no conflicts with other mods, due to it not actually replacing anything
- Can be configured to automatically disable in multiplayer (so that your friends don’t see errors)
If you follow this guide, your script is already configured to disable in multiplayer. We’ll get to how to change this later. - Can be configured to affect most custom campaign variants of the official campaigns
- No need to find map codes. It uses the name of the map, which is much easier to find.
- Will only appear on specified maps (or maps that might be related). It won’t unintentionally affect other, unrelated maps
- The models will always be replaced on specified maps, regardless of mods installed or load order.
- Can only be used on SI
- Has to be a model replacement in some way. Won’t work if it’s just a texture
- If configured to work in multiplayer, other players will have to install the mod in order to not see errors.
- Can’t replace the viewmodels used in Versus
- Can’t replace the exploded Boomer legs model (at least not to my knowledge)
- Can’t replace the Witch
Also, I don’t actually have a lot of knowledge on v-script. I put together this method based on what I do know. Correct me if I’m wrong on certain things.
Compiling Your Model with a Different Name
You can set the name to whatever you like, but I recommend keeping it to “X_Y”, with X being the name of the special infected and Y being a related term. Example shown on the right.
Compile the model as usual.
Setting Up the Script
Open the nut file with your text editor of choice (I’m using Notepad++), and copy-paste the following code.
Msg(“????\n”);
local mapname = Director.GetMapName()
if(Director.IsSinglePlayerGame() == false)
return;
if(mapname.find(“????”) != null)
IncludeScript(“????”);
Editing the Script
For the first instance of question marks:
Replace the question marks with whatever message you want. This is the message that will show up in the console, when the script gets loaded.
For the second instance of question marks:
Replace the question marks with the name of the map you want the script to run on. It doesn’t have to be the full name, but I would highly recommend putting the full name for custom maps. For official maps, I like to keep it to just the first few letters and numbers of the map (before the underscore) so that it would affect most custom campaign variants of the specified map, as shown below.
If you want to add more maps, add a space and a “|| mapname.find(“????”) != null” after the “null” but before the parenthesis, shown below.
Then replace the question marks with another map. You can repeat this however many times you like, shown in the example below.
For the last instance of question marks:
Replace the question marks with a random name. It cannot contain spaces. Try to make it unique, as it will conflict if someone has theirs set to the same one. Also, remember this name, as it’ll be the name of the second script we need to make.
(Optional) If you want the mod to work in multiplayer, remove the following code:
return;
Your script will now run in multiplayer games.
If you followed the steps, you should be finished with the first script.
Setting Up the Second Script
(For example, I’ve set the last instance of question marks to “mudsmokers”, therefore I’ll name this script “mudsmokers”.)
In that script, copy-paste the following code:
local XXXX = [“models/infected/ZZZZ.mdl”,”models/infected/VVVV.mdl”];
if(!IsModelPrecached(XXXX[1]))
PrecacheModel(XXXX[1]);
BBBB <-
{
OnGameEvent_player_spawn = function(event)
{
local SI = GetPlayerFromUserID(event.userid);
if(SI.IsValid() && !SI.IsSurvivor() && !SI.IsDead())
{
if(SI.GetZombieType() == MMMM)
{
local modelnimi = NetProps.GetPropString(SI, “m_ModelName”);
if(modelnimi == XXXX[0])
SI.SetModel(XXXX[1]);
}
}
}
}
__CollectEventCallbacks(BBBB, “OnGameEvent_”, “GameEventCallbacks”, RegisterScriptGameEventListener);
Editing the Second Script
For ALL instances of “XXXX” (there’s 5 of them), replace them with a related name. No spaces. They all have to be the exact same.
Example: I’ll replace all instances of “XXXX” with “MudSmokers”.
For ALL instances of “BBBB” (there’s 2 of them), replace them with whatever you want. No spaces. They both have to be the exact same. Try to keep this one unique, as it will cause conflicts if someone’s mod has the same one as yours.
Example: I’ll replace all instances of “BBBB” with “mudsmokersvscript”.
For the one instance of “ZZZZ”, replace it with the vanilla name of the SI model you’re replacing.
Example: My mod is meant to replace the Smoker, who uses the model “smoker”. I’ll replace “ZZZZ” with “smoker”.
For the one instance of “VVVV”, replace it with the name of your custom SI model.
Example: My custom SI model’s name is “smoker_mud”. I’ll replace “VVVV” with “smoker_mud”
For the one instance of “MMMM”, replace it with the number corresponding to your SI, as shown on the list.
Example: The Smoker’s number is 1. I’ll replace “MMMM” with “1”.
If you followed all the steps, your script should look something like this.
local MudSmokers = [“models/infected/smoker.mdl”,”models/infected/smoker_mud.mdl”];
if(!IsModelPrecached(MudSmokers[1]))
PrecacheModel(MudSmokers[1]);
mudsmokervscript <-
{
OnGameEvent_player_spawn = function(event)
{
local SI = GetPlayerFromUserID(event.userid);
if(SI.IsValid() && !SI.IsSurvivor() && !SI.IsDead())
{
if(SI.GetZombieType() == 1)
{
local modelnimi = NetProps.GetPropString(SI, “m_ModelName”);
if(modelnimi == MudSmokers[0])
SI.SetModel(MudSmokers[1]);
}
}
}
}
__CollectEventCallbacks(mudsmokervscript, “OnGameEvent_”, “GameEventCallbacks”, RegisterScriptGameEventListener);
Save it. You’re done.
Testing the Mod
Conclusion
And that wraps up our share on Left 4 Dead 2: Adding in Map-Specific SI Models with V-Script. If you have any additional insights or tips to contribute, don’t hesitate to drop a comment below. For a more in-depth read, you can refer to the original article here by cin, who deserves all the credit. Happy gaming!