This article is the documentation for the game "Team Fortress 2". Click here to go to the main page of the development documents.

Community Contributions

From Valve Developer Community
Jump to navigation Jump to search
English (en)Translate (Translate)

Squirrel This page contains code contributions and tips from the TF2Maps.net Discord for VScript in Team Fortress 2 Team Fortress 2

Warning.pngWarning:This page is still in construction! since it takes time adding all the contributions

Hooks

Some of these contributions are Hooks or Game events, learn Here on how to listen to them.

Script List

Name Description Usage Code
Change Halloween Scenario Allows to enable hardcoded stuff from specific halloween maps anywhere else. Check this list for all of them
Scenarios 
  • 0 - HALLOWEEN_SCENARIO_NONE
  • 1 - HALLOWEEN_SCENARIO_MANN_MANOR - Enables the Horseless Headless Horsemann Achievements
  • 2 - HALLOWEEN_SCENARIO_VIADUCT - Enables the Monoculuus Achievments
  • 3 - HALLOWEEN_SCENARIO_LAKESIDE - Enables Merasmus Achievments, and misc. stuff
  • 4 - HALLOWEEN_SCENARIO_HIGHTOWER - Helltower Features
  • 5 - HALLOWEEN_SCENARIO_DOOMSDAY - Carnival of Carnage Features
Warning.pngWarning:Changes can be reverted, some changes will save, but expect undesired effects!
Run the following code on tf_gamerules. NetProps.SetPropInt(self, "m_halloweenScenario", 0-5)
Health gain on HUD Show to a player a custom amount of gained HP
Warning.pngWarning:
  • Visual Only
  • Negative values will still show green
  • The Amount is not capped
Call the following event, specifying who is the player.
SendGlobalGameEvent("player_healonhit", {
  entindex = player.entindex(),
  amount = healAmount
});
Add or Remove score in RD/PD Destruction (Player and Objective less) This is so far the only way to change the score if the base gamemode is used differently than his original intent. Run this script anywhere, and call the two Functions.
Contents 
local logic_destruction = Entities.FindByClassname(null, "tf_logic_player_destruction")

::ScorePoints <- function(team, killscore)
{
    //Score Points by using a dummy flag and send it -Burguers
    printl("Added: " + killscore)
    FlagDummy <- SpawnEntityFromTable("item_teamflag", {
        TeamNum = team,
        PointValue = killscore,
        GameType = 5,
        trail_effect = 0,
    })
    FlagDummy.AcceptInput("RoundActivate", "!self", null, null)
    FlagDummy.Kill()
}

::RemovePoints <- function(team, killscore)
{
    local currentScore = NetProps.GetPropInt(logic_destruction,team == 2 ? "m_nRedScore" : "m_nBlueScore");
    local newScore = currentScore - killscore;
    printl("Current Score: " + currentScore)

    RemoverFlag <- SpawnEntityFromTable("item_teamflag", {
        TeamNum = team,
        GameType = 5,
        trail_effect = 0,
    })
    //This Sets the points to 0 caused by an overflow, then deliver a new ammount by calling the scoring above
    if (currentScore != 0)
    {
        RemoverFlag.KeyValueFromString("PointValue", "4294967295")
        RemoverFlag.AcceptInput("RoundActivate", "!self", null, null)
        RemoverFlag.Kill()
        if (newScore > 0)
            CG_ScorePoints(team, newScore)
    }
}
Hook ↑ Changing Killicon Force to display custom killicons if the user died to something specific, by spawning a dummy entity and changing his classname.
Tip.pngTip: Killicons List
myCustomInflictor <- SpawnEntityFromTable("info_target", { classname = "bumper_kart" }); //Replace "bumper_kart" with the kill icon you want to use
OnScriptHook_OnTakeDamage = function(params)
{
  if (/* insert your condition */)
    params.inflictor = myCustomInflictor;
}