Skip to content

Using VScript as a HL2 mapper

Blixibon edited this page Jun 13, 2020 · 7 revisions

This article is for Half-Life 2/Source 2013 mappers who have no experience with VScript to learn what it is and how they can use it in their maps.

You don't need any previous programming experience to use VScript. VScript is only as complex as you want it to be.

There are three main ways in which VScript can be used in Mapbase:

Each of these sections have their own tutorial(s) which start as if you've never used VScript before.

Mapbase's implementation of VScript started with reductor's custom Squirrel integration and code ported from the Alien Swarm SDK; it has been expanded to include functions adjusted specifically for Half-Life 2-related purposes as well as some more access to Valve's mathlib and utility functions.

Using VScript to simplify map logic

Although VScript can make things very complex, it actually works really well for making things less complex.

Source's logic entities (and Mapbase's expansions to them) make the I/O system a flexible tool for doing complex things, like math or storage. However, this can get very complicated very quickly, as several different outputs fire several different inputs on several different entities as one big, messy jumble of icons in Hammer's 3D view.

VScript can be used to simplify these types of logic contraptions, as things like storing numbers, adding/subtracting numbers, finding entities, etc. can happen using just one line of text. This can be done to make map logic seem less complicated and sometimes it's actually necessary to reduce the level's entity count.

If you want to learn how to use VScript, it may be best to start by doing it alongside the I/O system. Click here to go to a tutorial on how you can use VScript to interact with the I/O system.

Using VScript to do what's not possible with I/O

A lot more can be done with VScript than what can normally be done with logic entities and I/O, even with Mapbase's enhancements.

While you can just use VScript to simplify map logic, it also unlocks a lot of potential in other areas. It's a pathway to many abilities some mappers would consider...unnatural. Of course, if you're already a programmer, then using this side of VScript may come naturally. If not, then it may seem a bit more complex, but if you think you can benefit from what it's capable of, then it would definitely be worth the trouble.

Click here to go to a tutorial which makes it simple and easy to understand.

Using VScript to modify game behavior

In some of Valve's games, VScript had unique abilities to modify game-specific behavior. This often replaced dedicated logic entities (e.g. tf_gamerules) or even the regular keyvalue-based scripts files.

For example, in Left 4 Dead 2, you can use VScript to influence or detect the behavior of the AI director which controls zombie spawning. This is often used to choreograph campaign finales.

Half-Life 2 doesn't have any of those kinds of complex built-in game systems, but Mapbase still adds hooks to modify certain HL2-related elements. For example, Mapbase adds NPC_TranslateActivity and NPC_TranslateSchedule hooks for modifying NPC behavior. NPC_TranslateActivity allows VScript to modify the animations a NPC plays during its AI without requiring scripted_sequence.

(TODO: Tutorial)

Clone this wiki locally