Ok, A basic VScript run down. It's been a while, so I've thrown this together based on some other scripts I've done. Nothing is tested so you might need to debug and fix some small bugs.
This is a great page!!!
First and foremost, VScripts are located in the `/csgo/scripts/vscripts/` folder.
1. Make a folder named your maps name in the vscripts folder
VScript files have a .nut extension. I have some really complex scripts in some maps so I've got into a habit of naming the main script folder `main.nut`.
2. Make a file named `main.nut` in your maps VScript folder from step one.
Within your map, you need an entity to execute the script to make it run. I use a logic_relay entity myself, but almost every entity type will work.
3. Open your map in Hammer and add a logic_relay entity
We set the `Entity Scripts` property of the logic_relay to the path of the script file.
4. Set `Entity Scripts` to <map folder from step 1>/main.nut
Now each time a round starts, the logic_relay is created, and the script is executed. This serves really well because we can edit the script on the server, save it, restart the round, and the updated script executes. Much better then compiling the map again to make one little change!
5. Compile your map with the new logic_relay entity pointing at your .nut script and let the game launch the map in developer mode.
So lets get into some VScripting.
6. Open up your .nut file in your favorite text editor
I generally start each script with a print call to state the scripting is executing.
Code:
printl("Executing <MapName> VScript...");
If you save and use `endround` in the game console, you should see this message print to the console on every round start as the logic_relay entity is created (prints to server console on a proper dedicated server).
You will need to loop through players and work out the player count so you can figure out if you want to enable your teleports.
We will create a function for this so we can use local variables in the function scope that will be removed when the function ends. I'll name the function EnableTeleportsIfRequired.
Code:
::EnableTeleportsIfRequired <- function()
{
local player = null;
local team = null;
local CS_TEAM_CT = 3;
local CS_TEAM_T = 2;
local playercount = 0;
while ((player = Entities.FindByClassname(player, "player")) != null)
{
team = player.GetTeam();
if (team == CS_TEAM_T || team == CS_TEAM_CT)
{
playercount++;
}
}
}
Next we need to call the Enable input of the teleports if the required player count is reached. We use the EntFire function as found
here.
Code:
::EnableTeleportsIfRequired <- function()
{
...
if (playercount <= 10)
{
EntFire("name_of_teleport_trigger", "Enable");
}
}
At the end of the script we will call the EnableTeleportsIfRequired function.
Code:
printl("Executing <MapName> VScript...");
::EnableTeleportsIfRequired <- function()
{
...
}
EnableTeleportsIfRequired();
So the entire snippet looks like:
Code:
printl("Executing <MapName> VScript...");
::EnableTeleportsIfRequired <- function()
{
local player = null;
local team = null;
local CS_TEAM_CT = 3;
local CS_TEAM_T = 2;
local playercount = 0;
while ((player = Entities.FindByClassname(player, "player")) != null)
{
team = player.GetTeam();
if (team == CS_TEAM_T || team == CS_TEAM_CT)
{
playercount++;
}
}
if (playercount <= 10)
{
EntFire("name_of_teleport_trigger", "Enable");
}
}
EnableTeleportsIfRequired();
So the fundamental idea is:
1. Attach the VScript nut file to a logic_relay entity
2. Each round start the logic_relay entity is created and the script executes (consider the script to be called inside a round_start event hook)
3. We declare a function that does our work so the local variables are trashed
4. We call the function at the end of the script
My scripts are really large and used to control an entire maps input/outputs because:
1. You can edit the script and restart the round to test the changes without recompiling a map
2. If you dont pack the scripts into your map, people cant join your servers and steal the maps because the input/output logic is safely stored on the server
When your done, compile the map and build cubemaps/stringtables/ect then pack the vscripts into it!!!!
__________________