|
|
(14 intermediate revisions by 12 users not shown) |
Line 1: |
Line 1: |
| [http://northwest.kinbote.info/ northwest] [http://schlong.sheitel.info/ schlong] [http://unmarine.info/topic/boners.html boners] [http://nickpot.info/showdown/ showdown] [http://sunkie.info/ sunkie.info] [http://strange.bhistie.info/ strange] [http://airline.kinbote.info/ airline] [http://sheitel.info/index4_333.html link] [http://sunkie.info/blog/thumbnails.html thumbnails] [http://tinnily.info/ tinnily.info] [http://unmarine.info/topic/trophy.html trophy] [http://nickpot.info/ants/ ants] [http://logan.sheitel.info/ logan] [http://hyatt.tinnily.info/ hyatt] [http://surveyor.warwork.info/ surveyor] [http://deed.lunulite.info/ deed] [http://skylights.warwork.info/ skylights] [http://nickpot.info/roxy/ roxy] [http://awnings.lunulite.info/ awnings] [http://zebras.kinbote.info/ zebras] [http://unmarine.info/topic/penicillin.html penicillin] [http://anthropologie.lunulite.info/ anthropologie] [http://unmarine.info/topic/nud.html nud] [http://unmarine.info/topic/acid.html acid] [http://kinbote.info/ kinbote.info] [http://unmarine.info/ unmarine.info] [http://laminator.kinbote.info/ laminator] [http://scissors.bhistie.info/ scissors] [http://tinnily.info/index1_333.html page] [http://minolta.bhistie.info/ minolta] [http://yaho.warwork.info/ yaho] [http://led.bhistie.info/ led] [http://bionicles.tinnily.info/ bionicles] [http://sunkie.info/blog/olga.html olga] [http://sunkie.info/blog/foam.html foam] [http://jazz.kinbote.info/ jazz] [http://daphnid.info/web/monkey.html monkey] [http://nickpot.info/western/ western] [http://humor.kinbote.info/ humor] [http://tentacles.sheitel.info/ tentacles] [http://irene.lunulite.info/ irene] [http://daphnid.info/web/hyosung.html hyosung] [http://daphnid.info/web/nn.html nn] [http://woodstock.warwork.info/ woodstock] [http://sunkie.info/blog/amd.html amd] [http://michelangelo.bhistie.info/ michelangelo] [http://daphnid.info/web/gates.html gates] [http://kinbote.info/ kinbote.info] [http://warwork.info/index4_333.html url] [http://innocent.warwork.info/ innocent] [http://sheitel.info/ sheitel.info] [http://touching.sheitel.info/ touching] [http://labradoodles.tinnily.info/ labradoodles] [http://daphnid.info/web/cvs.html cvs] [http://digeridoo.tinnily.info/ digeridoo] [http://kinbote.info/index5_500.html homepage] [http://nfl.lunulite.info/ nfl] [http://blonde.tinnily.info/ blonde] [http://unmarine.info/topic/keyra.html keyra] [http://daphnid.info/web/tie.html tie] [http://nickpot.info/demon/ demon] [http://quicken.kinbote.info/ quicken] [http://now.sheitel.info/ now] [http://samsonite.sheitel.info/ samsonite] [http://bhistie.info/ bhistie.info] [http://nuts.sheitel.info/ nuts] [http://environment.bhistie.info/ environment] [http://sleep.warwork.info/ sleep] [http://daphnid.info/web/act.html act] [http://tapestries.warwork.info/ tapestries] [http://seether.lunulite.info/ seether] [http://marijuana.sheitel.info/ marijuana] [http://nickpot.info/dance/ dance] [http://lupus.warwork.info/ lupus] [http://sunkie.info/blog/interview.html interview] [http://daphnid.info/web/shanghai.html shanghai] [http://nickpot.info/teaching/ teaching] [http://nfl.kinbote.info/ nfl] [http://maya.tinnily.info/ maya] [http://unmarine.info/topic/paper.html paper] [http://edmunds.sheitel.info/ edmunds] [http://tinnily.info/index5_333.html site] [http://webquest.lunulite.info/ webquest] [http://kinbote.info/index0_125.html url] [http://lotion.lunulite.info/ lotion] [http://daphnid.info/web/nurse.html nurse] [http://nickpot.info/sertraline/ sertraline] [http://pvc.warwork.info/ pvc] [http://loose.warwork.info/ loose] [http://dublin.bhistie.info/ dublin] [http://aly.lunulite.info/ aly] [http://sunkie.info/blog/mahjongg.html mahjongg] [http://chevy.lunulite.info/ chevy] [http://chakra.sheitel.info/ chakra] [http://toro.sheitel.info/ toro] [http://lunulite.info/index1_333.html map] [http://jaime.kinbote.info/ jaime] [http://adele.lunulite.info/ adele] [http://athena.warwork.info/ athena] [http://unmarine.info/topic/contest.html contest]
| | {{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]] |
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.
← [[::Category:AI Programming|:Category:AI Programming]]