Personal tools

Lua/Client/Player/Functions/GetInventory

From JC2-MP Documentation

< Lua‎ | Client‎ | Player
Jump to: navigation, search

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


Example

Print your inventory when you type 'inventory' in console

  1. function PrintInventory()
  2. 	local inventory = LocalPlayer:GetInventory()
  3. 	print("You are carrying "..table.count(inventory).." weapons:")
  4. 	for slot, weapon in pairs(inventory) do
  5. 		print("\tSlot "..slot..": "..weapon.id)
  6. 	end
  7. end
  8.  
  9. Console:Subscribe("inventory", PrintInventory)

Example output

17:08:45 | [info ] | [sandbox] You are carrying 2 weapons:
17:08:45 | [info ] | [sandbox] 	Slot 0: 2
17:08:45 | [info ] | [sandbox] 	Slot 2: 14

See also

Player:GetInventory (server)