Defining the NPC: Difference between revisions
ErnobAsrol (talk | contribs) (caelpasolovi) |
mNo edit summary |
||
(7 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
{{lang|Defining_the_NPC}} | |||
{{npc tut}} | {{npc tut}} | ||
This page covers '''creating a simple NPC''' using the SDK's template. | |||
== Setting up == | |||
{{navbar | All versions of the SDK (including Alien Swarm) provide a NPC template file at <code>server/hl2/monster_dummy.cpp</code>. You can copy this file to a new location and start working on it. | ||
Change the model path in <code>Precache()</code> and <code>Spawn()</code> 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. | |||
== Relationships == | |||
:''This section targets the {{as|4.1}} codebase.'' | |||
An NPC's relationships define how it reacts to other NPCs. Use each NPC's <code>FindEntityRelationship(CBaseEntity *pTarget)</code> function to test the relationship state. | |||
=== Dispositions === | |||
There are four built-in "dispositions": | |||
* <code>D_HATE</code> | |||
* <code>D_FEAR</code> | |||
* <code>D_LIKE</code> | |||
* <code>D_NEUTRAL</code> | |||
Each relationship has a priority. The relationship with the highest priority wins if there is a conflict. | |||
=== Targets === | |||
A relationship can target one of three things: | |||
==== Faction ==== | |||
An NPC can belong to a faction, and that faction can have dispositions toward other factions. Factions are defined in <code>game/shared/shareddefs.h</code> (by default there are none). | |||
; <code>AddFactionRelationship()</code> | |||
: Adds a faction relationship for this NPC only. | |||
; <code>CBaseCombatCharacter::SetDefaultFactionRelationship()</code> | |||
: Adds a static faction relationship which is shared by all NPCs. | |||
; <code>ChangeFaction()</code> | |||
: Sets the faction to which the NPC belongs. | |||
==== Class ==== | |||
An NPC can classify itself. This particular class is the return value of the <code>Classify()</code> function, and is ''not'' related to C++ or Hammer classes. | |||
; <code>AddClassRelationship()</code> | |||
: Adds a class relationship for this NPC only. | |||
; <code>CBaseCombatCharacter::SetDefaultRelationship()</code> | |||
: Adds a static class relationship which is shared by all NPCs. | |||
; <code>Class_T Classify()</code> | |||
: Returns this NPC's class. | |||
Too add a new NPC class,go to basentity.h, line 95 and add you class. | |||
==== Entity ==== | |||
Lastly, one-off relationships can be specified between any two NPCs. | |||
; <code>AddEntityRelationship()</code> | |||
: Adds a relationship between this NPC and another. | |||
{{navbar|:Category:AI Programming|Creating an NPC|Giving an NPC Memory}} | |||
[[Category:AI Programming]] | [[Category:AI Programming]] |
Latest revision as of 11:31, 18 March 2024
This page covers creating a simple NPC using the SDK's template.
Setting up
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 Precache()
and 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.
Relationships
- This section targets the
Alien Swarm codebase.
An NPC's relationships define how it reacts to other NPCs. Use each NPC's FindEntityRelationship(CBaseEntity *pTarget)
function to test the relationship state.
Dispositions
There are four built-in "dispositions":
D_HATE
D_FEAR
D_LIKE
D_NEUTRAL
Each relationship has a priority. The relationship with the highest priority wins if there is a conflict.
Targets
A relationship can target one of three things:
Faction
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).
AddFactionRelationship()
- Adds a faction relationship for this NPC only.
CBaseCombatCharacter::SetDefaultFactionRelationship()
- Adds a static faction relationship which is shared by all NPCs.
ChangeFaction()
- Sets the faction to which the NPC belongs.
Class
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.
AddClassRelationship()
- Adds a class relationship for this NPC only.
CBaseCombatCharacter::SetDefaultRelationship()
- Adds a static class relationship which is shared by all NPCs.
Class_T Classify()
- Returns this NPC's class.
Too add a new NPC class,go to basentity.h, line 95 and add you class.
Entity
Lastly, one-off relationships can be specified between any two NPCs.
AddEntityRelationship()
- Adds a relationship between this NPC and another.