# SIM CARDS

1. Get player from number

{% tabs %}
{% tab title="Server Side" %}
* number `string`

```lua
exports['piotreq_phone']:GetPlayerFromNumber(number)
```
{% endtab %}
{% endtabs %}

Usage example

```lua
local xPlayer = exports['piotreq_phone']:GetPlayerFromNumber('piotreq')
if xPlayer then
   xPlayer.addInventoryItem('burger', 1) -- For ESX Framework (set framework in cfg)
end
```

2. Get number from identifier

{% tabs %}
{% tab title="Server Side" %}
* identifier `string`

```lua
exports['piotreq_phone']:GetNumberFromIdentifier(identifier)
```
{% endtab %}
{% endtabs %}

Usage example

```lua
local xPlayer = ESX.GetPlayerFromId(source)
local identifier = xPlayer.identifier
local playerNumber = exports['piotreq_phone']:GetNumberFromIdentifier(identifier)
if playerNumber then
   exports['piotreq_phone']:SendMessage({
      sender = 'Lester',
      receiver = playerNumber,
      content = 'Location is here'
   })
end
```

3. Get player number

{% tabs %}
{% tab title="Client Side" %}
```lua
exports['piotreq_phone']:GetNumber()
```
{% endtab %}
{% endtabs %}

Usage Example

```lua
local playerNumber = exports['piotreq_phone']:GetNumber()
print(playerNumber)
```

4. Check if sim card already exist

{% tabs %}
{% tab title="Server Side" %}
* number `string | number`

```lua
exports['piotreq_phone']:SimCardExist(number)
```
{% endtab %}
{% endtabs %}

Usage Example

```lua
local simExist = exports['piotreq_phone']:SimCardExist('piotreq')
print(simExist)
```

5. Generate number (function is checking if number already exist, you dont need to check it)

{% tabs %}
{% tab title="Server Side" %}
```lua
exports['piotreq_phone']:GenerateNumber()
```
{% endtab %}
{% endtabs %}

Usage Example

```lua
local newNumber = exports['piotreq_phone']:GenerateNumber()
print(newNumber)
```

6. Create sim card

{% tabs %}
{% tab title="Server Side" %}
* playerId `number`

```lua
exports['piotreq_phone']:CreateSimCard(playerId)
```
{% endtab %}
{% endtabs %}

Usage Example

```lua
local newSim = exports['piotreq_phone']:CreateSimCard(source)
print(newSim) -- function is returning number of created sim card
```

7. Get contact name by number

{% tabs %}
{% tab title="Server Side" %}
* sourceNumber `string | number`
* targetNumber `string | number`

```lua
exports['piotreq_phone']:GetContactByNumber(sourceNumber, targetNumber)
```
{% endtab %}
{% endtabs %}

8. Check if number is blocked

{% tabs %}
{% tab title="Server Side" %}
* sourceNumber `string | number`
* targetNumber `string | number`

```lua
exports['piotreq_phone']:NumberIsBlocked(sourceNumber, targetNumber)
```
{% endtab %}
{% endtabs %}

Usage Example

```lua
local isBlocked = exports['piotreq_phone']:NumberIsBlocked('piotreq', '123')
print(isBlocked) -- true | false
```

9. Get blocked numbers

{% tabs %}
{% tab title="Server Side" %}
* number `string | number`

```lua
exports['piotreq_phone']:GetBlockedNumbers(number)
```
{% endtab %}
{% endtabs %}

Usage Example

```lua
local numbers = exports['piotreq_phone']:GetBlockedNumbers(number)
print(json.encode(numbers))
-- {"123", "piotreq"}
```
