# Server Exports

Here, you'll discover all the handy exports for this asset. Please take the time to read through each step and example carefully to grasp how they function. We advise against using these exports if you're not an experienced developer.

***

## open

This export opens the MDT interface for a specific player.

```lua
exports['redutzu-mdt']:open(source)
```

Here's how you can utilize this export:

```lua
RegisterCommand('open_mdt', function(source)
    exports['redutzu-mdt']:open(source)
end, false)
```

***

## isAllowed

This export verifies if a player has the job necessary to open the MDT.

```lua
exports['redutzu-mdt']:isAllowed(source)
```

Here's how you can utilize this export:

{% code overflow="wrap" %}

```lua
RegisterCommand('example', function(source)
    local allowed = exports['redutzu-mdt']:isAllowed(source)

    if allowed then
        -- Do something if the player is allowed to open the MDT
    end
end, false)
```

{% endcode %}

***

## isJobWhitelisted

This export checks if at least one job is whitelisted.

```lua
exports['redutzu-mdt']:isJobWhitelisted(jobs) -- table or string
```

Here's how you can utilize this export:

```lua
RegisterNetEvent('dispatchEvent', function(data)
    local isWhitelisted = exports['redutzu-mdt']:isJobWhitelisted(data.jobs)

    if isWhitelisted then
        -- data.jobs includes one of the whitelisted jobs from Config.WhitelistedJobs
    end
end)
```

***

## hasPermission

This export verifies if a player has a specific permission.

```lua
exports['redutzu-mdt']:hasPermission(source, permission)
```

Here's how you can utilize this export:

```lua
RegisterCommand('pin_announcement', function(source)
    local hasPerm = exports['redutzu-mdt']:hasPermission(source, 'announcements.pin')
    
    if hasPerm then
        print('The player can pin announcements')    
    end
end, false)
```

***

## GetOfficerCallsign

This export retrieves the callsign of a player.

```lua
exports['redutzu-mdt']:GetOfficerCallsign(source)
```

Here's how you can utilize this export:

```lua
RegisterCommand('callsign', function(source)
    local callsign = exports['redutzu-mdt']:GetOfficerCallsign(source)
    
    if callsign then
        print('Callsign: ' .. callsign)    
    else
        print('No callsign')
    end
end, false)
```

***

## SetOfficerCallsign

This export modifies the callsign of a player.

```lua
exports['redutzu-mdt']:SetOfficerCallsign(source, callsign)
```

Here's how you can utilize this export:

```lua
RegisterCommand('change_callsign', function(source)
    exports['redutzu-mdt']:SetOfficerCallsign(source, 'ABC123')
end, false)
```

***

## GetOfficerStatus

This export retrieves the status of a player.

```lua
exports['redutzu-mdt']:GetOfficerStatus(source)
```

Here's how you can utilize this export:

```lua
RegisterCommand('status', function(source)
    local status = exports['redutzu-mdt']:GetOfficerStatus(source) -- 0, 1, 2, 3
    -- if you are using this code inside the MDT you can do:
    local statusName = Config.Statuses[status]?.label
    print('Current status: ' .. statusName )
end, false)
```

***

## SetOfficerStatus

This export updates the status of a player.

```lua
exports['redutzu-mdt']:SetOfficerStatus(source, status) -- status: keyof Config.Statuses
```

Here's how you can utilize this export:

```lua
RegisterCommand('change_status', function(source, args)
    local status = args[1] -- must be 0, 1, 2 or 3
    exports['redutzu-mdt']:SetOfficerStatus(source, status)
end, false)
```

***

## IsDuty

This export indicates whether the player is on duty or not.

```lua
exports['redutzu-mdt']:IsDuty(source)
```

Here's how you can utilize this export:

```lua
RegisterCommand('duty', function(source)
    local isDuty = exports['redutzu-mdt']:IsDuty(source)
    print('Player is ' .. isDuty and 'on duty' or 'off duty')
end, false)
```

***

## SetDuty

This export modifies the duty state of a player.

```lua
exports['redutzu-mdt']:SetDuty(source, state)
```

Here's how you can utilize this export:

```lua
RegisterCommand('toggleDuty', function(source)
    local isDuty = exports['redutzu-mdt']:IsDuty(source)
    exports['redutzu-mdt']:SetDuty(source, not isDuty)
end, false)
```
