Installing Tools

If you already have the Authoring Tools installed, you may skip this section, but you may still want to download Notepad++ if you don't have it already

Installing the Authoring Tools

Hover over the Library button.

Left 4 Dead 2 - How to start making mutations!

Left 4 Dead 2 - How to start making mutations!

Click on Tools in the dropdown menu.

Left 4 Dead 2 - How to start making mutations!

Find Left 4 Dead 2 Authoring Tools and double click it.

Left 4 Dead 2 - How to start making mutations!

Follow instructions to install it.


Installing Notepad++

While not necessary, Notepad++[notepad-plus-plus.org] is highly recommended for editing the script files.


While the Authoring Tools downloads, move onto the next section.


Setting up the Addon Folder

If you already know how to make addon folders, make a modes folder, scripts folder, addoninfo.txt and skip ahead to Step 4.

You can just get this empty template[cdn.discordapp.com] (In a VPK) instead of going through this section, although it could be useful to still go through this section.

Step 1

Create a folder in another folder you'll remember, I suggest in Documents.
Name it anything you want.




Step 2

Create three files in the folder from Step 1: modes folder, scripts folder, and an addoninfo text file.




Step 3

Copy and paste the following text into your addoninfo text file.


"AddonInfo" { addonSteamAppID "550" // the AppID of this addon (550 is L4D2, do not change it) addontitle "My First Mutation" // the title of your addon addonversion "1" // the version of your addon addonauthor "" // put your name here addonDescription "It's my first mutation!" // the description of your addon }
Fill out fields as wanted. (Quotes have to stay)

Make sure to save the file.




Step 4

Create a new text file named first_mutation in your modes folder. (File name should match the mutation code)



Copy and paste the following text into the first_mutation text file.


"first_mutation" { "base" "coop" // the base mode, can be survival, coop, versus, realism, etc "maxplayers" "4" // the maximum players that can join (if 1 on Sacrifice, finale can be done solo) "DisplayTitle" "My First Mutation" // the title displayed for the mode (shown on loading and in the main menu) "Description" "My first mutation!" // text to display in the mutation menu "Image" "maps/any" // the image to display in the mutation menu "Author" "" // the name to display in the mutation menu convar // console variables to set (each variable separated by a line) { sv_cheats 1 sv_infinite_ammo 1 } }

Fill out fields as wanted. (Quotes have to stay)




Step 5

Create a vscripts folder in your scripts folder.




Step 6

Either create a text file named first_mutation in the vscripts folder and change the extension to ".nut".

OR

Download this empty NUT file[cdn.discordapp.com]



Open first_mutation.nut (I recommend using Notepad++[notepad-plus-plus.org] and setting it as the default program for that extension)


Variable Types


  • Null
  • Integers
  • Floats
  • Booleans
  • Strings
  • Functions
  • Tables
  • Arrays
  • Entities
  • Vectors
  • QAngles


Null

Null value, does not contain anything.

Examples: null


Integers[squirrel-lang.org]

These are integers. Like, you know, integers.

Examples: 0, 5, 9999, -10, -142


Floats[squirrel-lang.org]

Floating point stuff, decimal points, that stuff.

Examples: 0.5, 999.1, -1.951321, 1.0


Booleans[squirrel-lang.org]

Just true or false. You use these in if statements.

Examples: true, false


Strings[squirrel-lang.org]

Holds characters.
Immutable (to modify, new string is created).
To create, use quotes around text.

Examples: "hello", "this is a string with integers: 111"


Functions[squirrel-lang.org]

When called, executes the code inside of it.
Can take parameters.
To call a parameter-less function, simply type the name and two parantheses.
To call a function with parameters, type the name and an opening parantheses (, type parameters separated by commas, and close it with a closing parantheses ).
Can return a variable in the function, which can be used to assign a variable by function call.

Examples:
function Func(){ KillEverything() count += 1 ent.Kill() }

function DoThingToEnt(victim) { victim.SetHealth(0) }

function DoOtherThing(first_thing,second_thing,third_thing){ if(first_thing == 1){ return second_thing } }Function call examples: Func(), DoThingToEnt(entity), DoOtherThing(1,2,3)


Tables[squirrel-lang.org]

A table holds keys. Each key has a value paired to it.
A table can hold as many keys as you want (or at least close to it).
A table can be empty.
A key cannot be an integer, but it may contain an integer as long as there is another character.
Curly brackets are used for making tables.
Use table["key"] or table.key to get the value of the key.

Examples: {key = "value", test = null}


Arrays[squirrel-lang.org]

An array/list of objects.

Examples: ["value", 1, null, true, {}]


Entities

These are entity handles for entities in game.
You can use functions in this list on these.


Vectors

Holds x, y, z floats.
Usually used for position/speed variables.

Examples: Vector(0,0,64), Vector(-1,2,-9995)

QAngles

Holds pitch, yaw, roll floats.
Usually used for entity orientation.

Examples: QAngle(-1321,5,9), QAngle(0,0,0)


Coding

Squirrel Documentation Links

I highly suggest reading through the Language Documentation in its entirety.

Understanding Scope

Understanding how scope works is important.
If you don't know how it works, it will be annoying and your code will likely be bad.

Everything is in a root table[squirrel-lang.org].
This root table contains the g_ModeScript table.
This is the table in which your mutation script will be put in.
Local variables can only be referenced/used in the table they were initialized in.

Creating Variables

Using <- creates a new slot in the root table. (variable <- "value")
Using local creates the variable in the current scope. (local variable = "value")

Can also put functions in variables by doing:

local variable = function(parameters){ DoThings() } variable <- function(){ DoOtherThings() }

Specific Expressions

Foreach


Iterates over every val or every key, value pair in a table or array.

foreach(key,val in table){ if(val == key){ delete table[key] } }OR

foreach(val in array) { Say(null,val,false) }

For


Repeats infinitely until reaches end condition.

for(local i=0; i<10; i+=1){ printl(i) }
for(local j=0; i<player_health; i+=2){ ZSpawn({type = ZOMBIE_WITCH}) }

In


Returns whether or not a key is in the table/array.

if("this_key" in table){ return null }

Switch


Basically a shorter, easier way of a chain of if statements.
The switch_variable is what will be compared.
If the switch_variable is equal to one of the cases, it will run the code in that case.

switch(switch_variable) case 1:{ printl("it was 1!") } case "test": { Entities.FindByClassname(null,"player").Kill() } default:{ printl("default case") } }

Comments

Comments are useful to provide comments on code or disable a section of code to debug and such.
Comments do not get processed, so they can't actually do anything.

For single line comments, use //
For multi-line comments, start with /* and end with */


Compiling the VPK

Once you're happy with your mutation or want to test it, you'll have to compile it into a VPK.

  • Simply drag the mutation folder (the folder containing the addoninfo.txt, modes folder, and scripts folder) onto the vpk.exe file in Left 4 Dead 2/bin
  • This will create the vpk in the parent folder of your mutation folder.
  • Drag the vpk file into Left 4 Dead 2/left4dead2/addons
  • Then, start your game.
You can start your mutation either through the main menu, or typing map c2m1_highway first_mutation


Common Errors (and what they mean)

This list is incomplete, if you experience errors and don't understand, please comment.


  • error unfinished string - (String is not closed properly, AKA missing quotation mark)
  • error end of statement expected (; or lf) - (Parantheses not closed properly)


Links and Tips

Useful Links

Useful Tools

Tips

  • Do not try to replace a vpk while still in-game (It likely won't load it properly)
  • Create a shortcut for the vpk.exe and place it in your addons folder
  • Use the script console command to test basic stuff
  • VPKs work by "adding" the files in them to the game, temporarily.

Post a Comment

Powered by Blogger.