Defining the NPC
Jump to navigation
Jump to search
To start your NPC, you must create a definition for it first.
- Copy npc_New.cpp to a new file related to the classname.
Example:src\dlls\hl2_dll\npc_Barney.cpp
- Make appropriate changes to the
Precache
,Spawn
, andClassify
functions.Precache
should include calls toUTIL_PrecacheOther
for all entities this NPC creates as well asPrecacheScriptSound
for all script sounds this NPC emits. Follow the subprocedure below if you want a custom class for the NPC.- Add the new class to the first enum
Class_T
insrc\dlls\BaseEntity.h
beforeNUM_AI_CLASSES
.Example class:Note:This modification will require a rebuild of the server solution because
BaseEntity.h
is included incbase.h
CLASS_COMBINE
- Navigate to your gamerules file (src\game_shared\hl2_gamerules.cpp) and go to InitDefaultAIRelationships.
- Copy one of the blocks of SetDefaultRelationship with a uniform first parameter (i.e. the first block:
CLASS_ANTLION
) and paste it at the end of the function. - Replace the first parameter of the pasted code with your new class from
Class_T
. - Change the disposition (i.e. D_NU) to the desired one from enum
Disposition_t
insrc\dlls\BaseCombatCharacter.h
. - Change the priority (i.e. 0) of the relationship to the desired one.
Note:A higher priority means this NPC will pay the most attention to the target class.
- Go through every block of SetDefaultRelationship and add the new class to it as the second parameter.
- Add the new class to the first enum
- Note the AI_BEGIN_CUSTOM_NPC section. This will be an important section for later steps.
Return to Creating an NPC | Giving an NPC Memory → |