STEAM GROUP
Left 4 Dead 2 Workshop Beta L4D2WSB
STEAM GROUP
Left 4 Dead 2 Workshop Beta L4D2WSB
4
IN-GAME
36
ONLINE
Founded
15 October, 2012
shotgunefx 12 Feb, 2013 @ 6:16pm
Vscript Snippets
I'd like to start a thread to post some helpful snippets based on the questions I'm getting if that's ok. Maybe a sub-forum is in order? It seems to early for the wiki at this point but if that's thought to be a better place, I'm happy to put it there.


First snippet is an example OnGameEvent_ handler as I found the differentiating between players and other ents a bit unintuitive as far as translating them to actual entity handles. I made it verbose for clarity.


//------------------------------------------------------------------------------ // Example event handling function // event data passed for a given event is specified in resource/modevents.res //------------------------------------------------------------------------------ function OnGameEvent_player_death( event ) { local entindex = null; local ent = null; // get entindex from userid for players/bots or entityid for anything else if (event.rawin("userid")) { // It's a player or bot entindex = event["userid"]; ent = GetPlayerFromUserID(entindex); // convert to an entity so we can ent.GetHealth() etc }else { // Common or something else entindex = event["entityid"]; ent = EntIndexToHScript(entindex); // convert to an entity so we can ent.GetHealth() etc } if (ent.GetClassname() == "player" && ent.IsSurvivor()) { // IsSurvivor only exists for player class not entities in general printl ("Survivor "+GetCharacterDisplayName(ent)+ " was killed"); }else { printl ("entity "+ent+ " was killed"); } }