Actually, this tutorial goes beyond just enemies. As you will soon see, the scripting system can be interconnected with any entity you wish. The Half-Life scripts I'm going to explain define what NPCs (non player characters) do, and how they do it.
The entities we will be working with are
- aiscripted_sequence (referred to here as AI_S)
- monster_scientist (or any other NPC)
- trigger_once (or any other trigger-type entity)
- trigger_multiple (or any other trigger-type entity)
I have attempted to draw a diagram of trigger and reaction hierarchy:
OK, that's probably confusing as hell, so let me explain it from left to right. First, you have a trigger. This trigger can come from many places. It can be a trigger_once or trigger_multiple entity which a player walks over, or uses something to activate. It can also come from a trigger condition of a monster. For example, the trigger condition of a zombie can be 50% health. When the zombie's health reaches 50% or below, the specified target is triggered. Therefore, the monster in our flowchart can also be the trigger. When a func_breakable brush is broken, that can also be a trigger. Other entities can also be triggers. Generally, almost any entity with a "target" attribute can be a trigger for that target.
When the condition of a trigger is met, the trigger activates its target: the aiscripted_sequence entity. It's important to understand what an aiscripted_sequence (which I'll now refer to as AI_S) is. AI_S is the shape and size of its assigned NPC because in a way, it IS the NPC. Think of AI_S as a point in space at which your NPC will do what it's assigned. A circle of AI_S entities can be a path for a pondering NPC who paces in circles. an AI_S entity facing a wall can be a point at which your NPC will stop and examine this wall, and then move on. So let's go back to the flowchart. When a trigger condition is met, the AI_S is triggered. The NPC walks (or runs, or faces, you define!) to the AI_S, faces the direction the AI_S is pointing, and performs the action defined by the AI_S. The completion of this action can now trigger another target (AI_S for example) if you so desire. The animations that an AI_S can force a monster to do can be found in your Worldcraft Entity Guide help file under Scripted Sequences. The AI_S has two target fields. One is for the monster that it will affect, and the other is for an object that will be affected (most commonly a
button or a
func_door or a
func_breakable).
Now, we get to our NPC. The NPC does the least work of these three entities. It's pretty much our bitch, or skank if you will: we tell it what to do, but it has no say in it. The only thing important to our little hoe is to have a name. If your NPC
is your trigger, it also needs a trigger condition and a target.