Personal tools

Lua/Server/Player/Functions/GetInventory

From JC2-MP Documentation

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

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'

  1. function PlayerChat(args)
  2. 	if args.text == "/inventory" then
  3. 		PrintInventory(args.player)
  4. 	end
  5. end
  6.  
  7. function PrintInventory(player)
  8. 	local inventory = player:GetInventory()
  9. 	Chat:Send(player, "You are carrying "..table.count(inventory).." weapons:", Color.PeachPuff)
  10. 	for slot, weapon in pairs(inventory) do
  11. 		Chat:Send(player, "\tSlot "..slot..": "..weapon.id, Color.MintCream)
  12. 	end
  13. end
  14.  
  15. Events:Subscribe("PlayerChat", PlayerChat)

Example output

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

See also