Tf logic training mode: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Replacing {{l4dseries}} or {} with {{this is a}}. This operation was performed by a bot.)
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{this is a|point entity|name=tf_logic_training_mode|game=Team Fortress 2|icon=1}}
{{LanguageBar}}
{{CD|CTrainingModeLogic|file1=tf_gamerules.cpp}}
{{This is a|logical entity|name=tf_logic_training_mode|game=Team Fortress 2}}
Handles outputs and and messages for training, mainly for the [[player]].
Handles outputs and and messages for training, mainly for the [[player]].
{{note|None of the inputs/outputs function in multiplayer except for <code>KickBots</code>.}}
{{tip|This entity, as well as most of its Inputs, can be used on any multiplayer map by spawning this entity after map load and setting the <code>m_bIsInTraining</code> NetProp on [[tf_gamerules]] to true with [[VScript]], however there are multiple caveats:
==Keyvalues==
# Players loadout will be replaced with stock items on resupply/respawn while training mode is enabled
{{KV|Next Map (nextMap)|string|Next map to load when the current one is finished. Default choices are <code>tr_dustbowl</code> and <code>tr_target</code>, although any map is accepted.}}
# The server will be hidden from the server browser, this will persist for the entire duration of the map
{{KV BaseEntity}}
# Achievement tracking is disabled
==Inputs==
# Doesn't print player join or team switch chat messages (they can still be seen when opening chat)
{{IO|ShowTrainingMsg|Show a training message, for training mode. The parameter should be the string entry in tf_english.txt|param=string}}
# Team and class switching menus will be disabled, however <code>join_class</code> and <code>autoteam</code> will still work
{{IO|ShowTrainingObjective|param=string|Sets a training objective to show to the player.}}
# Autobalance is disabled
{{IO|KickBots|Kicks all [[bot]]s from the server.}}
# Domination/Revenge logic is disabled
{{IO|ShowTrainingHUD|Makes the training objective HUD visible.}}
 
{{IO|HideTrainingHUD|Makes the training objective HUD hidden.}}
{{workaround|Many of these issues have workarounds:
{{IO|EndTraining|param=string|Ends training mode. The parameter is for displaying ending text from tf_english.txt}}
{{ExpandBox|
{{IO|PlaySoundOnPlayer|param=string|Play a sound on the player.}}
# Iterate player items and store them in an array/table in player scope first, then re-equip them using [[Team_Fortress_2/Scripting/VScript_Examples#Giving_a_weapon|this method]] after they are stripped.  This will not restore items correctly if the player changes their loadout and resupplies while the annotation is active
{{IO|WaitForTimerOrKeypress|Wait for the specified [[logic_timer]] entity to fire on its interval or for a keypress from the player.|param=string}}
# For custom servers, the <code>hide_server</code> cvar must be added to the vscript cvar allowlist, or <code>sv_allow_point_servercommand</code> must be set to <code>always</code> for <code>SendToServerConsole</code>
{{IO|SetNextMap|param=string|Set the next map for training.}}
# Set <code>m_bAllowTrainingAchievements</code> to true on [[tf_gamerules]]
{{IO|ForcePlayerSpawnAsClassOutput|Force the appropriate output to fire for the player spawning as a class. You can use this to essentially ask what class the player is.}}
# Set <code>m_bIsInTraining</code> to false on player_connect or player_team and set back to true shortly after.  However this will disable any active training HUD elements
{{I BaseEntity}}
{{todo|No known workaround, need to enable/disable the NetProp or use the console commands for class/team switching}}
==Outputs==
{{todo|No known workaround}}
{{IO|OnPlayerSpawnAsScout|Fired when the player spawns as a Scout.}}
{{todo|Potentially send the <code>player_death</code> event manually with domination/revenge death flags, or <code>player_domination</code>, untested.}}
{{IO|OnPlayerSpawnAsSniper|Fired when the player spawns as a Sniper.}}
}}
{{IO|OnPlayerSpawnAsSoldier|Fired when the player spawns as a Soldier.}}
}}
{{IO|OnPlayerSpawnAsDemoman|Fired when the player spawns as a Demoman.}}
}}
{{IO|OnPlayerSpawnAsMedic|Fired when the player spawns as a Medic.}}
 
