> 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
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.easy.gg/scripting/bedwars-scripting/services/inventoryservice.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
