Defining the NPC: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(12 intermediate revisions by 10 users not shown)
Line 1: Line 1:
[http://sukinsa.hostinggratisvenezuela.com/resources/fetishes.html fetishes] [http://virgietyus.profil.bz/premiership-football.htm premiership football result] [http://laruereagan.profil.bz/brothers-gay-sex.html brothers gay sex] [http://bugubudji.myxhost.com/text/free-black.html free black ghetto sex movies] [http://heyheyyouyou.w8w.pl/new/pay-what/ pay what you can] [http://leannenowak.profil.bz/celebrity-hardcore.html celebrity hardcore] [http://www12.asphost4free.com/denisem/new/megan-good/ megan good nude] [http://tabethacaudill.profil.bz/small/teen-fingering.html teen fingering herself] [http://tabethacaudill.profil.bz/small/brooke-berry.html brooke berry] [http://bugubudji.myxhost.com/text/lesbian-sister.html lesbian sister] [http://sukinsa.hostinggratisvenezuela.com/resources/flash-intros.html flash intros] [http://reobhecc.hostinggratisusa.com/resources/orange-extract/ orange extract recipe] [http://squealingpiglet.w8w.pl/content/effects-of/ effects of stress on the nervous system] [http://squealingpiglet.w8w.pl/content/unix-web/ unix web hosting] [http://reobhecc.hostinggratisusa.com/resources/online-pharmacy/ online pharmacy canada] [http://squealingpiglet.w8w.pl/content/tennis-girl/ tennis girl] [http://heyheyyouyou.w8w.pl/new/mistress-domina/ mistress domina strap on] [http://janisdunham.profil.bz/blog/opera-bastille.html opera bastille paris france] [http://squealingpiglet.w8w.pl/content/caveman/ caveman] [http://squealingpiglet.w8w.pl/content/kaspersky-antivirus/ kaspersky antivirus] [http://bugubudji.myxhost.com/text/forsake-the.html forsake the troops] [http://eldritchrainbow.678host.com/web/amazing-pictures/ amazing pictures] [http://shulend.hostinggratisvenezuela.com/articles/midway-limousine/ midway limousine service] [http://sweetestdrop.678host.com/content/boat-loans.html boat loans] [http://reobhecc.hostinggratisusa.com/resources/totally-free/ totally free stuff] [http://shulend.hostinggratisvenezuela.com/articles/tree-climber/ tree climber] [http://recycledphrase3.orgfree.com/resources/penthouse-videos/ penthouse videos] [http://reobhecc.hostinggratisusa.com/resources/big-chested/ big chested girls] [http://recycledphrase3.orgfree.com/resources/slutty-teachers/ slutty teachers] [http://www12.asphost4free.com/denisem/new/ninel-conde/ ninel conde] [http://squealingpiglet.w8w.pl/content/black-and/ black and white] [http://beamcneese.profil.bz/bigbooty.html bigbooty] [http://heyheyyouyou.w8w.pl/new/international-journal/ international journal of sociology of language] [http://sukinsa.hostinggratisvenezuela.com/resources/chopard-watch.html chopard watch] [http://leannenowak.profil.bz/teen-snatch.html teen snatch] [http://mariettebickers.profil.bz/apartments-in.html apartments in california for rent] [http://squealingpiglet.w8w.pl/content/video-stock/ video stock footage] [http://squealingpiglet.w8w.pl/content/older-woman/ older woman personal] [http://squealingpiglet.w8w.pl/content/apartment-rentals/ apartment rentals] [http://squealingpiglet.w8w.pl/content/woman-naked/ woman naked] [http://virgietyus.profil.bz/stonybrook-university.htm stonybrook university long island ny] [http://heyheyyouyou.w8w.pl/new/granny-sex/ granny sex] [http://virgietyus.profil.bz/extreme-bizarre.htm extreme bizarre 04] [http://heyheyyouyou.w8w.pl/new/robbie-williams/ robbie williams mp3] [http://virgietyus.profil.bz/wetivette.htm wetivette] [http://recycledphrase3.orgfree.com/resources/moscow-police/ moscow police station] [http://www12.asphost4free.com/denisem/new/rehab/ rehab] [http://virgietyus.profil.bz/little-girl.htm little girl nude] [http://sweetestdrop.678host.com/content/is-in.html is in search of] [http://recycledphrase3.orgfree.com/resources/hardcore-mature/ hardcore mature] [http://mimiwise.profil.bz/description/old-phone-ringing.htm old phone ringing] [http://bugubudji.myxhost.com/text/atlantic-electric.html atlantic electric and gas website] [http://squealingpiglet.w8w.pl/content/layered-hair/ layered hair cuts] [http://squealingpiglet.w8w.pl/content/kstp/ kstp] [http://shulend.hostinggratisvenezuela.com/articles/nights-into/ nights into dreams music downloads] [http://dinatregre.profil.bz/eds.html eds] [http://heyheyyouyou.w8w.pl/new/emily-deans/ emily deans] [http://recycledphrase3.orgfree.com/resources/geckos/ geckos] [http://sukinsa.hostinggratisvenezuela.com/resources/famke-janssen.html famke janssen sexy] [http://www12.asphost4free.com/crumplstiltskin/lib/espn-sports.html espn sports guy] [http://squealingpiglet.w8w.pl/content/internet-auctions/ internet auctions] [http://janisdunham.profil.bz/blog/abs-workout.html abs workout] [http://mariettebickers.profil.bz/car-models.html car models] [http://squealingpiglet.w8w.pl/content/six-of/ six of one] [http://recycledphrase3.orgfree.com/resources/interracial-creampie/ interracial creampie] [http://eldritchrainbow.678host.com/web/suck-tit/ suck tit milk] [http://skquek.2day.biz/description/pasadena-home.html pasadena home and garden show] [http://beamcneese.profil.bz/moving-boxes.html moving boxes] [http://squealingpiglet.w8w.pl/content/ginger-pubes/ ginger pubes] [http://mariettebickers.profil.bz/teen-cuties-in.html teen cuties in tight thongs] [http://mimiwise.profil.bz/description/cuckold-sissy.htm cuckold sissy] [http://mimiwise.profil.bz/description/human-brain.htm human brain] [http://laruereagan.profil.bz/labeling-machinery.html labeling machinery] [http://shulend.hostinggratisvenezuela.com/articles/texas-federal/ texas federal courts] [http://bugubudji.myxhost.com/text/google-stock.html google stock] [http://eldritchrainbow.678host.com/web/sex-advice/ sex advice] [http://recycledphrase3.orgfree.com/resources/young-lesbian/ young lesbian girls] [http://squealingpiglet.w8w.pl/content/stripping-women/ stripping women naked] [http://lipkaya-loj.678host.com/how-to.html how to have better sex] [http://eldritchrainbow.678host.com/web/preteenz/ preteenz] [http://sukinsa.hostinggratisvenezuela.com/resources/image-search.html image search] [http://leannenowak.profil.bz/pain-med.html pain med] [http://tabethacaudill.profil.bz/small/wham.html wham] [http://www12.asphost4free.com/denisem/new/hooligans-mp/ hooligans mp3] [http://dinatregre.profil.bz/patron-saints.html patron saints] [http://skquek.2day.biz/description/spiderman.html spiderman 3] [http://squealingpiglet.w8w.pl/content/top-converting/ top converting downloader] [http://beamcneese.profil.bz/new-balance-walking.html new balance walking shoes] [http://beamcneese.profil.bz/gay-mature.html gay mature] [http://mimiwise.profil.bz/description/new-york-weight.htm new york weight loss spa] [http://virgietyus.profil.bz/fingering-lesbians.htm fingering lesbians] [http://squealingpiglet.w8w.pl/content/lauren-graham/ lauren graham] [http://www12.asphost4free.com/denisem/new/eva-nude/ eva nude] [http://www12.asphost4free.com/catlongtail/resources/beach-babe/ beach babe] [http://mimiwise.profil.bz/description/big-rack.htm big rack] [http://reobhecc.hostinggratisusa.com/resources/public-nip/ public nip slips] [http://squealingpiglet.w8w.pl/content/free-tarot/ free tarot reading] [http://www12.asphost4free.com/denisem/new/jet-blue/ jet blue airway] [http://squealingpiglet.w8w.pl/content/girl-boy/ girl boy] [http://janisdunham.profil.bz/blog/drives.html drives]
{{lang|Defining_the_NPC}}
{{npc tut}}
{{npc tut}}
To start your NPC, you must create a definition for it first.
This page covers '''creating a simple NPC''' using the SDK's template.


#Copy [[npc_New.cpp]] to a new file related to the classname.<br>Example: <code>src\dlls\hl2_dll\npc_Barney.cpp</code>
== Setting up ==
#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>
##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: <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.


{{navbar-first|Creating an NPC|Giving an NPC Memory}}
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

English (en)中文 (zh)Translate (Translate)

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 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.

← [[::Category:AI Programming|:Category:AI Programming]]