{{IO|OnPlayerSpawnAsHeavy|Fired when the player spawns as a Heavy.}}
 
{{IO|OnPlayerSpawnAsPyro|Fired when the player spawns as a Pyro.}}
== Keyvalues ==
{{IO|OnPlayerSpawnAsSpy|Fired when the player spawns as a Spy.}}
{{KV Targetname}}
{{IO|OnPlayerSpawnAsEngineer|Fired when the player spawns as an Engineer.}}
{{KV|Next Map|intn=nextMap|string|Next map to load when the current one is finished. Default choices are <code>tr_dustbowl</code> and <code>tr_target</code>, although any map is accepted.}}
{{IO|OnPlayerDied|Fired when the player dies.}}
 
{{IO|OnBotDied|Fired when a bot dies.}}
== Inputs ==
{{IO|OnPlayerSwappedToPrimary|Fired when the player swaps to the item in their primary weapon slot.}}
{{warning|<code>EndTraining</code>, <code>PlaySoundOnPlayer</code>, and <code>ForcePlayerSwapToWeapon</code> will not work on dedicated servers.}}
{{IO|OnPlayerSwappedToSecondary|Fired when the player swaps to the item in their secondary weapon slot.}}
{{tip|official training maps use a special character to show yellow text, look for <code>TR_Generic_WeaponFire</code> in ''tf/resource/tf_english.txt'' to find this special character}}
{{IO|OnPlayerSwappedToMelee|Fired when the player swaps to the item in their melee weapon slot.}}
{{I|ShowTrainingMsg|Show a training message, for training mode. The parameter can be any raw string or a localized string entry from tf_english.txt|param=string}}
{{IO|OnPlayerSwappedToBuilding|Fired when the player swaps to the item in their building weapon slot.}}
{{tip|similar to [[env_hudhint]], training messages can read keybinds, for example <code>Press %reload%</code>}}
{{IO|OnPlayerSwappedToPDA|Fired when the player swaps to the item in their PDA weapon slot.}}
{{I|ShowTrainingObjective|param=string|Sets a training objective to show to the player.}}
{{IO|OnBuildOutsideArea|Fired when the player builds an object outside a suggested area.}}
{{I|KickBots|Kicks all [[bot]]s from the server.}}
{{IO|OnPlayerDetonateBuilding|Sent when the player manually detonates one of their buildings.}}
{{I|ShowTrainingHUD|Makes the training objective HUD visible.}}
{{O BaseEntity}}
{{I|HideTrainingHUD|Makes the training objective HUD hidden.}}
{{I|EndTraining|param=string|Ends training mode. The parameter is for displaying ending text from tf_english.txt}}
{{I|PlaySoundOnPlayer|param=string|Play a sound on the player.}}
{{I|WaitForTimerOrKeypress|Wait for the specified [[logic_timer]] entity to fire on its interval or for a keypress from the player.|param=string}}
{{I|SetNextMap|param=string|Set the next map for training.}}
{{I|ForcePlayerSpawnAsClassOutput|Force the appropriate output to fire for the player spawning as a class. You can use this to essentially ask what class the player is.}}
 
