Talk:L4D2 Vscripts

From Valve Developer Community
Jump to: navigation, search

ent_script_dump is super useful.

Vscript Variables

I compiled a list of all of the variables read by the Director in the server binary. Here's The List. It could use some organization before being placed on the wiki. I also skipped the mutation variables since they're already known through the mutation .nut files. Most of them are self explanatory--if there's any questions about how some are used I might be able to look some of them up. --ProdigySim 01:48, 28 July 2010 (UTC)

That's a great looking list. I'm wondering about one thing, though. Official scripts used variables like ZombieSpawnInFog and it is either TRUE or FALSE. Why is it an INT in the binary? Is it because of the language itself? Thanks a lot for this! --ThaiGrocer 16:51, 28 July 2010 (UTC)
I don't even remember making that list, haha. Yes, it's probably just a semantics thing. As an int, false is 0 and true is everything else. --ProdigySim 07:17, 6 December 2010 (UTC)
Thanks a lot for your help and an explanation! All of the options you had on the list are in the article. --ThaiGrocer 07:42, 6 December 2010 (UTC)

Other functions

Does anyone know if there's any more functions than those used on official scripts? 'Cause it lacks a lot of event calls e.g. OnPlayerDeath. --Winded

I've been looking through the binary a little bit, and I don't really see anything else. The scripting language is set up so they can just call script functions by name whenever they want. This means calling functions in scripts is only added when it's convenient for Valve's mutations/scripting. Map makers can call functions from entity inputs, though. So there's that. If I find anything super useful in the binaries I'll be sure to shout about it. --ProdigySim 07:23, 6 December 2010 (UTC)
Thank you for checking it out. --Winded
Forgot to mention--a less-than-ideal substitute to event calls would be the Update() function, which runs on every game frame. Not the greatest thing to do, but with some trickery you'll be able to code a lot of things without causing too much CPU usage. --ProdigySim 07:26, 6 December 2010 (UTC)
I've tried (and partly succeeded on) making an asi mod for GTA IV, and it didnt have events, only checks like IsPlayerEnteringCar() that where used on a 'while' loop and at the end of it there was a wait for 100 milliseconds, so other stuff can be processed. As you said, it may be expensive for cpu, so I prefer not using a function like that. --Winded

Next()

Note: the Next() function for CEntities takes 1 parameter, should be: Next(null|prev)

As in

ent <- null;
while((ent = Entities.Next(ent)) != null)
{
   printl(ent);
}

I changed on the main page

Squirrel VM table layout

Not a lot is mentioned about the overall table layout of the squirrel VM in this article. It's worth noting a lot of these things. Here's a script I used as a mutation and some results: http://pastie.org/private/tpqmxmer3eypshecckogw As you can see the root namespace contains most of the function and class definitions mentioned on this page. Mutation scripts are loaded as the ::DirectorScript.ChallengeScript table. I'm not sure about where other VScripts are loaded by default, but that can be important I think. --ProdigySim 16:19, 4 July 2012 (PDT)

DirectorOptions delegation

So on this wiki it says

DirectorScript.MapScript.LocalScript.DirectorOptions (When Director Script active) < DirectorScript.MapScript.ChallengeScript.DirectorOptions (Scripted mode only) < DirectorScript.DirectorOptions


But that's not correct if I understand correctly based on what's in director_base.nut . Isn't this correct ?

DirectorScript.MapScript.ChallengeScript.DirectorOptions (Scripted mode only) < DirectorScript.MapScript.LocalScript.DirectorOptions (When Director Script active) < DirectorScript.MapScript.DirectorOptions (I am kind of unsure what is this one) < DirectorScript.DirectorOptions


Special script files

Trying to collect some info on script files that are invoked at special times during the game's lifecycle. --ProdigySim (talk) 09:46, 19 November 2020 (PST)

Script file Scope Invocation Description
scriptedmode.nut unknown Invoked when scripted mode starts? Hosts various ScriptedMode related hooks from the C++ code, invokes Mutation scripts
scriptedmode_addon.nut unknown Invoked when scripted mode starts? per addon Gives addons the chance to run code at the same time as the builtin script
mapspawn.nut unknown Invoked on Map Start Added in the Last Stand Update to run map modifications as soon as the map starts
mapspawn_addon.nut unknown Invoked on Map Start, just after mapspawn.nut Gives addon makers a chance to run a script at the same time as the builtin script.
director_base.nut unknown ??? Sets up some Director constants and the GetDirectorOptions() function which is used by game C++ to get the final DirectorOptions delegated table