Scripted sequences

Scripted sequences provide more advanced control over NPCs than path_corners. They are created with the scripted_sequence entity. You can use these for many different actions such as controlling NPC movement and interactions, and for specifying animations. Unlike aiscripted_schedules, scripted_sequences are location-based entities. NPCs who play a role in the scripted sequence will act out a series of events based on the scripted_sequence entity's location. In this example, we're going to make an npc_citizen named ben walk across a room and sit in a corner. Place an npc_citizen in one corner of a room and a scripted_sequence in the opposite corner. Name the NPC ben and name the scriped_sequence sequence01.

Scripted sequences

The scripted_sequence controls NPC animations and movement. The NPC will face the same direction the scripted sequence is facing, so if we want ben to look towards the inside of the room, rotate the scripted_sequence so the yellow line points inside (alternatively, use the angles property to do this). We want to make ben sit down and then stay there, so we need to control two animations: the animation that transitions from standing to sitting and the actual sitting animation. Inside the scripted_sequence properties, you will see Action Animation and Post Action Idle Animation fields. The Action Animation plays after the NPC arrives at the scripted_sequence location, and the Post Action Idle Animation plays when the sequence is complete. We can tick the loop in post idle flag to make the Post Action Idle Animation play forever. So once ben sits down, he will remain seated forever (playing the sitting animation) until the sequence is cancelled. So our Action Animation will be ben transitioning from standing to sitting, and the Post Action Idle Animation will be ben sitting on the floor. Let's pick the animations.

Choosing your animation

If you don't know which animations are available or simply don't know the animation name, you can look at each animation in the Model Viewer or the Model tab in the Properties panel. The quickest and simplest way to choose an animation is to open the npc_citizen properties and move to the Model tab. In the Sequence property, you can select different animations that the NPC will play in the 3D view.

We want ben to sit down, so select the Sequence drop-down menu and type in sit to filter the animations so they contain the word sit. In the 3D viewport, the NPC will play the sequence animation so you can exactly see what the NPC will do.

Choosing your animation

Our Action Animation will be idle_to_sit_ground and our Post-Action Idle Animation will be sit_ground.

Open the properties of the scripted_sequence to apply the following attributes:

  • Name: ben_sequence01
  • Target NPC: ben
  • Action Animation: idle_to_sit_ground
  • Post Action Idle Animation: sit_ground
  • Move to position: walk

In the Flags tab, check the following:

  • No Interruptions
  • Override AI
  • Loop in Post Idle

Lastly, create a func_button to start the sequence with the following output:

OnPressed > ben_sequence01 > beginsequence > 0.00s Delay

Compile and run the map to watch ben walk across the room, turn to face the center of the room, and then sit in the corner.

Combining sequences

The scripted_sequence entity has special outputs that can fire in certain parts of the sequence. Open the Outputs tab of a scripted_sequence to view all the options available. In this example, we will be linking some scripted_sequences together in two ways: Outputs and the Next Script property. The series of events is as follows: when triggered, Pat (our NPC) will walk to a podium, sit down for 3 seconds, stand up, and walk to a keypad and use it. This sequence will also be repeatable.

Combining sequences

Place two func_buttons, an npc_citizen, and three scripted_sequences in a room. Name the npc_citizen Pat (or whatever name you prefer) and name the three scripted sequences Pat_sequence01, Pat_sequence02, and Pat_sequence03. Place Pat_sequence01 at the top of the podium, and place Pat_sequence02 adjacent to it. Place Pat_sequence03 in front of a func_button on the wall. Since this is a repeatable sequence, set the repeatable flag on each of the scripted_sequence entities.

Tip

In my example, I'm setting the NPCs up to spawn with weapons via the Weapons property because the sitting and standing animations look odd when the npc_citizen does not have anything in their hands.

Name one of the buttons button01 and leave the other without a name.

The button01 button will set all of our events in motion. Set the don't move flag (for aesthetics) and then enter the following output:

OnPressed > Pat_sequence01 > BeginSequence > 0.00s delay
OnPressed > button01 > lock > 0.00s delay

The first output will activate the first sequence. The other two sequences will be activated by other means. The second output locks the button so we don't have to time the delay before reset property. Once the sequences are complete, we will unlock the button so it can be reused.

The scripted_sequence Pat_sequence01 will be similar to ben from the previous example. Enter the following properties to have Pat walk to the pedestal, sit down, and wait:

  • Name: Pat_sequence01
  • Target NPC: Pat
  • Action Animation: idle_to_sit_ground
  • Post-Action Idle Animation: sit_ground
  • Move to Position: walk

Since we want Pat to remain seated once the sequence is complete, check the loop in post-idle flag. If this flag is not checked, Pat will stand up and return to her default idle stance once the sequence is complete; it won't look pretty either. When the loop in post idle flag is checked, the sequence will loop forever until the sequence is canceled. We need to manually cancel the sequence and begin the next sequence after three seconds. Create the following outputs for Pat_sequence01 to accomplish this:

OnEndSequence > Pat_sequence01 > CancelSequence > 3.00s Delay
OnEndSequence > Pat_sequence02 > BeginSequence > 3.00s Delay

The second scripted sequence instructs Pat to stand up. It has the following properties:

  • Name: Pat_sequence02
  • Target NPC: Pat
  • Action Animation: sit_ground_to_idle
  • Move to Position: No - Turn to Face
  • Next Script: Pat_sequence03

Since we don't want Pat to actually move before she stands up, we want to set the Move to Position property to No – Turn to Face. This will ensure that Pat will look in the direction of the scripted_sequence angles. In this case, I have set Angles to 180 because Pat will be facing that direction when she's sitting.

Combining sequences

Using the No – Turn to Face setting can be useful for activating a series of animations for a single NPC without the need for the scripted_sequence to be at the desired NPC position.

The Next Script property specifies which scripted_sequence to play after this one is complete. The next script will be fired immediately. We have the next script set to Pat_sequence03, so as soon as Pat stands up, she will begin with the third sequence.

The third sequence tells Pat to walk to it and then play the door open towards left animation to simulate a button press. The sequence will then fire an output to toggle a light in the player's area and reset button01.

  • Name: Pat_sequence03
  • Target NPC: Pat
  • Action Animation: open_door_towards_left
  • Move to Position: walk

Add the following output to Pat_sequence03:

OnEndSequence > light01 > toggle > 0.00s Delay
OnEndSequence > button01 > unlock > 0.00s Delay

The first output toggles the light. Multiple run-throughs of this sequence of events will turn on and then turn off the light. The second output unlocks the button so it can be used again. Since the firing of this output marks the end of our sequence, we can restart everything.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.144.65