== Outputs ==
{{todo|See which outputs work in multiplayer}}
{{O|OnPlayerSpawnAsScout|ac-is-this=1|param=void|Fired when the player spawns as a Scout.}}
{{O|OnPlayerSpawnAsSniper|ac-is-this=1|param=void|Fired when the player spawns as a Sniper.}}
{{O|OnPlayerSpawnAsSoldier|ac-is-this=1|param=void|Fired when the player spawns as a Soldier.}}
{{O|OnPlayerSpawnAsDemoman|ac-is-this=1|param=void|Fired when the player spawns as a Demoman.}}
{{O|OnPlayerSpawnAsMedic|ac-is-this=1|param=void|Fired when the player spawns as a Medic.}}
{{O|OnPlayerSpawnAsHeavy|ac-is-this=1|param=void|Fired when the player spawns as a Heavy.}}
{{O|OnPlayerSpawnAsPyro|ac-is-this=1|param=void|Fired when the player spawns as a Pyro.}}
{{O|OnPlayerSpawnAsSpy|ac-is-this=1|param=void|Fired when the player spawns as a Spy.}}
{{O|OnPlayerSpawnAsEngineer|ac-is-this=1|param=void|Fired when the player spawns as an Engineer.}}
{{O|OnPlayerDied|activator=the killer|param=void|Fired when the player dies.}}
{{O|OnBotDied|activator=the killer|param=void|Fired when a bot dies.}}
{{O|OnPlayerSwappedToPrimary|ac-is-this=1|param=void|Fired when the player swaps to the item in their primary weapon slot.}}
{{O|OnPlayerSwappedToSecondary|ac-is-this=1|param=void|Fired when the player swaps to the item in their secondary weapon slot.}}
{{O|OnPlayerSwappedToMelee|ac-is-this=1|param=void|Fired when the player swaps to the item in their melee weapon slot.}}
{{O|OnPlayerSwappedToBuilding|ac-is-this=1|param=void|Fired when the player swaps to the item in their building weapon slot.}}
{{O|OnPlayerSwappedToPDA|ac-is-this=1|param=void|Fired when the player swaps to the item in their PDA weapon slot.}}
{{O|OnBuildOutsideArea|activator=the building|param=void|Fired when the player builds an object outside a suggested area.}}
{{O|OnPlayerDetonateBuilding|activator=the player|caller=the building|param=void|Sent when the player manually detonates one of their buildings.}}

Latest revision as of 11:43, 8 May 2025

English (en)Translate (Translate)
C++ Class hierarchy
CTrainingModeLogic
CPointEntity
CBaseEntity
C++ tf_gamerules.cpp

tf_logic_training_mode is a logical entity available in Team Fortress 2 Team Fortress 2. Handles outputs and and messages for training, mainly for the player.

Tip.pngTip:This entity, as well as most of its Inputs, can be used on any multiplayer map by spawning this entity after map load and setting the m_bIsInTraining NetProp on tf_gamerules to true with VScript, however there are multiple caveats:
  1. Players loadout will be replaced with stock items on resupply/respawn while training mode is enabled
  2. The server will be hidden from the server browser, this will persist for the entire duration of the map
  3. Achievement tracking is disabled
  4. Doesn't print player join or team switch chat messages (they can still be seen when opening chat)
  5. Team and class switching menus will be disabled, however join_class and autoteam will still work
  6. Autobalance is disabled
  7. Domination/Revenge logic is disabled
PlacementTip.pngWorkaround:Many of these issues have workarounds:

  1. Iterate player items and store them in an array/table in player scope first, then re-equip them using this method after they are stripped. This will not restore items correctly if the player changes their loadout and resupplies while the annotation is active
  2. For custom servers, the hide_server cvar must be added to the vscript cvar allowlist, or sv_allow_point_servercommand must be set to always for SendToServerConsole
  3. Set m_bAllowTrainingAchievements to true on tf_gamerules
  4. Set m_bIsInTraining to false on player_connect or player_team and set back to true shortly after. However this will disable any active training HUD elements
Todo: No known workaround, need to enable/disable the NetProp or use the console commands for class/team switching
Todo: No known workaround
Todo: Potentially send the player_death event manually with domination/revenge death flags, or player_domination, untested.


Keyvalues

