Updated VScript tutorial for HL2 mappers (markdown)

Blixibon 2020-05-24 23:18:45 -05:00
parent e98d3ff3d0
commit ec14a80716

@ -20,7 +20,7 @@ Open the file using Notepad, Notepad++, or any other text editor.
---
### 2. Adding I/O code
### 2. Adding the code
Inside of this script file, we will add code which makes the player fire the `SetHealth` input with a parameter of `85`.
@ -31,7 +31,7 @@ After you have added `SetPlayerHealthTo85`, add a `{` on the line below it, and
Your file should now look like this:
```squirrel
function MakePlayerDropWeapon()
function SetPlayerHealthTo85()
{
}
```
@ -41,7 +41,7 @@ Now we will make the function actually fire `SetHealth` on the player.
In between the `{` and `}` lines, add a new line with `EntFire()` inside.
```squirrel
function MakePlayerDropWeapon()
function SetPlayerHealthTo85()
{
EntFire()
}
@ -58,10 +58,40 @@ EntFire("!player", "SetHealth", "85")
In the function itself, it would look like this:
```squirrel
function MakePlayerDropWeapon()
function SetPlayerHealthTo85()
{
EntFire("!player", "SetHealth", "85")
}
```
Whenever the `SetPlayerHealthTo85` function is called, it will fire the `SetHealth` input on the player with a parameter of `85`, which sets the player's health to 85.
Now that we've written our code, it's time to access it from the map.
---
### 3. Running the file
Like outputs, an entity can run a VScript file and store its functions, etc. until the entity is deleted.
Entities can run VScript files through a keyvalue (**Entity scripts**) or an input (`RunScriptFile`). Both of them take the filename of the script(s) to run. The extension is optional and you do not need to insert `scripts/vscripts`.
In Hammer, create an entity (e.g. a `logic_relay` or an `info_target`) and use either the keyvalue or the input to run your test file.
---
### 4. Calling `SetPlayerHealthTo85`
When the entity runs the script, it will have the `SetPlayerHealthTo85` stored and waiting to be fired, similar an output. We need to call that function from somewhere, which would then set the player's health to `85`.
In the I/O system, this can be done by firing `RunScriptCode` on the entity running the script. This input should have a parameter of "SetPlayerHealthTo85()", which will tell the entity to call its `SetPlayerHealthTo85` function.
You can fire `RunScriptCode` with this parameter by using something in the map or by using the `ent_fire` console command in-game.
---
### 5. Testing
Compile your map and load it in-game. Test the `RunScriptCode` input with the `SetPlayerHealthTo85()` parameter. If you followed these steps correctly, the player's health will be set to 85.
If this does not work, check the steps above and make sure you followed them correctly.