> For the complete documentation index, see [llms.txt](https://docs.easy.gg/scripting/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.easy.gg/scripting/bedwars-scripting/services/inventoryservice.md).

# InventoryService

Example usage:

```lua
-- Set up a 20% chance to drop an emerald when damaging enemies
Events.EntityDamage(function(event)
    if not event.fromEntity then
        return
    end
    
    -- Only give emeralds when random between 1 and 5 is 1
    if math.random(1, 5) ~= 1 then
        return
    end
    
    local fromPlayer = event.fromEntity:getPlayer()
    if fromPlayer then
        InventoryService.giveItem(fromPlayer, ItemType.EMERALD, 1, true)
    end
end)
```

### Functions

#### giveItem(player: [Player](/scripting/bedwars-scripting/objects/player.md), itemType: [ItemType](/scripting/bedwars-scripting/types/itemtype.md), amount: number, playWorldEffect: bool)

Gives a player a specified number of an item. If `playWorldEffect` is true, an effect will play showing the recipient getting their items.

#### getAmount(player: [Player](broken://pages/fOfVQF5nlALekCoylPz2), itemType: [ItemType](broken://pages/FvdgRy7Bq206vdjUGPn7)): number

Returns amount of specified item the player has (0 if they have none).

#### removeItemAmount(player: [Player](broken://pages/fOfVQF5nlALekCoylPz2), itemType: [ItemType](broken://pages/FvdgRy7Bq206vdjUGPn7), amount: number)

Removes the amount of the item from the player's inventory.&#x20;

#### clearInventory(player: [Player](broken://pages/fOfVQF5nlALekCoylPz2))

Clears all items from the player's inventory.

#### getInventory(player: [Player](broken://pages/fOfVQF5nlALekCoylPz2)): { itemType: [ItemType](/scripting/bedwars-scripting/types/itemtype.md), amount: number }\[]

Returns a table of the amount of each item the player has in their inventory - including armor and hand items.

Example:

```lua
local player = PlayerService.getPlayerByDisplayName("quinticat")
local inv = InventoryService.getInventory(player)
for i, data in ipairs(inv) do
    print(player.name .. " has " .. data.amount .. " " .. data.itemType)
end
```
