Home / Lua / Server / Player / Functions / GetInventory


Returns    table
Prototype    Player:GetInventory()
Description    Returns the player's inventory as a table of Weapons.

Example

Report a player's inventory to them when they type '/inventory'

function PlayerChat(args)
	if args.text == "/inventory" then
		PrintInventory(args.player)
	end
end

function PrintInventory(player)
	local inventory = player:GetInventory()
	Chat:Send(player, "You are carrying "..table.count(inventory).." weapons:", Color.PeachPuff)
	for slot, weapon in pairs(inventory) do
		Chat:Send(player, "\tSlot "..slot..": "..weapon.id, Color.MintCream)
	end
end

Events:Subscribe("PlayerChat", PlayerChat)

Example output

You are carrying 2 weapons:
	Slot 0: 2
	Slot 2: 14

See also