---
description: Functions - Serverside
---

# Server

## MSK.Register

Register Server Callback _(_[_MSK.Trigger_](../client#msk.trigger)_)_

```lua
MSK.Register("Callback_Name", function(source, arg1, arg2, ...)
    return ...
end)

-- Example
MSK.Register("msk_testing:serverCallback:1", function(source, a, b, c)
    print(source, a, b, c)
    return a, b, c
end)

MSK.Register("msk_testing:serverCallback:2", function(source, cb, a, b, c)
    print(source, a, b, c)
    cb(a, b, c)
    print('Have fun!')
end)

-- As an Export:
exports.msk_core:Register("msk_testing:serverCallback:1", function(source, a, b, c)
    print(source, a, b, c)
    return a, b, c
end)
```

## MSK.Trigger

Trigger Client Callback _(_[_MSK.Register_](../client#msk.registerclientcallback)_)_

```lua
local data = MSK.Trigger("Callback_Name", source, arg1, arg2, ...)

-- Example
local a, b, c = MSK.Trigger("msk_testing:clientCallback", source, '123', '456', '789')
print(a, b, c)

-- As an Export:
local a, b, c = exports.msk_core:Trigger("msk_testing:clientCallback", source, '123', '456', '789')
```

## MSK.AddWebhook

Discord Webhook

<mark style="color:red;">**Parameters**</mark>\
**webhook** - `string` - The Discord Webhook Link\
**color** - `string` - Color for the Embed Message\
**botName** - `string` - The name of the bot\
**botAvatar** - `string` - Bot Avatar Link\
**title** - `string` - The Embed Message Title\
**description** - `string` - the Embed Message\
**fields** - `table` - Fields\
**footer** - `table <text, link>` - Embed Message Footer\
**time** - `string` - Time in the footer

If you don't want to use f.e. `footer` then set `footer = false` to deactivate the `footer`.

```lua
MSK.AddWebhook(webhook, botColor, botName, botAvatar, title, description, fields, footer, time)

-- Example
webhook = "https://discordapp.com/api/webhooks/101088",
botColor = "6205745", -- https://www.mathsisfun.com/hexadecimal-decimal-colors.html
botName = "MSK Scripts",
botAvatar = "https://i.imgur.com/PizJGsh.png",
title = "MSK Scripts - Webhook Script",
description = "Test Beschreibung",
fields = {
    {name = "Title", value = 'Description', inline = true},
    {name = "Title", value = 'Description', inline = true},
},
footer = {
    text = "© MSK Scripts", 
    link = "https://i.imgur.com/PizJGsh.png"
},
time = "%d/%m/%Y %H:%M:%S" -- format: "day/month/year hour:minute:second"

-- As an Export:
exports.msk_core:AddWebhook(webhook, botColor, botName, botAvatar, title, description, fields, footer, time)
```

## MSK.Notification

Show a Notification.\
You can use farbcodes like: `~g~`

<details>

<summary>Preview</summary>

<img src="https://1100044979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IG4qpnsvwJ4tB5edczg%2Fuploads%2FZUIMJwos6UMuLpnf88Q3%2FScreenshot_283.png?alt=media&#x26;token=7aa7ddec-88e7-4afb-becf-96e84ec62d6f" alt="" data-size="original">

</details>

<mark style="color:red;">**Parameters**</mark>\
**source** - `string/number` - The Player Server ID\
**title** - `string` - Title\
**message** - `string` - Message Text\
**info** - `string` - Optional - Default: general\
**time** - `number <miliseconds>` - Optional - Default: 5000

```lua
MSK.Notification(source, title, message, info, duration)

-- Example
MSK.Notification(source, 'Title', 'This is a Notification', 'general', 5000)

-- As an Export:
exports.msk_core:Notification(source, title, message, info, duration)
```

## MSK.AdvancedNotification

Shows a Picture Notification

<mark style="color:red;">**Parameters**</mark>\
**source** - `string/number` - The Player Server ID\
**text** - `string` - Text\
**title** - `string` - Title\
**subtitle** - `string` - Subtitle\
**icon** - `string` - Optional - Default: CHAR\_HUMANDEFAULT\
**flash** - `boolean` - Optional - Default: true\
**icontype** - `number` - Optional - Default: 1

```lua
-- flash and iconType are optional
MSK.AdvancedNotification(source, text, title, subtitle, icon, flash, icontype)

-- Example
MSK.AdvancedNotification(source, 'This is a Notification', 'Title', 'Subtitle', 'CHAR_HUMANDEFAULT', true, 1)

-- As an Export:
exports.msk_core:AdvancedNotification(source, text, title, subtitle, icon, flash, icontype)
```

## MSK.HasItem

Checks if you have the item in your inventory _(only for ESX or QBCore)_

<mark style="color:red;">**Parameters**</mark>\
**playerId** - `number` - The ServerId of the player\
**item** - `string` - The item name

<mark style="color:green;">**Returns**</mark>\
**hasItem** - `table <name, label, count>` - If the player has the item

```lua
local hasItem = MSK.HasItem(playerId, item)

-- Example
local hasItem = MSK.HasItem(playerId, 'bread')
print(hasItem.name, hasItem.label, hasItem.count)

-- As an Export:
local hasItem = exports.msk_core:HasItem(playerId, item)
```

## MSK.GetPlayer

Get the Player from PlayerId, Identifier, CitizenId or Phone. This works for ESX and QBCore.

<mark style="color:red;">**Parameters**</mark>\
**playerData** - `table <source, identifier, citizenid, phone>` - Player Data

<mark style="color:green;">**Returns**</mark>\
**Player** - `table` - The PlayerData

```lua
local Player = MSK.GetPlayer({source = playerId})
local Player = MSK.GetPlayer({identifier = playerIdentifier})
local Player = MSK.GetPlayer({citizenid = playerCitizenId})
local Player = MSK.GetPlayer({phone = 123456789}) -- Only QBCore

-- As an Export:
local Player = exports.msk_core:GetPlayer(playerData)
```

## MSK.GetPlayers

Get all the Players on the server.

<mark style="color:red;">**Parameters**</mark>\
**key** - `string` - Optional\
**value** - `string` - Optional

<mark style="color:green;">**Returns**</mark>\
**Players** - `table <key, Player>` - The PlayerData

```lua
local Players = MSK.GetPlayers() -- returns all players on the server
local Players = MSK.GetPlayers('job', 'police') -- returns only players with that specified job
local Players = MSK.GetPlayers('gang', 'bloods') -- returns only players with that specified gang *(Only QBCore)*
local Players = MSK.GetPlayers('group', 'admin') -- returns only player that have the group/permission 'admin'

-- As an Export:
local Players = exports.msk_core:GetPlayers(key, value)
```

## MSK.Cron.Create

Create a Cronjob

<mark style="color:red;">**Parameters**</mark>\
**date** - `table <w, d, h, m, atD, atH, atM>` - The datetime when the cron will be executed\
**data** - `any` - You can set you own data to use it later when executing

<mark style="color:green;">**Returns**</mark>\
**uniqueId** - `number` - UniqueId of the Cronjob\
**data** - `any` - Your data from parameters\
**date** - `table <d, h, m>` - The current Datetime

```lua
-- Will be executed every minute
MSK.Cron.Create({m = 1}, 'Cronjob executed at', function(uniqueId, data, date)
    print(data) -- Output: 'Cronjob executed at'
    print('Day: ' .. date.d, 'Hour: ' .. date.h, 'Minute: ' .. date.m)
end)

-- Will be executed every hour
MSK.Cron.Create({h = 1}, 'Cronjob executed at', function(uniqueId, data, date)
    print(data) -- Output: 'Cronjob executed at'
    print('Day: ' .. date.d, 'Hour: ' .. date.h, 'Minute: ' .. date.m)
end)

-- Will be executed every day
MSK.Cron.Create({d = 1}, 'Cronjob executed at', function(uniqueId, data, date)
    print(data) -- Output: 'Cronjob executed at'
    print('Day: ' .. date.d, 'Hour: ' .. date.h, 'Minute: ' .. date.m)
end)

-- Will be executed every day at 18:30
MSK.Cron.Create({atH = 18, atM = 30}, 'Cronjob executed at', function(uniqueId, data, date)
    print(data) -- Output: 'Cronjob executed at'
    print('Day: ' .. date.d, 'Hour: ' .. date.h, 'Minute: ' .. date.m)
end)

-- Will be executed every monday at 18:30
MSK.Cron.Create({atD = 1, atH = 18, atM = 30}, 'Cronjob executed at', function(uniqueId, data, date)
    print(data) -- Output: 'Cronjob executed at'
    print('Day: ' .. date.d, 'Hour: ' .. date.h, 'Minute: ' .. date.m)
end)

-- As an Export:
exports.msk_core:CreateCron(date, data, cb)
```

## MSK.Cron.Delete

Deletes a specific Cronjob

<mark style="color:red;">**Parameters**</mark>\
**uniqueId** - `number` - The UniqueId of the Cronjob

<mark style="color:green;">**Returns**</mark>\
**success** - `boolean <true/false>` - If the Cronjob Id was found and deleted.

```lua
local success = MSK.Cron.Delete(uniqueId)

-- As an Export:
exports.msk_core:DeleteCron(uniqueId)
```

## MSK.RegisterItem

This function registeres an item dependet on which framework you use.

```lua
MSK.RegisterItem(item, callback)

-- Example: ESX
MSK.RegisterItem('bread', function(playerId)
    -- Do something here
end)

-- Example: QBCore
MSK.RegisterItem('bread', function(playerId, item)
    -- Do something here
end)
```
