Response System

From Valve Developer Community
Revision as of 04:46, 1 August 2005 by N-neko (talk | contribs) (rough stub based on response_rules.txt)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 <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 <criterionname> <matchkey> <matchvalue> weight nnn required

  • matchkey
    • concept
    • map
    • classname
    • name
    • health
    • healthfrac

Context

  • 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 <rulename>
{
   criteria name1 [name2 name3 etc.]
   response responsegroupname [responsegroupname2 etc.]
   [matchonce]					; optional parameter
   [ <matchkey > <matchvalue> weight nnn required ]
}

Reponse

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