Response System

From Valve Developer Community
Revision as of 04:59, 1 August 2005 by N-neko (talk | contribs)
Jump to navigation Jump to search

Stub

This article or section is a stub. You can help by expanding it.

Introduction

In HL2, AIs speaks/actions based on "Concepts." /scripts/talker/response_rules.txt is the base script file for this Response System. It contains criterion/rule/response definitions.

The Response system checks each rule against the set, give it a numeric score based on the rule's set of criteria. Then the system picks one rule with the highest score, dispatch a response that the rule points.

Concept

Concept is high level state that the code is trying to convey, such as say hello, or say you're mad, etc.

  • code
  • entity input

Enumeration

Enumeration declares an enumerated type so that comparisons can be matched against the string versions of the type.

 enumeration <enumerationname>
 { 
		"key1" "value1"
		"key2" "value2"
		...etc.
	}

The code and criteria refer to enumerations with square brackets and a double colon separator, e.g.: [enumerationname::key1]


Criterion

Criterion is a match condition. If it doesn't match, score = 0. If it does match, the score is weight value * rule.

criterion <criterionname> <matchkey> <matchvalue> weight nnn required
  • matchkey
    • concept
    • map
    • classname
    • name
    • health
    • healthfrac

Context

Map placed entities have up to three "context" keypairs that can be specified. They take the form:

"key:value" (key, single colon separator, value)

When an entity with any such context keypairs is asked to dispatch a response, the keypairs are added to the criteria set passed to the rule system. Thus, map placed entities and triggers can specify their

own context keypairs and these can be hooked up to response rules to do map-specific and appropriate responses
  • World
  • NPC
    • Property
      • ResponseContext(string) : "Response Contexts" : "" : "Response system context(s) for this entity. Format should be: 'key:value,key2:value2,etc'. When this entity speaks, the list of keys & values will be passed to the response rules system."
    • Input
      • AddContext(string) : "Adds a context to this entity's list of response contexts. The format should be 'key:value'."
      • RemoveContext(string) : "Remove a context from this entity's list of response contexts. The name should match the 'key' of a previously added context."
      • ClearContext(void) : "Removes all contexts in this entity's list of response contexts."
  • env_speaker
  • ai_speechfilter

Rule

Rule consists of one or more criteria and a response. The final score for a rule is the sum of all of the scores of its criteria.

rule <rulename>
{
   criteria name1 [name2 name3 etc.]
   response responsegroupname [responsegroupname2 etc.]
   [matchonce]					; optional parameter
   [ <matchkey > <matchvalue> weight nnn required ]
}

Reponse

Response specifies a response to issue. A response consists of a weighted set of options and can recursively reference.

Single line:

response <responsegroupname> [nodelay | defaultdelay | delay interval ] [speakonce] [noscene] [odds nnn] [respeakdelay interval] [soundelvel "SNDLVL_xxx"] responsetype parameters

Multipul lines:

response <responsegroupname>
{
	[permitrepeats]   ; optional parameter, by default we visit all responses in group before repeating any
	[sequential]	  ; optional parameter, by default we randomly choose responses, but with this we walk through the list starting at the first and going to the last
	[norepeat]		  ; Once we've run through all of the entries, disable the response group
	responsetype1 parameters1 [nodelay | defaultdelay | delay interval ] [speakonce] [odds nnn] [respeakdelay interval] [soundelvel "SNDLVL_xxx"] [displayfirst] [ displaylast ] weight nnn
	responsetype2 parameters2 [nodelay | defaultdelay | delay interval ] [speakonce] [odds nnn] [respeakdelay interval] [soundelvel "SNDLVL_xxx"] [displayfirst] [ displaylast ] weight nnn
	etc.
}
  • responsetype
    • speak ; it's an entry in sounds.txt
    • sentence ; it's a sentence name from sentences.txt
    • scene ; it's a .vcd file
    • response ; it's a reference to another response group by name
    • print  ; print the text in developer 2 (for placeholder responses)

Add your new NPC to the Response System

  • Make your NPC derived from NPC_Talker
  • Write a new rule script for your NPC
    • See npc_xxx.txt for examples
  • Include the new script in /scripts/talker/response_rules.txt