game_scavenge_progress_display

From Valve Developer Community
Jump to: navigation, search
English (en)Translate (Translate)
Progress display.png
Class hierarchy
CScavengeProgressDisplay
CBaseEntity

game_scavenge_progress_display is a point entity available in Left 4 Dead 2 Left 4 Dead 2. When turned on it displays the number of gas cans poured into point_prop_use_target entities in the current round on the upper part of the screen as <number_of_cans_filled> / <Max>. Number of filled cans cannot be decreased using available inputs but it's possible with vscripts. Turning it off and back on won't nullify the amount.

Keyvalues

Name (targetname) <string>
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

Max (Max) <integer>
Number of items to collect.

Inputs

TurnOn
Turn the display on.
TurnOff
Turn the display off.
SetTotalItems <integer>
Set the target (or total) number of scavenge items.

Vscript Enhancement

Script example to increment/decrement or reset the counter. When this script is used as this entity's Entity script it sets FireUser1 input to increment the counter, FireUser2 to decrement the counter and FireUser3 to reset the counter to 0.

Todo: should work in versus and coop gamemodes but needs more testing
local function add_to_scav_counter(val, index) {
    local current_count = NetProps.GetPropIntArray(terror_gamerules, "m_iScavengeTeamScore", index);
    local new_count = 0;
    if(val != null) {
        new_count = current_count + val;
    }
    if(new_count >= 0 && new_count < 64) {
        NetProps.SetPropIntArray(terror_gamerules, "m_iScavengeTeamScore", new_count, index);
    }
}
local add_to_counter_functions_by_gamemode = {
    function versus(val) {
        local team = NetProps.GetPropInt(terror_gamerules, "m_bAreTeamsFlipped");
        add_to_scav_counter(val, team);
    }
    function coop(val) {
        add_to_scav_counter(val, 0);
    }
}
local gamemode = Director.GetGameModeBase();
if(!(gamemode in add_to_counter_functions_by_gamemode)) {
    printl("Unsupported gamemode for game_scavenge_progress_display script");
    return;
}
terror_gamerules <- Entities.FindByClassname(null, "terror_gamerules").weakref();
AddToCounter <- add_to_counter_functions_by_gamemode[gamemode];
function IncrementScavCounter() {
    AddToCounter(1);
}
//won't decrease already gotten points in versus maybe todo ?
function DecrementScavCounter() {
    AddToCounter(-1);
}
function ResetScavCounter() {
    AddToCounter(null);
}
function OnPostSpawn() {
    self.ConnectOutput("OnUser1", "IncrementScavCounter"); //FireUser1 increments by 1
    self.ConnectOutput("OnUser2", "DecrementScavCounter"); //FireUser2 decrements by 1
    self.ConnectOutput("OnUser3", "ResetScavCounter"); //FireUser3 sets the counter to 0
}

See also