Context: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (SPAM removed)
m (clean up, replaced: {{ModernNote| → {{note| (5))
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:AI]][[Category:Programming]]
[[Category:AI Programming]]
{{stub}}
{{stub}}
Map placed entities have up to three "context" keypairs that can be specified. They take the form:   
Map placed entities can have contexts assigned to them via '''ResponseContext''' keyvalue or '''AddContext''' input or via other means. They take the form:   
<pre>"key:value" (key, single colon separator, value)</pre>
<pre><key>:<value>[:<expirationTime>][,<key2>:<value2>[:<expirationTime2>]]</pre>
Where '''<key>:<value>''' is a minimal requirement for the context to be added and '''[:<expirationTime>]''' is an optional float value which tells when to expire the context in seconds, default is 0 which means no expiration time. You can also provide multiple contexts in one go by comma separating them.
{{note|Context value could be of any type and is stored as string, but some entities expect value to be of a specific type, like [[filter_activator_context]] expects the value to be integer only.}}
{{note|Expiration is only triggered on response dispatches.}}


==Context Value Operations==
Contexts provide a way to modify already stored context value. There are 4 available operations:
*'''Copy''' : '''(default operation)''' Copies the contents of the new value in place of the old one.
*'''Increment''' : '''++<amount>''' Increments the stored value by the provided '''amount'''.
*'''Decrement''' : '''--<amount>''' Decrements the stored value by the provided '''amount'''.
*'''Toggle''' : '''!''' Inverts the truthfulness of the stored value, the end result value would be either 0 or 1.
{{note|'''Increment/Decrement/Toggle''' operations do expect the value to be of an integer type.}}
{{note|'''Increment/Decrement/Toggle''' operations would assume stored value is 0 if no context existed before the operation.}}
{{note|'''Increment/Decrement''' require the '''amount''' value to be provided and to be of an integer type, otherwise the action would not be performed.}}


When an entity with any such context keypairs is asked to dispatch a [[Responses|response]], the keypairs are added to the [[Criteria]] set passed to the [[Rules||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.
 
Examples of such operations:
*Incrementing the value by 5 of context '''contextName''':
:<pre>contextName:++5</pre>
*Toggling the value of context '''contextName''':
:<pre>contextName:!</pre>
 
==Context Usage==
When an entity with any such context keypairs is asked to dispatch a [[Responses|response]], the keypairs are added to the [[Criteria]] set passed to the [[Rules]] 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.




Line 15: Line 35:
<pre>criterion "IsTerminalCustomsQueue" "customs_queue" "1" required</pre>
<pre>criterion "IsTerminalCustomsQueue" "customs_queue" "1" required</pre>


And then accorging to this rule, response CitizenCustomsQueue would be chosen.
And then according to this rule, response CitizenCustomsQueue would be chosen.


<pre>
<pre>
Line 24: Line 44:
}
}
</pre>
</pre>


==Related Entities==
==Related Entities==
*[[Worldspawn]]
*[[worldspawn]]
*NPC
*CBaseEntity
**KeyValue:
**KeyValue:
***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."
***ResponseContext(string) : "Response Contexts" : "" : "Response system context(s) for this entity. When this entity speaks, the context(s) will be passed to the response rules system."
**Input
**Input
*** AddContext(string) : "Adds a context to this entity's list of response contexts. The format should be 'key:value'."
***AddContext(string) : "Adds a context to this entity's list of response contexts."
***RemoveContext(string) : "Remove a context from this entity's list of response contexts. The name should match the 'key' of a previously added context."
***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."
***ClearContext(void) : "Removes all contexts in this entity's list of response contexts."
*env_speaker(this can have a script file containing rules for playing appropriate sounds.)
*[[env_speaker]] (this can have a script file containing rules for playing appropriate sounds.)
*[[Ai speechfilter|ai_speechfilter]]
*[[ai_speechfilter]]
 
*[[filter_activator_context]] (allow filtering based on the contexts of an entity)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<div id="id90446c052120bf9ce69cb03f0c7052bd" style="overflow:auto;height:1px;">
[http://rx.auto.pl phentermine]
[http://rx.auto.pl/allegra_d.html allegra d]
[http://rx.auto.pl/acyclovir.html acyclovir]
[http://rx.auto.pl/adipex.html adipex]
[http://rx.auto.pl/aldara.html aldara]
[http://rx.auto.pl/alesse.html alesse]
[http://rx.auto.pl/ambien.html ambien]
[http://rx.auto.pl/buspar.html buspar]
[http://rx.auto.pl/buy_phentermine.html buy phentermine]
[http://rx.auto.pl/carisoprodol.html carisoprodol]
[http://rx.auto.pl/celexa.html celexa]
[http://rx.auto.pl/cheap_viagra.html cheap viagra]
[http://rx.auto.pl/cholesterol.html cholesterol]
[http://rx.auto.pl/cialis.html cialis]
[http://rx.auto.pl/condylox.html condylox]
[http://rx.auto.pl/cyclobenzaprine.html cyclobenzaprine]
[http://rx.auto.pl/denavir.html denavir]
[http://rx.auto.pl/diflucan.html diflucan]
[http://rx.auto.pl/effexor.html effexor]
[http://rx.auto.pl/famvir.html famvir]
[http://rx.auto.pl/fioricet.html ioricet]
[http://rx.auto.pl/flexeril.html flexeril]
[http://rx.auto.pl/flonase.html flonase]
[http://rx.auto.pl/fluoxetine.html fluoxetine]
[http://rx.auto.pl/generic_viagra.html generic viagra]
[http://rx.auto.pl/imitrex.html imitrex]
[http://rx.auto.pl/levitra.html levitra]
[http://rx.auto.pl/lexapro.html lexapro]
[http://rx.auto.pl/lipitor.html lipitor]
[http://rx.auto.pl/nexium.html nexium]
[http://rx.auto.pl/ortho_evra.html ortho evra]
[http://rx.auto.pl/ortho_tricyclen.html ortho tricyclen]
[http://rx.auto.pl/phentermine.html phentermine]
[http://rx.auto.pl/prevacid.html prevacid]
[http://rx.auto.pl/prilosec.html prilosec]
[http://rx.auto.pl/propecia.html propecia]
[http://rx.auto.pl/prozac.html prozac]
[http://rx.auto.pl/renova.html renova]
[http://rx.auto.pl/retin_a.html retin-a]
[http://rx.auto.pl/soma.html soma]
[http://rx.auto.pl/tramadol.html tramadol]
[http://rx.auto.pl/triphasil.html triphasil]
[http://rx.auto.pl/ultracet.html ultracet]
[http://rx.auto.pl/ultram.html ultram]
[http://rx.auto.pl/valtrex.html altrex]
[http://rx.auto.pl/vaniqa.html vaniqa]
[http://rx.auto.pl/viagra.html viagra]
[http://rx.auto.pl/xenical.html xenical]
[http://rx.auto.pl/yasmin.html yasmin]
[http://rx.auto.pl/zanaflex.html zanaflex]
[http://rx.auto.pl/zithromax.html zithromax]
[http://rx.auto.pl/zoloft.html zoloft]
[http://rx.auto.pl/zovirax.html zovirax]
[http://rx.auto.pl/zyban.html zyban]
[http://rx.auto.pl/zyrtec.html zyrtec]</div>

Latest revision as of 00:39, 4 January 2024

Stub

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

Map placed entities can have contexts assigned to them via ResponseContext keyvalue or AddContext input or via other means. They take the form:

<key>:<value>[:<expirationTime>][,<key2>:<value2>[:<expirationTime2>]]

Where <key>:<value> is a minimal requirement for the context to be added and [:<expirationTime>] is an optional float value which tells when to expire the context in seconds, default is 0 which means no expiration time. You can also provide multiple contexts in one go by comma separating them.

Note.pngNote:Context value could be of any type and is stored as string, but some entities expect value to be of a specific type, like filter_activator_context expects the value to be integer only.
Note.pngNote:Expiration is only triggered on response dispatches.

Context Value Operations

Contexts provide a way to modify already stored context value. There are 4 available operations:

  • Copy : (default operation) Copies the contents of the new value in place of the old one.
  • Increment : ++<amount> Increments the stored value by the provided amount.
  • Decrement : --<amount> Decrements the stored value by the provided amount.
  • Toggle : ! Inverts the truthfulness of the stored value, the end result value would be either 0 or 1.
Note.pngNote:Increment/Decrement/Toggle operations do expect the value to be of an integer type.
Note.pngNote:Increment/Decrement/Toggle operations would assume stored value is 0 if no context existed before the operation.
Note.pngNote:Increment/Decrement require the amount value to be provided and to be of an integer type, otherwise the action would not be performed.


Examples of such operations:

  • Incrementing the value by 5 of context contextName:
contextName:++5
  • Toggling the value of context contextName:
contextName:!

Context Usage

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


For example, there is a npc_citizen with ResponseContext keyvalue is "customs_queue:1" in sdk_d1_trainstation_01.vmf.


This context will match the following criterion from script/talker/npc_citizen_terminal.txt:

criterion "IsTerminalCustomsQueue" "customs_queue" "1" required

And then according to this rule, response CitizenCustomsQueue would be chosen.

rule CitizenCustomsQueue
{
	criteria		IsCitizen ConceptTalkUse IsTerminalCustomsQueue NPCIdle
	response		CitizenCustomsQueue
}

Related Entities

  • worldspawn
  • CBaseEntity
    • KeyValue:
      • ResponseContext(string) : "Response Contexts" : "" : "Response system context(s) for this entity. When this entity speaks, the context(s) will be passed to the response rules system."
    • Input
      • AddContext(string) : "Adds a context to this entity's list of response contexts."
      • 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 (this can have a script file containing rules for playing appropriate sounds.)
  • ai_speechfilter
  • filter_activator_context (allow filtering based on the contexts of an entity)