Defining the NPC: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
Ghost12332 (talk | contribs) mNo 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.<br>Example: <code>src\dlls\hl2_dll\npc_Barney.cpp</code> | #Copy [[npc_New.cpp]] to a new file related to the classname. (In Orange Box Engine, The file is now called "monster_dummy")<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. <code>Precache</code> should include calls to <code>UTIL_PrecacheOther</code> for all entities this NPC creates as well as <code>PrecacheScriptSound</code> for all script sounds this NPC emits. Follow the subprocedure below if you want a custom class for the NPC. | #Make appropriate changes to the <code>Precache</code>, <code>Spawn</code>, and <code>Classify</code> functions. <code>Precache</code> should include calls to <code>UTIL_PrecacheOther</code> for all entities this NPC creates as well as <code>PrecacheScriptSound</code> 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 <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> | ## 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> |
Revision as of 07:33, 23 July 2008
To start your NPC, you must create a definition for it first.
- Copy npc_New.cpp to a new file related to the classname. (In Orange Box Engine, The file is now called "monster_dummy")
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 → |