Defining the NPC: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
(caelpasolovi)
Line 1: Line 1:
tabomonbo
{{npc tut}}
{{npc tut}}
To start your NPC, you must create a definition for it first.
To start your NPC, you must create a definition for it first.

Revision as of 10:24, 16 December 2008

tabomonbo

To start your NPC, you must create a definition for it first.

  1. 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
  2. Make appropriate changes to the Precache, Spawn, and Classify functions. Precache should include calls to UTIL_PrecacheOther for all entities this NPC creates as well as PrecacheScriptSound for all script sounds this NPC emits. Follow the subprocedure below if you want a custom class for the NPC.
    1. Add the new class to the first enum Class_T in src\dlls\BaseEntity.h before NUM_AI_CLASSES.
      Note.pngNote:This modification will require a rebuild of the server solution because BaseEntity.h is included in cbase.h
      Example class: CLASS_COMBINE
    2. Navigate to your gamerules file (src\game_shared\hl2_gamerules.cpp) and go to InitDefaultAIRelationships.
    3. 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.
    4. Replace the first parameter of the pasted code with your new class from Class_T.
    5. Change the disposition (i.e. D_NU) to the desired one from enum Disposition_t in src\dlls\BaseCombatCharacter.h.
    6. Change the priority (i.e. 0) of the relationship to the desired one.
      Note.pngNote:A higher priority means this NPC will pay the most attention to the target class.
    7. Go through every block of SetDefaultRelationship and add the new class to it as the second parameter.
  3. 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