Defining the NPC: Difference between revisions
Jump to navigation
Jump to search
m (note) |
No edit summary |
||
Line 2: | Line 2: | ||
To start your NPC, you must create a definition for it first. | To start your NPC, you must create a definition for it first. | ||
Copy [[npc_New.cpp]] to a new file related to the classname. | #Copy [[npc_New.cpp]] to a new file related to the classname.<br>Example: <code>src\dlls\hl2_dll\npc_Barney.cpp</code> | ||
#Make appropriate changes to the <code>Precache</code>, <code>Spawn</code>, and <code>Classify</code> functions. Follow the subprocedure below if you want a custom class for the NPC. | |||
Example: <code>src\dlls\hl2_dll\npc_Barney.cpp</code> | ## Add the new class to the first enum <code>Class_T</code> in <code>src\dlls\BaseEntity.h</code> before <code>NUM_AI_CLASSES</code>.{{note|This modification will require a rebuild of the server solution because <code>BaseEntity.h</code> is included in <code>cbase.h</code>}}Example class: <code>CLASS_COMBINE</code> | ||
##Navigate to your gamerules file (hl2_gamerules.cpp) and go to [[InitDefaultAIRelationships]]. | |||
Note the '''AI_BEGIN_CUSTOM_NPC''' section. This will be an important section for later steps. | ##Copy one of the blocks of [[SetDefaultRelationship]] with a uniform first parameter (i.e. the first block: <code>CLASS_ANTLION</code>) and paste it at the end of the function. | ||
##Replace the first parameter of the pasted code with your new class from <code>Class_T</code>. | |||
##Change the disposition (i.e. D_NU) to the desired one from enum <code>Disposition_t</code> in <code>src\dlls\BaseCombatCharacter.h</code>. | |||
##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. | |||
#Note the '''AI_BEGIN_CUSTOM_NPC''' section. This will be an important section for later steps. | |||
[[Category:AI Programming]] | [[Category:AI Programming]] |
Revision as of 12:45, 8 June 2006
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. 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 (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.