Name (targetname) <string>[ Edit ]
The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g. parentname or target).
Also displayed in Hammer's 2D views and Entity Report.
See also:  Generic Keyvalues, Inputs and Outputs available to all entities

Next Map (nextMap) <string>
Next map to load when the current one is finished. Default choices are tr_dustbowl and tr_target, although any map is accepted.

Inputs

Warning.pngWarning:EndTraining, PlaySoundOnPlayer, and ForcePlayerSwapToWeapon will not work on dedicated servers.
Tip.pngTip:official training maps use a special character to show yellow text, look for TR_Generic_WeaponFire in tf/resource/tf_english.txt to find this special character
ShowTrainingMsg <stringRedirectInput/string>
Show a training message, for training mode. The parameter can be any raw string or a localized string entry from tf_english.txt
Tip.pngTip:similar to env_hudhint, training messages can read keybinds, for example Press %reload%
ShowTrainingObjective <stringRedirectInput/string>
Sets a training objective to show to the player.
KickBots
Kicks all bots from the server.
ShowTrainingHUD
Makes the training objective HUD visible.
HideTrainingHUD
Makes the training objective HUD hidden.
EndTraining <stringRedirectInput/string>
Ends training mode. The parameter is for displaying ending text from tf_english.txt
PlaySoundOnPlayer <stringRedirectInput/string>
Play a sound on the player.
WaitForTimerOrKeypress <stringRedirectInput/string>
Wait for the specified logic_timer entity to fire on its interval or for a keypress from the player.
SetNextMap <stringRedirectInput/string>
Set the next map for training.
ForcePlayerSpawnAsClassOutput
Force the appropriate output to fire for the player spawning as a class. You can use this to essentially ask what class the player is.

Outputs

Todo: See which outputs work in multiplayer
OnPlayerSpawnAsScout <void>
!activator = !caller = this entity
Fired when the player spawns as a Scout.
OnPlayerSpawnAsSniper <void>
!activator = !caller = this entity
Fired when the player spawns as a Sniper.
OnPlayerSpawnAsSoldier <void>
!activator = !caller = this entity
Fired when the player spawns as a Soldier.
OnPlayerSpawnAsDemoman <void>
!activator = !caller = this entity
Fired when the player spawns as a Demoman.
OnPlayerSpawnAsMedic <void>
!activator = !caller = this entity
Fired when the player spawns as a Medic.
OnPlayerSpawnAsHeavy <void>
!activator = !caller = this entity
Fired when the player spawns as a Heavy.
OnPlayerSpawnAsPyro <void>
!activator = !caller = this entity
Fired when the player spawns as a Pyro.
OnPlayerSpawnAsSpy <void>
!activator = !caller = this entity
Fired when the player spawns as a Spy.
OnPlayerSpawnAsEngineer <void>
!activator = !caller = this entity
Fired when the player spawns as an Engineer.
OnPlayerDied <void>
!activator = the killer
!caller = this entity
Fired when the player dies.
OnBotDied <void>
!activator = the killer
!caller = this entity
Fired when a bot dies.
OnPlayerSwappedToPrimary <void>
!activator = !caller = this entity
Fired when the player swaps to the item in their primary weapon slot.
OnPlayerSwappedToSecondary <void>
!activator = !caller = this entity
Fired when the player swaps to the item in their secondary weapon slot.
OnPlayerSwappedToMelee <void>
!activator = !caller = this entity
Fired when the player swaps to the item in their melee weapon slot.
OnPlayerSwappedToBuilding <void>
!activator = !caller = this entity
Fired when the player swaps to the item in their building weapon slot.
OnPlayerSwappedToPDA <void>
!activator = !caller = this entity
Fired when the player swaps to the item in their PDA weapon slot.
OnBuildOutsideArea <void>
!activator = the building
!caller = this entity
Fired when the player builds an object outside a suggested area.
OnPlayerDetonateBuilding <void>
!activator = the player
!caller = the building
Sent when the player manually detonates one of their buildings.