View Single Post
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-07-2013 , 23:39   Re: [TF2] Assister Domination Quotes (1.0, 2013-05-07)
Reply With Quote #2

Technical information on manipulating the TF2 Response System.

This plugin uses TF2's own Response system to work.

Inside tf2_misc_dir.vpk is the directory scripts/talker/ with has a number of .txt files.

These text files control the Valve response system.

To get characters to say their in-game lines, you can look up the response concept you want it to play and figure out what contexts have to be in place before it will work.

This plugin uses the SpeakResponseConcept input instead of DispatchResponse. This is because DispatchResponse does not appear to work correctly in TF2.

Here's an example of how to get a specific response working:

For this, I chose to play the Medic's Melee Dare. The first step is to open up scripts/talker/medic.txt and search for the word Dare. Ignore the first one you find, as it's the Duel version. Eventually, you'll find this:

Code:
Response MeleeDareCombatMedic
{
    scene "scenes/Player/Medic/low/661.vcd"
    scene "scenes/Player/Medic/low/669.vcd"
    scene "scenes/Player/Medic/low/672.vcd"
    scene "scenes/Player/Medic/low/667.vcd"
    scene "scenes/Player/Medic/low/677.vcd"
    scene "scenes/Player/Medic/low/680.vcd"
    scene "scenes/Player/Medic/low/1241.vcd"
    scene "scenes/Player/Medic/low/679.vcd"
}
Rule MeleeDareCombatMedic
{
    criteria ConceptPlayerBattleCry IsWeaponMelee IsMedic IsCrosshairEnemy
    Response MeleeDareCombatMedic
}
The Rule is the important one. See the "criteria" line there? Everything after criteria is a space separate list of contexts defined in response_rules.txt

So, open up scripts/talker/response_rules.txt and look for ConceptPlayerBattleCry
Code:
criterion "ConceptPlayerBattleCry" "Concept" "TLK_PLAYER_BATTLECRY" required
The second argument (Concept) is the rule type. Concepts are special and we'll be sending it to SpeakResponseConcept later. The third ("TLK_PLAYER_BATTLECRY") is its value. The last argument tells us this is required (but pretty much all criteria are).

Now, unfortunately IsMedic isn't really overridable, as the game resets it too quickly for us to override it.

UPDATE: The above may not be true. However, when you define two contexts of the same type, only the first one applies. However, you can remove a context like this:

Code:
SetVariantString("playerclass");
AcceptEntityInput(client, "RemoveContext");
You can remove all existing contexts like this:
Code:
AcceptEntityInput(client, "ClearContext");
END UPDATE
Lets take a look at it anyway. Here's the definitions for this context:
Code:
criterion "IsMedic" "playerclass" "Medic" "required"
This context isn't a Concept, meaning that it could (in theory) be set using AddContext. We'll talk more about AddContext in a moment.

Lets look at the last two contexts: IsWeaponMelee and IsCrosshairEnemy

Code:
criterion "IsWeaponMelee" "weaponmode" "melee" required
criterion "IsCrossHairEnemy" "crosshair_enemy" "Yes" "required"
Remember what I said about AddContext? This is where you want it. It takes a single string argument, which is in format key:value. You can set these contexts by doing this:

Code:
#include <sdktools>

...

SetVariantString("weaponmode:melee");
AcceptEntityInput(client, "AddContext");

SetVariantString("crosshair_enemy:Yes");
AcceptEntityInput(client, "AddContext");
Once you have the contexts set, it's time to call our Concept whose name we saw earlier... and remember to clear the contexts again afterwards.

Code:
SetVariantString("TLK_PLAYER_BATTLECRY");
AcceptEntityInput(client, "SpeakResponseConcept");
    
AcceptEntityInput(client, "ClearContext");
I haven't tested this code, so the melee weapon context may be reset too quickly for us to fake it using this method... YMMV.

Edit: My tf2-data respository contains the talker files, which did not change in the Gun Mettle Update.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 07-22-2015 at 10:47.
Powerlord is offline