Left 4 Dead 2/Script Functions/GetInvTable

From Valve Developer Community
Jump to: navigation, search
Dead End - Icon.png
This article has no links to other VDC articles. Please help improve this article by adding links that are relevant to the context within the existing text.
January 2024

Function Description

void GetInvTable(CTerrorPLayer player,table invTable)

Fills invTable with the specified player's inventory. This function works on survivors and special infected.


Type Name Description
CTerrorPlayer player Player who's inventory to get.
table invTable Table for writing the inventory in.


// Prints a list of weapons each player is carrying
function PrintWeapons()
	local player = null
	// Iterate through every player
	while(player = Entities.FindByClassname(player, "player"))
		printl("Player: " + player.GetPlayerName())
		// Add an empty table to store the inventory in
		local invTable = {}
		// Call the function to fill the table
		GetInvTable(player, invTable)
		// Check if the player has a primary weapon
		if("slot0" in invTable)
			printl("Primary weapon equipped: " + invTable.slot0)
			printl("Primary weapon not equipped!")
		// Print all equipped weapons
		foreach(slot, weapon in invTable)
			printl("\t" + slot + "= " + weapon.GetClassname())


Output Parameters

Keys written to invTable by the function.

Warning.pngWarning: Only keys with equipped weapons are added to the table. Always confirm that a key exists using the Squirrel in keyword before using it.
Type Key Description
handle slot0 Primary weapon
handle slot1 Secondary weapon
handle slot2 Throwable
handle slot3 Medkit/Defib
handle slot4 Pills/Adrenaline
handle slot5 Carried physics object (L4D style, e.g. Gas can or the Gnome)
handle Held Carried physics object (legacy style, from CanPickupObject() or PickupObject() )