# SInventory

**الأعضاء** 7

|       |                                         |                                                                                                      |
| ----- | --------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| دالة  | [Authorize](#authorize)                 | Requests access to inventory functions, must be called prior to attempting to access inventory.      |
| دالة  | [CountCopiesOfItem](#countcopiesofitem) | –                                                                                                    |
| دالة  | [AddToHotbar](#addtohotbar)             | Adds the first found instance of itemID to the players hotbar entry at slot 'index'.                 |
| دالة  | [RemoveFromHotbar](#removefromhotbar)   | Remove item at slot index from Hotbar                                                                |
| دالة  | [RequestRefresh](#requestrefresh)       | Forces a check for external changes to the users inventory, can only be called once every 60 seconds |
| خاصية | [Authorized](#authorized)               | Returns true if player has accepted access authorization request to his inventory                    |
| خاصية | [Items](#items)                         | Returns the array of the users current inventory items                                               |

## الدوال

### Authorize

void Authorize(Closure onAuthorized = null, Closure onRejected = null)

Requests access to inventory functions, must be called prior to attempting to access inventory. As soon as the player has accepted the request, the Authorized attribute will be 'true'.

المعاملات

| الاسم        | النوع   | القيمة الافتراضية |
| ------------ | ------- | ----------------- |
| onAuthorized | Closure | null              |
| onRejected   | Closure | null              |

القيم المرجعة

`void`

مثال

**Lua**

```lua
 Space.Inventory.Authorize()
 --or
 Space.Inventory.Authorize(onAuth, onRej)

```

**Lua**

```lua
--this script shows you how to use this function to take authorization and immediately
--take action based on the result all in a single prompt (a click in this case)

function ifno()
  Space.Log("not authorized")
  end

function ifyes()
Space.Log("authorized")
--your next steps go here
  end
function click()
  
  Space.Inventory.Authorize(ifyes,ifno)

end


Space.Host.ExecutingObject.AddClickable()
Space.Host.ExecutingObject.Clickable.OnClick(click) 

```

### CountCopiesOfItem

int CountCopiesOfItem(int itemID)

المعاملات

| الاسم  | النوع | القيمة الافتراضية |
| ------ | ----- | ----------------- |
| itemID | int   | –                 |

القيم المرجعة

`int`

مثال

**Lua**

```lua
numOfCopies = Space.Inventory.CountCopiesOfItem(38384839)

```

### AddToHotbar

void AddToHotbar(int index, int itemID)

Adds the first found instance of itemID to the players hotbar entry at slot 'index'.

المعاملات

| الاسم  | النوع | القيمة الافتراضية |
| ------ | ----- | ----------------- |
| index  | int   | –                 |
| itemID | int   | –                 |

القيم المرجعة

`void`

مثال

**Lua**

```lua
Space.Inventory.AddToHotbar(2, 23423523)

```

### RemoveFromHotbar

void RemoveFromHotbar(int index)

Remove item at slot index from Hotbar

المعاملات

| الاسم | النوع | القيمة الافتراضية |
| ----- | ----- | ----------------- |
| index | int   | –                 |

القيم المرجعة

`void`

مثال

**Lua**

```lua
Space.Inventory.RemoveFromHotbar(2)

```

### RequestRefresh

void RequestRefresh()

Forces a check for external changes to the users inventory, can only be called once every 60 seconds

القيم المرجعة

`void`

مثال

**Lua**

```lua
Space.Inventory.RequestRefresh()

```

## الخصائص

### Authorized

bool Authorized {get; }

Returns true if player has accepted access authorization request to his inventory

مثال

**Lua**

```lua
isAuthorized = Space.Inventory.Authorized

```

### Items

[SInventoryItem](/docs/ar/scripting/client-scripting-api-reference/types/sinventoryitem.md)\[] Items {get; }

Returns the array of the users current inventory items

مثال

**Lua**

```lua
invItems = Space.Inventory.Items

```
