# 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](https://docs.easy.gg/scripting/bedwars-scripting/objects/player), itemType: [ItemType](https://docs.easy.gg/scripting/bedwars-scripting/types/itemtype), 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](https://docs.easy.gg/scripting/bedwars-scripting/services/broken-reference), itemType: [ItemType](https://docs.easy.gg/scripting/bedwars-scripting/services/broken-reference)): number

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

#### removeItemAmount(player: [Player](https://docs.easy.gg/scripting/bedwars-scripting/services/broken-reference), itemType: [ItemType](https://docs.easy.gg/scripting/bedwars-scripting/services/broken-reference), amount: number)

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

#### clearInventory(player: [Player](https://docs.easy.gg/scripting/bedwars-scripting/services/broken-reference))

Clears all items from the player's inventory.

#### getInventory(player: [Player](https://docs.easy.gg/scripting/bedwars-scripting/services/broken-reference)): { itemType: [ItemType](https://docs.easy.gg/scripting/bedwars-scripting/types/itemtype), 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
