L4D2 Level Design/Wandering Witch: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(→‎Changing Behaviour at runtime: used proper Outputs template.)
(→‎Changing Behaviour at runtime: That old script seemed kind of confusing, how about this simpler one? I also changed some text to use <h4> ( don't @ me about logic_script I don't know what it is))
Line 16: Line 16:
Create a text file called '''Witch_behaviour.nut''' (or any sensical name) and put it into the scripts/vscripts folder.<br>  
Create a text file called '''Witch_behaviour.nut''' (or any sensical name) and put it into the scripts/vscripts folder.<br>  
The script should contain the following:
The script should contain the following:
function WitchWalk(){
{{ScrollBox|<source lang=js>
worldspawn_timeofday <- [
const TIME_NIGHT = 0
  "3"
const TIME_DAY = 3
]
worldspawn <- Entities.FindByClassname (null, "worldspawn");
local i = RandomInt(0,worldspawn_timeofday.len()-1);
printl("TimeOfDay is "+worldspawn_timeofday[i]);
printl( worldspawn.__KeyValueFromString("timeofday",worldspawn_timeofday[i]) );
}
function WitchSit(){
worldspawn_timeofday <- [
  "0"
]
worldspawn <- Entities.FindByClassname (null, "worldspawn");
local i = RandomInt(0,worldspawn_timeofday.len()-1);
printl("TimeOfDay is "+worldspawn_timeofday[i]);
printl( worldspawn.__KeyValueFromString("timeofday",worldspawn_timeofday[i]) );
}
{{Note|This script is based on this [[L4D2_Vscript_Examples#Changing_witch_movement_type_on_map_load|Vscript Example]], but merged to one script and changed function names to make more sense.}}


// Note, these only modify witches if they haven't spawned before this function did anything!
function NewWitches_Sit()
{
local worldspawn = Ent("worldspawn")
if( worldspawn.__KeyValueFromInteger( "timeofday", TIME_NIGHT ) );
{
if( developer() )
printl( "Set worldspawn 'timeofday' key to "+tostring(TIME_NIGHT)+", (NIGHTTIME)" )
}
}
function NewWitches_Walk()
{
local worldspawn = Ent("worldspawn")
if( worldspawn.__KeyValueFromInteger( "timeofday", TIME_DAY ) );
{
if( developer() )
printl( "Set worldspawn 'timeofday' key to "+tostring(TIME_DAY)+", (DAYTIME)" )
}
}
</source>}}
Next, place a [[logic_script]] entity into your map, using "Witch_behaviour" in the "Entity Scripts" field.
Next, place a [[logic_script]] entity into your map, using "Witch_behaviour" in the "Entity Scripts" field.


Any entity capable of firing [[Inputs and Outputs|outputs]], such as [[logic_timer]], [[trigger_once]], [[func_button]], [[logic_case]], ect. can have the following output to change the behaviour of the next spawned witches until changed:<br>
Any entity capable of firing [[Inputs and Outputs|outputs]], such as [[logic_timer]], [[trigger_once]], [[func_button]], [[logic_case]], ect. can have the following output to change the behaviour of the next spawned witches until changed:<br>
'''Sitting Witch'''
<h4>Sitting Witch</h4>
{| {{OutputsTable}}
{| {{OutputsTable}}
| [[Image:Io11.png]] || ''Depends on entity'' || <logic_script entity name> || RunScriptCode|| WitchSit() || 0.00 || No
| [[Image:Io11.png]] || ''Depends on entity'' || <logic_script entity name> || RunScriptCode|| NewWitches_Sit() || 0.00 || No
|}
|}
'''Wandering Witch'''
<h4>Wandering Witch</h4>
{| {{OutputsTable}}
{| {{OutputsTable}}
| [[Image:Io11.png]] || ''Depends on entity'' || <logic_script entity name> || RunScriptCode|| WitchWalk() || 0.00 || No
| [[Image:Io11.png]] || ''Depends on entity'' || <logic_script entity name> || RunScriptCode|| NewWitches_Walk() || 0.00 || No
|}
|}
{{note|This will not make a wandering witch sit down or vice versa.}}
{{note|This will not make a wandering witch sit down or vice versa.}}

Revision as of 03:08, 25 March 2021

Template:Otherlang2

In L4D2, we discover that witches sit and rock themselves only at night. If there's sunlight, they wander. You can control this in your map from the Map > Map Properties... menu item.

If you change Time of day to any time of day when the sun is out, including "Dawn", "Morning", and "Afternoon", witches spawned by the Director will wander.

float

Changing Behaviour at runtime

If you would like to have both standing and sitting witches, or randomly pick which to use, you can do so by using a vscript.

Create a text file called Witch_behaviour.nut (or any sensical name) and put it into the scripts/vscripts folder.
The script should contain the following:

const TIME_NIGHT = 0
const TIME_DAY = 3

// Note, these only modify witches if they haven't spawned before this function did anything!
function NewWitches_Sit()
{
	local worldspawn = Ent("worldspawn")
	if( worldspawn.__KeyValueFromInteger( "timeofday", TIME_NIGHT ) );
	{
		if( developer() )
			printl( "Set worldspawn 'timeofday' key to "+tostring(TIME_NIGHT)+", (NIGHTTIME)" )
	}
}
function NewWitches_Walk()
{
	local worldspawn = Ent("worldspawn")
	if( worldspawn.__KeyValueFromInteger( "timeofday", TIME_DAY ) );
	{
		if( developer() )
			printl( "Set worldspawn 'timeofday' key to "+tostring(TIME_DAY)+", (DAYTIME)" )
	}
}

Next, place a logic_script entity into your map, using "Witch_behaviour" in the "Entity Scripts" field.

Any entity capable of firing outputs, such as logic_timer, trigger_once, func_button, logic_case, ect. can have the following output to change the behaviour of the next spawned witches until changed:

Sitting Witch

  My Output Target Entity Target Input Parameter Delay Only Once
Io11.png Depends on entity <logic_script entity name> RunScriptCode NewWitches_Sit() 0.00 No

Wandering Witch

  My Output Target Entity Target Input Parameter Delay Only Once
Io11.png Depends on entity <logic_script entity name> RunScriptCode NewWitches_Walk() 0.00 No
Note.pngNote:This will not make a wandering witch sit down or vice versa.

You could also make an intricate setup of a logic_case randomly picking between witch behaviours and spawns them one after another, to get a map such as the Sugarmill, but with both sitting and wandering witches.