# Usage

## Exports

#### Server-Side Exports

**getPlayerSubscriptions**

*This export can be used if you want to retrieve all subscriptions of the target player.*

```lua
// Usage example
RegisterNetEvent("exampleEvent", function()
   local Player = Framework.Functions.GetPlayer(source)
   local currentSubscriptions = exports['cfx-praryo-subscriptions']:getPlayerSubscriptions(Player.PlayerData.source)
	
   print(json.encode(currentSubscriptions, {
     indent = true
   }))
end)

// Output (Array): {"level_1", "level_2"}
// level_1, level_2 comes from the Config.Subscriptions index.
```

**hasPlayerSubscription**

*This export can be used to determine whether a player has a specific subscription.*

```lua
// Usage example
RegisterNetEvent("exampleEvent", function()
   local Player = Framework.Functions.GetPlayer(source)
   local hasSub = exports['cfx-praryo-subscriptions']:hasPlayerSubscription(Player.PlayerData.source, "level_1")
	
   if hasSub then
      print("Subscribed to level_1 subscription.")
   else
      print("Not subscribed to level_1 subscription.")
   end
end)
```

####

**addPlayerSubscription**

*This export can be used to add pending subscriptions using your scripts.*

```lua
// Usage example
RegisterNetEvent("exampleEvent", function()
   local Player = Framework.Functions.GetPlayer(source)
   local success, message, message_type = exports['cfx-praryo-subscriptions']:addPlayerSubscription(Player.PlayerData.source, "level_1")
	
   if success then
      print("Added subscription pending to player")
   else
      print("Failed to add (".. message_type .."): ".. message .."")
   end
end)
```

**removePlayerSubscription**

*This export can be used to remove subscriptions using your scripts.*

```lua
// Usage example
RegisterNetEvent("exampleEvent", function()
   local Player = Framework.Functions.GetPlayer(source)
   local success, message, message_type = exports['cfx-praryo-subscriptions']:removePlayerSubscription(Player.PlayerData.source, "level_1")
	
   if success then
      print("Remove subscription from player")
   else
      print("Failed to remove (".. message_type .."): ".. message .."")
   end
end)
```

#### Client-Side Exports

**getPlayerSubscriptions**

*This export can be used if you want to retrieve all subscriptions of the target player.*

```lua
// Usage example
RegisterNetEvent("exampleEvent", function()
   local currentSubscriptions = exports['cfx-praryo-subscriptions']:getPlayerSubscriptions()
	
   print(json.encode(currentSubscriptions, {
     indent = true
   }))
end)

// Output (Array): {"level_1", "level_2"}
// level_1, level_2 comes from the Config.Subscriptions index.
```

**hasPlayerSubscription**

*This export can be used to determine whether a player has a specific subscription.*

```lua
// Usage example
RegisterNetEvent("exampleEvent", function()
   local hasSub = exports['cfx-praryo-subscriptions']:hasPlayerSubscription("level_1")
	
   if hasSub then
      print("Subscribed to level_1 subscription.")
   else
      print("Not subscribed to level_1 subscription.")
   end
end)
```

## Events

**Server-Side Events**

*Usage:*

<pre class="language-lua"><code class="lang-lua"><strong>-- Event when a player redeem a subscription
</strong><strong>AddEventHandler("cfx-praryo-subscriptions:serverEvents:newSubscription", function(source, subscription)
</strong>   print("[".. source .."] Subscription added: " .. subscription)
end)

-- Event when admin remove a subscription from player
AddEventHandler("cfx-praryo-subscriptions:serverEvents:removeSubscription", function(source, subscription)
   print("[".. source .."] Subscription removed: " .. subscription)
end)
</code></pre>

*Example:*

```lua
AddEventHandler("cfx-praryo-subscriptions:serverEvents:newSubscription", function(source, subscription)
   local Player = Framework.Functions.GetPlayer(source)
	
   if subscription == "level_1" then
      exports.ox_inventory:AddItem(source, 'bread', 4)
   end
end)
```

#### Client-Side Events

*Usage:*

```lua
RegisterNetEvent("cfx-praryo-subscriptions:clientEvents:newSubscription", function(subscription)
   print("Subscription added: " .. subscription)
end)

RegisterNetEvent("cfx-praryo-subscriptions:clientEvents:removeSubscription", function(subscription)
   print("Subscription removed: " .. subscription)
end)
```

*Example:*

```lua
RegisterNetEvent("cfx-praryo-subscriptions:clientEvents:newSubscription", function(subscription)
   if subscription == "level_1" then
      exports.ox_inventory:openInventory('stash', { id = 'level_1_subscription' })
   end
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://praryo.gitbook.io/documentation/paid-resources/cfx-praryo-subscriptions/usage.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.
