> For the complete documentation index, see [llms.txt](https://titans-productions.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://titans-productions.gitbook.io/documentation/redm/tp-libs/development-api/server.md).

# Server

### Exports

API Getter Function

```lua
local API = exports.tp_libs:getAPI()
```

#### General Utility Functions

1. Gets the selected framework that is used through **TP Libs**.

```lua
--- @param framework - return string
local framework = API.getFramework()
```

2. Gets the webhook url from `tp_libs/server/discord/webhooks.lua` directly for using it on other scripts.

```lua
--- @param framework - requires a valid script name that exists on webhooks.lua file.
--- @param webhookName - requires a valid webhook action name that exists on a valid script on webhooks.lua file
local webhookUrl = API.getWebhookUrl(scriptName, webhookName)
```

3. Sends an image by its url on discord by a valid webhook.

```lua
--- @param webhook - requires a string (a valid webhook url)
--- @param title - requires a string (a title of the sent webhook)
--- @param description - requires a string (a description of the sent webhook)
--- @param url - requires a string (a valid url of the image that must end in .jpg, .jpeg, .png, etc).
--- @param color - requires a string (a valid discord color hash)
API.sendImageUrlToDiscord(webhook, title, description, url, color)
```

4. Sends an embed message on discord by a valid webhook.

```lua
--- @param webhook - requires a string (a valid webhook url)
--- @param title - requires a string (a title of the sent webhook)
--- @param description - requires a string (a description of the sent webhook)
--- @param color - requires a string (a valid discord color hash)
API.sendToDiscord(webhook, title, description, color)
```

5. Trigger client data only on specific jobs. The client event must be having only parameter called `data` which holds the `data` that is sent by the parameter on the trigger event.

```lua
--- @param eventName - requires a string (a valid event name that is located in client)
--- @param data - requires a table form ( { } )
--- @param jobs - requires a table form ( { 'job1', 'job2' } )
API.TriggerClientEventByJobs(eventName, data, jobs) 
```

6. Trigger client data only on specific coordinates. The client event must be having only parameter called `data` which holds the `data` that is sent by the parameter on the trigger event.

```lua
--- @param eventName - requires a string (a valid event name that is located in client)
--- @param data - requires a table form ( { } )
--- @param coords - requires a vector3 ( vector3(x, y, z) ) 
--- @param radius - requires an integer or float value ( the radius that is going to send the required data)
API.TriggerClientEventToCoordsOnly(eventName, data, coords, radius) 
```

7. Trigger client data instant on specific coordinates and the rest players will receive that data in delay. The client event must be having only parameter called `data` which holds the `data` that is sent by the parameter on the trigger event.

```lua
--- @param eventName - requires a string (a valid event name that is located in client)
--- @param data - requires a table form ( { } )
--- @param coords - requires a vector3 ( vector3(x, y, z) ) 
--- @param radius - requires an integer or float value ( the radius that is going to send the required data)
--- @param delay - requires an integer ( the delay for the players who are not near in the coords - in milliseconds)
--- @param multiplyDelay - requires a boolean ( the delay will be multiplied if this is enabled ( true / false ) based on the multiplyMinPlayers parameter)
--- @param multiplyMinPlayers - requires an integer ( the input players count that it will multiply, this is useful if you have lot of players in the server, you might want to multiply the delay if > 50).
API.TriggerClientEventAsyncByCoords(eventName, data, coords, radius, delay, multiplyDelay, multiplyMinPlayers)
```

#### Player Object Data

```lua
local xPlayer = API.GetPlayerObject(source)
```

1. Check if player character has loaded and not in session

```lua
--- @param loaded - return boolean
local loaded = xPlayer.loaded()
```

2. Get player steam hex identifier or citizen id for rsg.

```lua
--- @param identifier - return string
local identifier = xPlayer.getIdentifier()
```

3. Get selected character identifier or cid for rsg.

```lua
--- @param charIdentifier - return string or int (depends what framework is providing)
local charIdentifier = xPlayer.getCharIdentifier()
```

4. Get player group name (user, admin, owner, anything)

```lua
--- @param group - return string
local group = xPlayer.getGroup()
```

5. Get player job name.

```lua
--- @param job - return string
local job = xPlayer.getJob()
```

6. Get player job grade.

```lua
--- @param jobGrade - return integer
local jobGrade = xPlayer.getJobGrade()
```

7. Get player first name.

```lua
--- @param firstname - return string
local firstname = xPlayer.getFirstName()
```

7. Get player last name.

```lua
--- @param lastname - return string
local lastname = xPlayer.getLastName()
```

8. Get player money (cash).

```lua
--- @param money - return integer
local money = xPlayer.getMoney()
```

9. Add player money (cash)

```lua
--- @param amount - requires an integer value.
xPlayer.addMoney(amount)
```

10. Remove player money (cash)

```lua
--- @param amount - requires an integer value.
xPlayer.removeMoney(amount)
```

11. Get player gold.

```lua
--- @param gold - return integer
local gold = xPlayer.getGold()
```

12. Add player gold

```lua
--- @param amount - requires an integer value.
xPlayer.addGold(amount)
```

13. Remove player gold

```lua
--- @param amount - requires an integer value.
xPlayer.removeGold(amount)
```

14. Get player total inventory weight (total items weight that player is carrying).

```lua
--- @param weight - returns an integer or float value.
local weight = xPlayer.getInventoryTotalWeight()
```

15. Get player max inventory weight (the maximum weight player inventory can carry).

```lua
--- @param maxWeight - returns an integer or float value.
local maxWeight = xPlayer.getInventoryMaxWeight()
```

16. Add player inventory item (no metadata support for adding items).

```lua
--- @param item - requires an item valid name from your server items.
--- @param quantity - requires an integer value (added amount).
--- @param label - requires a string (this is mostly for rsg, set it to blank "")
xPlayer.addItem(item, quantity, label)
```

17. Get an item quantity.

```lua
--- @param item - requires an item valid name from your server items.
local quantity = xPlayer.getItemCount(item)
```

18. Get an item weight.

```lua
--- @param item - requires an item valid name from your server items.
local weight = xPlayer.getItemWeight(item)
```

19. Check if player can carry a specific item quantity.

```lua
--- @param item - requires an item valid name from your server items.
--- @param quantity - requires an integer value.
local canCarryItem = xPlayer.canCarryItem(item, quantity)
```

20. Check if player can carry a specific item quantity.

```lua
--- @param item - requires an item valid name from your server items.
--- @param quantity - requires an integer value (added amount).
--- @param label - requires a string (this is mostly for rsg, set it to blank "")
xPlayer.removeItem(item, quantity, label)
```

21. Add player inventory weapon (cannot modify or create custom metadata).

```lua
--- @param weapon - requires a valid weapon name from your server weapons.
xPlayer.addWeapon(weapon)
```

22. Check if player can carry a specific weapon quantity.

```lua
--- @param weapon - requires a valid weapon name from your server weapons.
--- @param quantity - requires an integer value.
local canCarryWeapons = xPlayer.canCarryWeapons(weapon, quantity)
```

23. Get player discord roles.

```lua
--- @param discordRoles - returns a table form.
local discordRoles = xPlayer.getDiscordRoles()
```

24. Get player connection status in case the player 's ping is very high, got disconnected in purpose or not.

```lua
--- @param hasLostConnection - returns a boolean.
local hasLostConnection = xPlayer.hasLostConnection()
```
