Defining the NPC
This page covers creating a simple NPC using the SDK's template.
All versions of the SDK (including Alien Swarm) provide a NPC template file at
server/hl2/monster_dummy.cpp. You can copy this file to a new location and start working on it.
Change the model path in
Spawn() to a valid model file (choose something humanoid for now) and you will be able to spawn a NPC which turns to face sounds it hears nearby.
An NPC's relationships define how it reacts to other NPCs. Use each NPC's
FindEntityRelationship(CBaseEntity *pTarget) function to test relationship state.
There are four built-in "dispositions":
Each relationship has a priority. The relationship with the highest priority wins if there is a conflict.
A relationship can target one of three things:
An NPC can belong to a faction, and that faction can have dispositions toward other factions. Factions are defined in
game/shared/shareddefs.h (by default there are none).
- Adds a faction relationship for this NPC only.
- Adds a static faction relationship which is shared by all NPCs.
- Sets the faction to which the NPC belongs.
An NPC can classify itself. This particular class is the return value of the
Classify() function, and is not related to C++ or Hammer classes.
- Adds a class relationship for this NPC only.
- Adds a static class relationship which is shared by all NPCs.
- Returns this NPC's class.
Lastly, one-off relationships can be specified between any two NPCs.
- Adds a relationship between this NPC and another.