# Unlockables

**URL:** https://heroiclabs.com/docs/hiro/server-framework/unlockables/
**Keywords:** unlockables, hiro
**Categories:** hiro, unlockables, server-framework

---


# Unlockables

Read more about the Unlockables system in Hiro [here](../../concepts/unlockables/).

## Functions

### Create

Place a new unlockable into a slot either randomly, by ID, or optionally using a custom configuration.

```go
userId := "userId"
unlockableId := "unlockableId"
unlockableConfig := &hiro.UnlockablesConfigUnlockable{}

unlockables, err := systems.GetUnlockablesSystem().Create(ctx, logger, nk, userId, unlockableId, unlockableConfig)
if err != nil {
  return err
}
```

### Get

Get all unlockables active for a user.

```go
userId := "userId"

unlockables, err := systems.GetUnlockablesSystem().Get(ctx, logger, nk, userId)
if err != nil {
  return err
}
```

### UnlockAdvance

Add the given amount of time towards the completion of an unlockable that has been started.

```go
userId := "userId"
instanceId := "instanceId"
var seconds int64 = 3600

unlockables, err := systems.GetUnlockablesSystem().UnlockAdvance(ctx, logger, nk, userId, instanceId, seconds)
if err != nil {
  return err
}
```

### UnlockStart

Begin an unlock of an unlockable for a user.

```go
userId := "userId"
instanceId := "instanceId"

unlockables, err := systems.GetUnlockablesSystem().UnlockStart(ctx, logger, nk, userId, instanceId)
if err != nil {
  return err
}
```

### PurchaseUnlock

Immediately unlock an unlockable for a user.

```go
userId := "userId"
instanceId := "instanceId"

unlockables, err := systems.GetUnlockablesSystem().PurchaseUnlock(ctx, logger, nk, userId, instanceId)
if err != nil {
  return err
}
```

### PurchaseSlot

Create a new slot for a user.

```go
userId := "userId"

unlockables, err := systems.GetUnlockablesSystem().PurchaseSlot(ctx, logger, nk, userId)
if err != nil {
  return err
}
```

### Claim

Claim an unlockable which has been unlocked for the user.

```go
userId := "userId"
instanceId := "instanceId"

reward, err := systems.GetUnlockablesSystem().Claim(ctx, logger, nk, userId, instanceId)
if err != nil {
  return err
}
```

### QueueAdd

Add one or more unlockables to the queue to be unlocked as soon as an active slot is available.

```go
userId := "userId"
instanceIds := []string{"instanceId_001", "instanceId_002"}

unlockables, err := systems.GetUnlockablesSystem().QueueAdd(ctx, logger, nk, userId, instanceIds)
if err != nil {
  return err
}
```

### QueueRemove

Remove one or more unlockables from the unlock queue, unless they have started unlocking already.

```go
userId := "userId"
instanceIds := []string{"instanceId_001", "instanceId_002"}

unlockables, err := systems.GetUnlockablesSystem().QueueRemove(ctx, logger, nk, userId, instanceIds)
if err != nil {
  return err
}
```

### QueueSet

Replace the entirety of the queue with the specified instance IDs, or wipes the queue if no instance IDs are given.

```go
userId := "userId"
instanceIds := []string{"instanceId_001", "instanceId_002"}

unlockables, err := systems.GetUnlockablesSystem().QueueSet(ctx, logger, nk, userId, instanceIds)
if err != nil {
  return err
}
```

## Hooks

### SetOnClaimReward

Set a custom reward function which will run after an unlockable's reward is rolled.

```go
systems.GetUnlockablesSystem().SetOnClaimReward(OnClaimReward)

func OnClaimReward(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, sourceID string, source *hiro.UnlockablesConfigUnlockable, rewardConfig *hiro.EconomyConfigReward, reward *hiro.Reward) (*hiro.Reward, error) {
	// Modify reward or take additional actions.
	return reward, nil
}
```