# API

**Integrate Tattoos with your system**

{% hint style="danger" %}
All events are **SERVER SIDE**!
{% endhint %}

### Explanation

* **playerId**\* = player server id
* **tattooName**\* = name of the tattoo in tattoo list (e.g. "*TAT\_AR\_001*")
* **tattooIdentifier**\* = combination of male & female hash (e.g "mpHeist3\_Tat\_003\_M-mpHeist3\_Tat\_003\_F")
* **expiration** = expiration in real life days, if you want the tattoo to disappear, like a henna tattoo
* **opacity** = tattoo opacity (1-5), default is 1
* **onlyPreview** = open the shop as a preview shop (only browsing tattoos), `true/false`
* **part** - body part to open the menu for - `head, body, left_arm, right_arm, left_leg, right_leg`, can be set as `nil` to open whole menu
* **cb**\* = callback function to handle response from the called event

*`*` required*

## Server Events

### Get player tattoos by identifier

Returns a table of player's tattoos by their identifier.

* The identifier is the one you use in rcore\_tattoos database table
* The cb (callback) parameter is a function that will be called with the result of the query.
  * use the callback to handle the result (see example)
* This event is mainly used for integrations. You can pass the player tattoos to the `setPedTattoos` client event to apply tattoos to ped in multichar for example.

```lua
TriggerEvent('rcore_tattoos:getPlayerTattoosByIdentifier', identifier, cb)
```

Example:

```lua
TriggerEvent('rcore_tattoos:getPlayerTattoosByIdentifier', 'license:1234567890abcdef', function(tattoos)
    -- do something with the tattoos
end)
```

### Add player tattoo

Adds a tattoo to player's body without deducting their money and passes `true/false` to callback depending on success.

```lua
TriggerEvent('rcore_tattoos:addPlayerTattoo', playerId, tattooName, tattooIdentifier, expiration, opacity, cb)
```

### Remove player tattoo

Removes a tattoo on player's body and passes `true/false` to callback depending on success.

```lua
TriggerEvent('rcore_tattoos:removePlayerTattoo', playerId, tattooIdentifier, cb)
```

### Buy tattoo

Same as adding a tattoo, but this will go through the buying process (removing player money etc.) and passes `true/false` to callback depending on success.

```lua
TriggerEven-t('rcore_tattoos:buyTattoo', playerId, tattooName, tattooIdentifier, expiration, opacity, cb)
```

### Get players tattoos

Returns a table of player's tattoos.

```lua
TriggerEvent('rcore_tattoos:getPlayerTattoos', playerId, cb)
```

### Get tattoo price

Returns a price of the given tattoo as a number.

```lua
TriggerEvent('rcore_tattoos:getTattooPriceByName', tattooName, cb)

TriggerEvent('rcore_tattoos:getTattooPriceByIdentifier', tattooIdentifier, cb)
```

### Open tattoo menu from anywhere

Opens the tattoo shop UI for a player

Also available for client! More info in client section below.

```lua
TriggerEvent('rcore_tattoos:openTattooMenuForPlayer', playerId, onlyPreview, part, cb)
```

### Get tattoo collection by name

Returns collection of the tattoo from given name

* **tattooName** - name of the tattoo (e.g. `TAT_AR_001`)

```lua
TriggerEvent(triggerName('getTattooCollectionByName'), tattooName, cb)
-- returns > mpchristmas2017_overlays
```

### Get tattoo name hashes by name

Returns name hashes of the tattoo from given name

* **tattooName** - name of the tattoo (e.g. `TAT_AR_001`)

```lua
TriggerEvent(triggerName('getTattooNameHashByName'), tattooName, cb)
-- returns > {
--     ["hashMale"] = MP_Christmas2017_Tattoo_007_M,
--     ["hashFemale"] = MP_Christmas2017_Tattoo_007_F,
-- }
```

## Callback

Here you can see an example of an event call with a callback function

```lua
TriggerEvent('rcore_tattoos:getTattooPriceByName', 'TAT_AR_001', function(price)
    print('The tattoo price is $' .. price)
end)
```

**Console output:**

```
The tattoo price is $300
```

## Client events

### Apply tattoos to ped

This event will apply tattoos to the ped of the player.

* **ped** - ped to apply tattoos to
* **tattoos** - table of tattoos to apply (must be in format returned by server event `getPlayerTattoosByIdentifier`)
* **disableClearCurrentTattoos** - (optional) if set to `true`, it will not clear current tattoos on the ped before applying new ones. Default is `false`.

```lua
TriggerEvent('rcore_tattoos:setPedTattoos', ped, tattoos, disableClearCurrentTattoos)
```

### Apply player tattoos

This event will reset & apply tattoos, can be useful when other script reset player tattoos

From server

```lua
TriggerClientEvent('rcore_tattoos:applyOwnedTattoos', playerId)
```

From client

```lua
TriggerEvent('rcore_tattoos:applyOwnedTattoos')
```

You can also add extra parameter so tattoos will not clear all player decoration and only add new tattoos.

```lua
local withoutClearingTattoos = true
TriggerClientEvent('rcore_tattoos:applyOwnedTattoos', playerId, withoutClearingTattoos)
```

From client

```lua
local withoutClearingTattoos = true
TriggerEvent('rcore_tattoos:applyOwnedTattoos', withoutClearingTattoos)
```

### Open tattoo menu from anywhere

Parameters are the same as in the server event above in server section!

To simply open tattoo menu in default form for client, call the event without any parameters.

```lua
TriggerServerEvent('rcore_tattoos:openTattooMenuForPlayer')
```

If you want to change parameters, but still open for current client you are calling it from, set playerId as `nil`.

```lua
-- just an example, adjust parameters to your need :)
local onlyPreview = true
TriggerServerEvent('rcore_tattoos:openTattooMenuForPlayer', nil, onlyPreview)
```

### Additional call after tattoo reset

If you for any reason need to do something from your other scripts after our script resets all ped decorations (tattoos, hair fades..), take a look at `rcore_tattoos/client/api/helper.lua` at the function `resetPedDecorationsExtra`

If you do not understand what this means, you can simply ignore it.

This function can be used for example to reapply your hair fades from another script that our script keeps deleting when it resets tattoos. If this happens to you, you can put some code inside this function and it will get executed every time the tattoos are reset from our script.

### Business bossmenu marker reload

If you need to reload bossmenu markers manually, you can use this event call from client side

```lua
TriggerEvent('rcore_tattoos:reloadBusinessMarkers')
```

This will do the whole process of checking player job, if they are boss of certain business and whether to render the business bossmenu marker.

You can also use `Config.JobReloadDelay` if you need to do it automatically after certain seconds when the script loads. More info in [Config](https://documentation.rcore.cz/paid-resources/rcore_tattoos/config) section.
