# ItemPurchase

Example usage:

```lua
-- Refund 50% of all Iron purchases in the shop
Events.ItemPurchase(function(event)
    -- Only refund the player if the resource used to purchase the item is Iron
    if (event.costItem == ItemType.IRON) then
        -- Round 50% of the price to the closest smaller integer
        local refund = math.floor(event.price * 0.5);
        InventoryService.giveItem(event.player, ItemType.IRON, refund, true)
    end
end)
```

### Parameters

#### player: [Player](/scripting/bedwars-scripting/objects/player.md)

The player who received a new item.

#### itemType: [ItemType](/scripting/bedwars-scripting/types/itemtype.md)

The type of item received by the player.

#### amount: number

The amount of the item received by the player.

#### costItem: [ItemType](/scripting/bedwars-scripting/types/itemtype.md)

The type of item used to purchase the specified item.

#### price: number

&#x20;The amount of the cost item used to purchase the specified item.


---

# 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/events/itempurchase.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.
