Night Shifts - Mobile Data Terminal for FiveM

Installation and integration guide for Night Shifts MDT (v1) on FiveM.


📋 Table of Contents

  1. 🛒 Purchase Information
  2. ⚠️ Important Pre-Installation Notes
  3. 🔧 System Requirements & Compatibility
  4. 📦 Installation Process
  5. ⚙️ Configuration Setup
  6. 🎮 How It Works
  7. 🔗 Integration & Compatibility
  8. 📊 Exports
    1. GetUserShiftData(targetServerId)
    2. GetPostalForPlayer(source)
    3. GetCivilianIntegrationSnapshot(civId, callback)
    4. GetLicensesByCivilianId(civId, callback)
    5. GetAllFlagsMarkersByCivilianId(civId [, callback])
    6. GetPoliceRecordsByCivilianId(civId [, callback])
    7. GetActiveWarrants(limitOrOpts, callback)
    8. Board list getters (flags, vehicle BOLOs, ANPR)
    9. LookupVehicleByPlate(plate [, callback]) and GetCivilianByPlate(plate [, callback])
    10. GetActiveCalls() / GetCallById(callId)
    11. Server events
    12. GetDepartments()
    13. GetRanksByDepartmentId(departmentId)
    14. GetSubDepartmentsByDepartmentId(departmentId)
    15. GetSetting(key)
    16. GetAllSettings()
    17. GetCurrencySymbol()
    18. GetCurrentLanguage()
    19. GetAvailableLanguages()
    20. GetActiveShiftByServerId(serverId)
    21. GetCurrentShiftDurationByServerId(serverId)
    22. StartShiftByServerId(serverId, departmentId, subDepartmentId, rankId, callsign)
    23. EndShiftByServerId(serverId [, callback])
    24. UpdateShiftStatusByServerId(serverId, statusCode [, callback])
    25. UpdateShiftStatusByBindingByServerId(serverId, binding [, callback])
    26. UpdateCallsignByServerId(serverId, newCallsign)
    27. ForwardCallToMDT(callData [, callback])
    28. IsMenuOpen()
    29. IsOnPoliceShift() · IsOnAmbulanceShift() · IsOnFireShift() · IsOnTowShift() · IsOnCouncilShift()
    30. GetPlayerCallsign()
    31. OpenMenu() · CloseMenu() · ToggleMenu()
    32. ForwardCallToMDT(callData)
  9. 🚑 Medical Records (Ambulance Panel)
    1. Tiered permissions
    2. 🩺 Configuring medical types (admin)
    3. Database
  10. 🛠️ Troubleshooting
  11. 💡 Best Practices
  12. 🆘 Support

🛒 Purchase Information

Get Night Shifts MDT:

Purchase on Nights Software Store


⚠️ Important Pre-Installation Notes

Critical Installation Order: Always follow this exact sequence to avoid parsing errors in the F8 console:

  1. Download ZIP Package from CFX Portal
  2. Unpack in a folder on your local machine
  3. Set File Transfer Protocol (FTP) type to binary
  4. Drag files from local machine to server resources folder
  5. Add to server.cfg (ensure script)
  6. Boot up the server

Support Policy: Follow this guide step by step. If you’re stuck, ask for support in our Discord and provide the specific step name. Do not skip steps.

Database Requirement: Night Shifts MDT requires a MySQL database and oxmysql resource to function properly.

Emergency Response Simulator Compatible: It is possible to search NPCs and their vehicles in the MDT when they have been interacted with via the Emergency Response Simulator.


🔧 System Requirements & Compatibility

OneSync Compatibility

  • ✅ OneSync Legacy: Fully tested and compatible
  • ✅ OneSync Infinity: Fully tested and compatible

Framework Compatibility

  • ✅ Standalone: If no supported framework resource is running, the MDT runs in standalone mode: no automatic civilian generation from characters (players use council registration / staff workflows as you configure).
  • ✅ Auto civilian generation (framework bridge): When a supported framework is detected and started before or with the MDT, the resource syncs each loaded character into nsmdt_civilians (create or update by framework id). Supported stacks (detection order on the server):

    Framework Resource / API Character id used for sync
    ESX es_extended identifier
    QBox qbx_core (GetPlayer) citizenid
    QBCore qb-core citizenid

    On first sync, a council-style personal id (e.g. CIV-…) can be issued; identity documents may be auto-generated when your document types and council rules allow (see server logs for [MDT Framework]). Existing civilians are updated on subsequent loads (name, job, phone, etc., per bridge data).

  • ✅ Framework fines: Optional bank/cash deduction for council fines when a framework player pays—configure Config.FrameworkFineAccount in config.lua (ESX / QBCore / QBox).
  • ✅ Custom banking (standalone): If you run a standalone server with your own banking resource (or want to override one specific operation on a framework server), the banking bridge exposes a BankingBridge.Custom slot you can plug into. Council fines, balance reads and any future money-moving feature will then go through your code instead of (or in addition to) the framework path. See Custom Banking Bridge below.

Run es_extended, qbx_core, or qb-core on the same server as Night Shifts MDT if you want automatic civilian sync. Only one framework path is selected (ESX → QBox → QBCore in that order if multiple were present).

Dependencies

  • ✅ MySQL Database - Required for data storage
  • ✅ oxmysql - Required database API

Note: Database setup (MySQL + oxmysql) is required regardless of framework. Permissions and departments are configured inside the MDT (and initial super-admins in config.lua). Optional integrations include: auto civilian sync on supported frameworks, fine payments through the framework account, and Discord-driven department assignment via the separate Night Discord API resource — see Discord integration below.


📦 Installation Process

Step 1: Database Setup (Required)

We assume you have a database for your FiveM server. If you do not have one, contact your hosting providers’ documentation on how to get and build one. This is a dependency for Night Shifts MDT to work.

  1. Set up your database via your hosting provider
  2. Connect to your database using credentials in an SQL connection string
  3. Add to server.cfg above the ensure/start of resources:
set mysql_connection_string "user=Your_Database_Username;password=Your_Database_Password;host=Your_Database_Host;port=3306;database=Your_Database_Name;charset=utf8mb4_general_ci"

Localhost Example:

set mysql_connection_string "user=root;password=;host=localhost;port=3306;database=Your_Database_Name;charset=utf8mb4_general_ci"
  1. Automatic Table Installation - When you boot up the server, the code will run queries to install required tables

Manual Installation: The files include a datatables.sql file if you prefer to manually install the tables.

Step 2: Install oxmysql (Required)

If you don’t have oxmysql installed, download it from: Download oxmysql

  1. Place oxmysql into your resources folder
  2. Add to server.cfg - Ensure it starts before Night Shifts MDT:
ensure oxmysql

Documentation: For oxmysql questions, visit oxmysql documentation

Step 3: Test Database Connection

Start your server and check the console for oxmysql connection messages. You should see:

[script:oxmysql] Database server connection established!

Step 4: Postal codes (optional — auto-detect)

Night Shifts MDT does not require a specific postal resource name. It auto-detects which postal / map data is available on your server and uses it for player and world lookups (dispatch, addresses, etc.).

How it works

  1. HUD-first (player position) — If a supported HUD exposes postal for the local player, that is preferred: rhud (get_postal), then SimpleHUD / ModernHUD (getPostal), in that order.
  2. World coordinates — For map pins and coordinates, the MDT tries rhud world APIs first, then hinted postal resources in order: mnr_postals, nearest-postal.
  3. Multiple formats — The same hints are probed for several backends: JSON lists referenced by the resource postal_file manifest metadata, MNR-style Lua data (config + data files), export-based nearest-postal (getNearestPostal, getPostalAtCoords, etc.), and similar. You can ship different postal file packs (or forks of nearest-postal / MNR) as long as the resource exposes one of these patterns; the MDT picks the first working match at runtime.
  4. Dependencies of postal resources — Some MNR builds need ox_lib running. Install what your chosen postal resource documents.

You typically ensure your postal / map stack before Night Shifts MDT in server.cfg, for example:

ensure ox_lib
ensure nearest-postal
# or: ensure mnr_postals
# plus any minimap / postal overlay resource you use

No extra bridge resource — Integration is built into the MDT client; you do not need a separate “MDT ↔ postal” bridge. If nothing matches, postal-dependent UI may show blanks until a compatible resource is added.

Step 5: Install Night Shifts MDT

  1. Download from CFX Portal Assets
  2. Extract and transfer using binary FTP mode
  3. Place the resource folder into your resources directory — keep the original folder name (night_shifts_mdt) as shipped; do not rename it.
  4. Add to server.cfg:
ensure night_shifts_mdt
  1. Verify startup — Check console for oxmysql and night_shifts_mdt starting without errors

Using ERS? In server.cfg, ensure night_shifts_mdt before ensure night_ers — ERS calls MDT exports at startup, so the MDT must already be running. See Emergency Response Simulator Integration below for config and behaviour.

First start & database setup: When the resource starts, it runs a sequence of MySQL queries to create or update the required tables, columns, and indexes automatically. That work can take a short time (often a few seconds; longer on a slow database or a very first install). Let the server console finish this phase before deciding something failed—brief delays here are normal.


⚙️ Configuration Setup

Required Tools

Visual Studio Code: We strongly recommend downloading VS Code for editing Lua files.

Configuration Files

Paths below use night_shifts_mdt as the resource folder name—use the same name you deploy and ensure in server.cfg (some installs rename the folder; paths are always relative to that folder).

Path Purpose
night_shifts_mdt/config/config.lua Main config — tablet prop/animations, ERS link (Enable_ERS), framework fine account, hotkeys, civilian emergency call, Show ID, initial super-admins, and other core toggles.
night_shifts_mdt/config/config_anpr.lua ANPR — static cameras, patrol HUD scan settings, officer watchlist expiry, patrol-registry-only mode, and NpcRegistryScopedToModel (NPC auto-flags scoped to plate + vehicle model)
night_shifts_mdt/config/config_npc_pool.lua ERS NPC pool — fictive NPC identities and vehicle-record probabilities for Emergency Response Simulator / PNC integration
night_shifts_mdt/config/translations/<locale>.lua Languages — one file per locale (e.g. en.lua, de.lua, fr.lua, …)

Optional files some servers customize:

Path Purpose
night_shifts_mdt/client/c_functions.lua Client helpers (e.g. postal auto-detect, shared utilities)
night_shifts_mdt/server/s_functions.lua Server helpers, Discord webhook implementation, and the optional Custom Banking Bridge preset

Configuration Process

  1. Open VS Code and navigate to the config files
  2. Read thoroughly - each line has explanatory comments
  3. Configure in order - work from top to bottom
  4. Watch for notes - important warnings are clearly marked
  5. Test frequently - use F8 console and server console for error checking

Time Investment: Plan adequate time for configuration. Each variable is named descriptively to help you understand its purpose.


🎮 How It Works

Civilian-facing

  • Emergency call (e.g. F3) — Quick civilian emergency call into the dispatch ecosystem (subject to cooldowns and “on shift” rules in config)
  • Council self-service — Manage your civilian profile: documents, licenses, vehicles, properties, and businesses from the tablet
  • Show ID — Present government ID to a nearby player for RP identity checks

Emergency services (in the tablet)

  • Shift & status — Clock in/out, department selection, status codes, panic (command or MDT) as configured
  • Dispatch — Call board, units, notes, and map-backed situational awareness; quick-respond and communications as set up on your server
  • PNC — Full lookup stack: people, plates, warrants, case files, flags, ANPR, and penal code reference. Linked Reports on civilian/vehicle profiles show approved operation forms only when the form template is marked PNC-visible in Admin → Form Builder (pnc.reports.view / pnc.reports.view_all_department).
  • Operations & forms — Department-specific configurable forms and workflows; applications and internal operations tied to the same form system. Operation forms can link civilians/vehicles; visibility on PNC is opt-in per template (defaults: internal). Applications and medical department forms stay department-internal.
  • Management — Roster, fleet, bulletins, certifications, and submission review for leadership roles

ANPR & NPC traffic

Patrol ANPR (in-vehicle HUD and static cameras) and PNC → ANPR (watchlist, hit log) work alongside the NPC pool when ERS integration is enabled. Three ideas help avoid confusion in roleplay:

Three separate layers

Layer What it means Typical lifetime
PNC vehicle record Owner, tax/MOT/insurance, stolen/BOLO on the vehicle file NPC rows: ~90 min per plate + model encounter (plateTTLMinutes in config_npc_pool.lua)
ANPR watchlist (registry) What triggers a red ANPR HIT on the patrol HUD Officer flags: plate-wide, ~10 days (RegistryExpiryDays). NPC auto-flags: plate + GTA model, same ~90 min as the NPC vehicle row
Hit log Audit of past detections Historical only — a past hit does not mean the plate is still flagged

ANPR HIT vs vehicle BOLO/stolen

  • ANPR HIT = plate is on the watchlist right now (officer added it, or NPC pool auto-flagged stolen/BOLO when the record was created).
  • Vehicle BOLO/stolen on a PNC lookup = flags on that specific vehicle record.
  • Those can differ: e.g. active watchlist hit but a clean vehicle file after plate recycle, or a historic hit in the log with no active watchlist entry.

NPC behaviour (GTA plate reuse)

  • Any plate format works. Ambient NPC vehicles get a full fictional record (owner, tax/MOT/insurance, stolen/BOLO) regardless of plate layout — custom plate-changer formats included. There is no “native plate pattern” list to configure anymore.
  • GTA reuses the same plate string on different cars. NPC vehicle stories and NPC auto-ANPR flags are keyed by plate + model hash, so a recycled plate on a different model is a separate story and does not inherit the previous car’s watchlist hit.
  • New story on driver change. If the same plate + model turns up driven by a different NPC, it is treated as a different car (sold/recycled): a fresh vehicle story is generated and the previous NPC row for that plate is replaced. Recurring peds keep their own identity across encounters.
  • Owners are recurring residents. When a vehicle’s registered owner differs from the driver, the MDT reuses an existing NPC resident as the owner instead of inventing a brand-new person every time, so the world feels populated by the same faces.
  • Officer watchlist entries you add in PNC/ANPR remain plate-wide by design and are overlays on the vehicle file — they no longer stop the NPC pool from generating a record.
  • Player-registered plates always win. A plate registered in MDT Vehicle Registration uses that record and clears any NPC rows for the plate; registering a plate afterwards removes its NPC entry.
  • Driver ≠ registered owner is normal (~25% by default via probOwnsVehicle in config_npc_pool.lua) — especially on ERS callouts and borrowed/rental-style NPC stories.

Tuning encounter rates

In config/config_npc_pool.lua (defaults shown):

  • probStolenVehicle — chance a new NPC vehicle record is stolen (stolen always includes BOLO on the vehicle file and ANPR auto-flag when resolved).
  • probBOLO — additional BOLO chance on non-stolen NPC vehicles.
  • plateTTLMinutes — how long NPC plate+model vehicle rows (and matching NPC ANPR auto-flags) stay active.

Patrol scan behaviour (cone dwell, equipped vehicle hashes, static cameras) is in config/config_anpr.lua. Set PatrolRegistryOnly = true there if you only want watchlist hits on the HUD with no NPC/PNC vehicle resolution for ambient traffic.

Permissions

Two layers work together: who can open admin tools vs what each job role may do in the MDT while on shift.

  • Admin permissions — A global admin level (0–3: regular user, moderator, admin, super admin) decides whether someone can use the admin panel at all, and which admin areas they get (users, departments, MDT settings, penal code editor, license/document/flag types, forms, system logs, emergency-wide actions, bug reports, and the admin-permissions editor for super admins). Moderators and up can have granular actions inside those modules (for example view vs edit on penal codes, or which settings tabs they may change). Levels are assigned when a super admin edits user management; initial super-admins can be seeded in config.lua for first-time setup.
  • Rank permissions — Separate from admin level: each rank inside a department has its own permission strings (for example PNC lookups, dispatch features, council administration). Super admins or department managers assign these when configuring ranks. Permissions can inherit from other ranks in the same department via rank hierarchy, so a sergeant can automatically include patrol allowances without duplicating every flag. The MDT resolves a player’s effective permissions when they clock in to a department (and refreshes when ranks or hierarchy change).

In practice: Admin level answers “May this person run the server / MDT configuration UI?” Rank permissions answer “Once clocked in as this job role, which operational menus and actions (dispatch, PNC, ANPR, …) are allowed?” A user can be a high rank in police without any admin level, and an admin can configure the server without needing a department rank.

Where department + rank assignments come from. A user’s rows in nsmdt_user_departments are tagged with an assignmentSource that records who put them there:

Source Set by Removable by
admin A super admin / admin assigns the user via User Management in the admin panel Admin only — never overwritten by automatic syncs
open_join The user joins a department configured as open join from the home page Admin, or the user leaves voluntarily
discord The optional Discord integration maps a Discord role the user holds to that (department, rank) Admin (manually), or removed automatically when the user loses the Discord role / the mapping is deleted / integration is disabled

Admin assignments take precedence: if an admin edits a row that started life as discord, it is promoted to admin and stays put across syncs.

Server owners & admins

  • First-run & roles — Initial super-admins and tiered admin levels (moderator / admin / super admin) in config; ongoing user management and permission matrices in-tablet
  • Reference data — Departments, ranks, penal codes, license/document/flag/certification types, and form builder without editing NUI source
  • Operations — System logs, emergency-wide actions, MDT-wide settings, and bug reports from the field

🔗 Integration & Compatibility

How Night Shifts MDT fits next to other resources. Required pieces are under System Requirements (OneSync, MySQL, oxmysql). Postal / HUD data for addresses and map context (optional): see Step 4: Postal codes — the MDT auto-detects supported resources on the client and does not use a separate postal bridge.

Frameworks (optional)

  • Standalone — MDT works with no ESX / QBCore / QBox; civilians are created through council flows and staff tools unless you add a framework.
  • ESX / QBox / QBCore — When es_extended, qbx_core, or qb-core is running, the framework bridge syncs characters into nsmdt_civilians and the banking bridge can charge council fines to the player’s bank or cash (Config.FrameworkFineAccount). Details and detection order: Framework Compatibility (earlier on this page).

Custom Banking Bridge

The MDT’s banking bridge (server/server_banking_bridge.lua) handles ESX, QBox and QBCore out of the box. For everything else — a standalone server with your own banking resource, a heavily modified framework, or a server that just wants to override one specific operation — you can register handlers on BankingBridge.Custom. Anywhere the MDT moves money (today: council fine payments) will then go through your code.

A ready-to-uncomment preset is provided at the bottom of server/s_functions.lua (which is escrow-ignored and ships open). That is the recommended place to register your handlers; the file is reloaded on every resource restart and survives MDT updates.

When the custom path runs (and when it doesn’t)

Selection happens per call, not globally — you can override only the operations you care about and let the framework keep handling the rest.

Situation What runs
BankingBridge.Custom.<Op> is registered as a function Your handler runs first. Its return value is what callers receive.
Your handler throws an error Bridge logs ^1[MDT Banking]^7 BankingBridge.Custom.<Op> threw: … and falls through to the framework path (or STANDALONE). MDT never crashes from a buggy handler.
BankingBridge.Custom.<Op> is nil / not a function Falls through to the framework path for that op (ESX → QBox → QBCore), or STANDALONE if no framework is detected.
BankingBridge.Custom is nil entirely Same as above — pure framework / STANDALONE behaviour, identical to MDT’s pre-custom default.
Standalone server, no custom registered GetPlayerMoney returns 0. AddMoney / RemoveMoney are no-ops returning true so caller flow (e.g. fine “paid”) is not blocked. The council fine UI skips the deduction call entirely in this case.
Standalone server, custom is registered Council fines and other money calls do invoke your handler. The bridge’s HasActiveBackend() reports true once any custom handler is present, which is what gates the fine deduction.

The custom check happens per operation. If you implement only AddMoney, calls to GetPlayerMoney / RemoveMoney will still hit the detected framework (or STANDALONE no-op). Implement all three for a fully self-contained custom backend.

Handler signatures

Handler Signature Return
GetPlayerMoney function(source, account) Number — current balance for that account. Return 0 if the player is unknown.
RemoveMoney function(source, amount, reason, account) Booleantrue on success; false on failure (e.g. insufficient funds). On false the council UI shows the localised “insufficient funds” toast.
AddMoney function(source, amount, reason, account) Booleantrue on success.

Parameters:

  • source — player server id (number).
  • amount — already validated > 0 by the bridge before your handler runs (number, integer once normalised).
  • reason — human-readable string the MDT supplies (e.g. "MDT Fine #42"). Forward to your banking transaction history.
  • account — one of 'cash', 'bank', 'crypto'. The MDT itself uses 'bank' for fines (configurable via Config.FrameworkFineAccount).

reason is also the second argument to ESX xPlayer.removeMoney / QBCore Player.Functions.RemoveMoney for parity. If your banking system has no concept of a transaction reason, you can ignore the parameter — the MDT does not inspect what you do with it.

Minimal example

In server/s_functions.lua, uncomment the preset block at the bottom and replace the exports['my_banking']:… calls with whatever your banking resource exposes:

Citizen.CreateThread(function()
    local waited = 0
    while BankingBridge == nil do
        Citizen.Wait(100)
        waited = waited + 100
        if waited >= 10000 then
            print('^1[Night Shifts MDT]^7 BankingBridge global never appeared — custom banking NOT registered.')
            return
        end
    end

    BankingBridge.Custom = {
        GetPlayerMoney = function(source, account)
            return exports['my_banking']:GetBalance(source, account) or 0
        end,
        RemoveMoney = function(source, amount, reason, account)
            return exports['my_banking']:Withdraw(source, amount, reason, account) == true
        end,
        AddMoney = function(source, amount, reason, account)
            return exports['my_banking']:Deposit(source, amount, reason, account) == true
        end,
    }
end)

The Citizen.CreateThread + polling wrapper is intentional — s_functions.lua loads before server_banking_bridge.lua, so the BankingBridge global does not exist yet at the top of this file. Polling (rather than a single Wait(0)) makes the registration robust against any boot-order shuffle and gives a clear console error if the bridge is somehow missing.

Do not call BankingBridge.Custom.<Op>(…) recursively from inside your own handler — that will infinite-loop. Always call your underlying banking resource’s exports directly.

What currently uses the bridge

Today the bridge is exercised by council fine payments (server/server_council.lua). Any future feature that moves money will go through the same three functions, so registering custom handlers now future-proofs your standalone setup.

Emergency Response Simulator (night_ers)

Optional integration for servers that run Emergency Response Simulator (night_ers).

  • MDT → ERS — With Config.Enable_ERS in the MDT, clock-in/out can call night_ers so ERS shift state stays aligned (set ManageShiftsByMDT in ERS where applicable so the MDT owns shift toggles).
  • PNC & world — ERS-driven NPCs and vehicles can appear in lookups, ANPR, and related flows according to your config_npc_pool.lua and ERS settings.
  • server.cfgensure night_shifts_mdt before ensure night_ers. ERS calls MDT exports (PNC lookups, ped interactions, call forwarding, …) at startup, so the MDT has to be running first. If you do not run ERS, omit it.

Requirements

Requirement Notes
oxmysql2.12.0 night_ers requires oxmysql v2.12.0 or newer. We recommend running the latest oxmysql release on any server using ERS.
night_shifts_mdt started before night_ers in server.cfg Boot order matters — night_ers calls MDT exports (PNC lookups, ped interactions, call forwarding, …) on its own startup, so the MDT must already be running. The MDT probes night_ers lazily at runtime, so it does not need ERS up first.
Config.Enable_ERS = true in the MDT Toggles the integration. With it off, the MDT ignores ERS entirely even if the resource is running.
ManageShiftsByMDT enabled on the ERS side (where applicable) Lets the MDT own clock-in/out so ERS shift state stays aligned with MDT shifts instead of fighting them.

Discord integration (night_discordapi)

Optional integration that lets the MDT grant department + rank automatically based on the Discord roles a player holds. Intended for servers that already manage their roster in Discord and don’t want to mirror every promotion by hand in the admin panel.

This is a separate capability from Discord webhooks below — webhooks post messages out of the MDT, this integration reads roles in to decide who has access to what.

What it does

  • Maps Discord roles → (department, rank). Optionally also a sub-department and an isPrimary flag. One Discord role can map to one (department, rank) pair; one user can have many mapped roles and gets all of the assignments.
  • Syncs automatically when a player connects, when the Discord role list changes server-side (5-minute background sweep), and on demand from buttons described below.
  • Removes access automatically when a Discord role is taken away, when its mapping is deleted in the admin panel, or when the master integration switch is turned off.
  • Never touches admin-assigned rows. If an admin assigns or edits a department row in User Management, that row is tagged admin and is never overwritten by a sync. See the table in Permissions for how the source tags interact.

Requirements

Requirement Notes
night_discordapi2.3.0 The MDT calls GetDiscordMemberRoleIds (added in 2.3) to read raw role IDs. Older builds will start, but mapping by role ID is unavailable and only legacy name-based matching works. Recommended: upgrade.
night_discordapi started before night_shifts_mdt in server.cfg Boot order matters — the MDT probes GetResourceState('night_discordapi') on connect.
Each player has linked their Discord account in the FiveM app Without a Discord identifier (GetPlayerIdentifierByType(src, 'discord')), the integration silently skips that player. The admin panel surfaces unlinked online players so you can ask them to fix it.
night_discordapi is configured with the bot token + guild(s) + role table described in its Discord API documentation The MDT only consumes data the API exposes; if the bot can’t see a guild or role, the MDT can’t map it.

Set it up

All of this is done inside the MDT admin panel — no config.lua changes needed.

  1. Install and configure night_discordapi as documented on its own page. Add ensure night_discordapi before ensure night_shifts_mdt in server.cfg. Restart the server.
  2. Open the MDT as a Super Admin, go to Admin Panel → Discord Integration.
  3. Toggle the master switch on. If night_discordapi isn’t started, the page will tell you so and the toggle stays disabled.
  4. (Optional) Restrict to specific guilds. By default the integration reads role data from every guild your bot knows about. If you want to scope it to one or two specific Discord servers, list their guild names (the friendly names defined in night_discordapi’s Discord_Guild_Names).
  5. Add role → rank mappings with the Add mapping button. The role picker lists every Discord role visible to the bot, grouped by guild; the department / rank pickers list everything you have configured in the MDT. Use the Bulk add dialog when seeding many ranks for one department in one go.

That’s it — the next time an affected player connects (or in the next 5-minute background sweep, whichever comes first), they’ll be assigned the matching department and rank and the home page will reflect it.

Map the role ID (the dropdown does this automatically when night_discordapi ≥ 2.3 is running). Discord role names can be renamed at any time and the mapping list will flag renamed or missing roles with badges so you can clean them up.

Refreshing roles

Trigger Who Cooldown Forces a fresh Discord fetch?
Player connects Automatic Yes (initial seed)
Player opens the MDT Automatic No (uses cached roles)
5-minute background sweep Automatic Yes
“Refresh roles” button on the home page Per-player 30 s Yes
“Resync all online” button in the admin panel Per-admin 30 s Yes (for every linked online player)

The two manual buttons exist so you don’t have to wait up to 5 minutes after a Discord-side change. They don’t conflict with the background sweep — night_discordapi collapses overlapping requests for the same player.

Disabling the integration

Flipping the master switch off does two things immediately:

  1. Stops all future Discord syncs (the home-page Refresh button hides itself for every online player).
  2. Bulk-deletes every department row tagged assignmentSource = 'discord' so any access that was granted via Discord is revoked at once. Admin and open-join rows are untouched.

This is intentional — leaving Discord-granted access in place after disabling the integration would mean players keep permissions you can no longer manage from Discord. If you want to keep specific people in their departments, re-add them via User Management before turning the integration off, and they’ll be tagged admin and protected.

Who can use the page

The Discord Integration admin page is gated by the new Discord Integration module in the Admin Permissions editor. Defaults:

Level Page access manage_settings manage_mappings resync
0 User · 1 Moderator
2 Admin · 3 Super Admin

Each action is editable per level by a Super Admin, so e.g. a Moderator can be granted resync alone (handy after a Discord-side restructure) without being able to alter mappings or flip the master switch.


Discord webhooks (optional)

Different mechanism to the Discord integration above — webhooks post messages out of the MDT to a Discord channel (dispatch alerts, admin audit), they do not read Discord roles or affect access. You can run either, both, or neither.

The implementation (reading URLs and posting embeds) lives in server/s_functions.lua; you do not paste webhook URLs into that file on a normal install.

URLs are read from server convars at runtime:

  • nsmdt_discord_webhook_dispatch — dispatch-related notifications
  • nsmdt_discord_webhook_admin — admin audit–style notifications

Set them in server.cfg (or any supported way you set FiveM convars), for example:

set nsmdt_discord_webhook_dispatch "https://discord.com/api/webhooks/…"
set nsmdt_discord_webhook_admin "https://discord.com/api/webhooks/…"

If a convar is empty or missing, the MDT skips posting for that channel (same behaviour as documented in the Lua comments above those convar names).

Calling the MDT from other resources

Other scripts can use exports['night_shifts_mdt'] (folder name must match). Use this page’s Exports section for signatures, rules, and examples. The same integration guide also ships in the resource as docs/EXPOSED_EXPORTS.md (the only docs file included in the production pack).

ERS + CAD / other scripts (summary for server owners)

If you run Emergency Response Simulator together with Night Shifts MDT, you usually do not need to change anything for in-game ID checks: ERS keeps showing the same licence lines on the NPC card; the values now come from the MDT when a civilian is linked.

Setup you should know about

  • server.cfg: keep ensure night_shifts_mdt before ensure night_ers, as in both guides.
  • Licence types: The five ERS licence types (driver, motorcycle, boat, pilot, commercial) use fixed internal ids so NPC pools and the ERS ped card stay consistent. In Admin → License Types they show a small lock icon; you can edit the display name for localization, but delete and changing prefix / behaviour / id are blocked. Other licence types (hunting, fishing, etc.) work as before.
  • PNC flag types (Important Notices): Preset types used with ERS show a small lock icon in Admin → Flag Types (same idea as ERS licence types). You can still edit labels and settings; deleting those preset types is blocked (a migration may re-add any missing presets on upgrade). Custom flag types behave as before in the MDT; on the NPC card, keep using pedData.FlagsOrMarkers like plain ERS — see ERS → Field ownership.
  • CAD or custom resources listening to ERS events: see ERS → Field ownership for which fields come from the MDT vs ERS. mdtCivilianId on the ped payload is the MDT civilian record number; mdtPersonalId is the public dossier id when present (e.g. CIV-…).

Licences on the ped card — With the MDT on, the License_* fields match what ERS has always used (including valid/invalid styling). With the MDT off, ERS still generates random licence results as before.

“Flags / markers” on the ped card — Same as ERS without the MDT: your scripts keep using pedData.FlagsOrMarkers. With the MDT on, that data comes from the civilian’s Important Notices instead of being rolled at random. See ERS — field ownership / NPC payload for the full pedData table.


📊 Exports

For developers only. Use this section if you are writing or integrating another FiveM resource (e.g. CAD, dispatch bridge) that must call the MDT from Lua. Normal install: set up server.cfg, configure the MDT in-game, and edit the Lua config files above—you can ignore Exports unless your team is adding custom code.

Support rule: Exports documented in this section (and in the resource file docs/EXPOSED_EXPORTS.md) are the supported integration API. The resource registers many other exports for internal / ERS / admin use — if it is not documented here, treat it as unsupported (may change without notice).

How this section is organised

Kind Meaning
Getter Read-only; returns data (or calls your callback with data).
Setter / mutator Writes or updates server-side state (DB and/or cache).
Action Performs a side effect (create call, relay event, open UI). Check return values and callbacks where documented.

Quick start

Use the colon call form: exports['night_shifts_mdt']:ExportName(...). Dot/bracket calls (exports.res.Name(...)) can drop the first argument on CitizenFX (e.g. serverId), so ByServerId exports look like “invalid server id” / off-shift.

local mdt = exports['night_shifts_mdt']

-- Optional: resource version string
local version = mdt:GetVersion()

-- Prefer callbacks for civilians / vehicles / flags / licenses / roster / hit log
-- (sync without a callback is warm-cache only and often empty)
mdt:GetVehiclesByCivilianId(civId, function(vehicles)
  print(#vehicles)
end)

-- First arg of *ByServerId = acting officer (source); targets go in data
mdt:CreateFlagByServerId(source, {
  civId = 42,
  flagType = 'other',
  description = 'Terminal note',
  severity = 'low',
}, function(ok, result)
  if not ok then return print(result) end
  print('flagId', result.flagId)
end)

Rules of thumb

  1. Callback = MySQL SSOT for person-file reads (civilians, vehicles, flags, criminal records, licenses, roster, ANPR hit log, plate lookup). Sync without a callback only sees warm cache. Callbacks from another resource are supported (CitizenFX funcref). Board / lookup reads do not require a connected player or open MDT session.
  2. …ByServerId first argument = the acting officer’s FiveM server id (source) — auth + audit. Warrant / flag / civilian / vehicle targets are always in data.
  3. Permission keys match Admin → ranks (e.g. pnc.flags, pnc.registration, pnc.anpr.manage). Use HasPermissionByServerId to hide UI before writes fail.

Server — integration exports

Getters

GetUserShiftData(targetServerId)
   
Parameters targetServerId (number) — FiveM player server id (source from events, or any valid id).
Returns Single table (not an array). Empty {} if the player cannot be resolved or has no session. Keys (values may be nil when not on shift or not yet pushed): serverId, rockstarLicense, userName, nickName, adminLevel, isOnShift, departmentId, subDepartmentId, rankId, callsign, statusCode, statusLabel, statusColor, shiftDuration (seconds), totalShiftTime, shiftTimeByDepartment (table), location, speed, heading, compassDirection, postal, distanceToNearestPostal, street, zone, modeOfTransport, sirens, plate. location is a plain { x, y, z } table when present (not a vector3).
Limitations Server-only. Location fields depend on the client having pushed location while on shift; they may be empty/nil shortly after clock-in.
local mdt = exports['night_shifts_mdt']
local data = mdt:GetUserShiftData(source)
if data.isOnShift then
    print(data.userName, data.callsign, data.statusCode or "")
    print("Location:", data.street or "—", data.postal or "")
end
GetPostalForPlayer(source)
   
Parameters source (number) — player server id. Invalid id returns the translated unknown postal string.
Returns String — postal / zone code for that player’s current ped position.
Limitations Server-only. Without a supported postal backend, you only get the unknown label.

Resolution order (same behaviour as Step 4: Postal codes):

  1. rhud — if started, exports.rhud:get_postal at the ped’s X/Y.
  2. SimpleHUD or ModernHUD — if started, getPostal(source) on that resource.
  3. Static postal data — nearest code from mnr_postals, nearest-postal, or JSON via postal_file metadata, using the ped’s coordinates.
local postal = exports['night_shifts_mdt']:GetPostalForPlayer(source)
GetCivilianIntegrationSnapshot(civId, callback)

When you need this: Only if you run custom server-side code (for example a CAD or bridge) that must load PNC licences, flags/markers, and police records for one civilian using their MDT nsmdt_civilians.id—often the same number as mdtCivilianId on an ERS ped after MDT merge. Standard installs and in-game play do not call this export.

   
Parameters civId (number) — nsmdt_civilians.id (e.g. pedData.mdtCivilianId from ERS after an MDT merge). callback (function) — callback(snapshot).
Returns Nothing synchronously. callback receives snapshot: civilianId, licenses (array, from MySQL — same shape as in-tablet PNC; overlaps summary fields on pedData.License_* but includes full rows), flagsMarkers (array — all cached rows for this civilian), policeRecords (array, from cache).
Limitations Server-only. Async. Invalid civId or non-function callback → ignored. flagsMarkers / policeRecords follow the MDT cache. Granular only: GetLicensesByCivilianId, GetAllFlagsMarkersByCivilianId, GetPoliceRecordsByCivilianId when you do not need the bundle.
local cid = pedData.mdtCivilianId
if cid then
  exports['night_shifts_mdt']:GetCivilianIntegrationSnapshot(cid, function(s)
    -- s.licenses, s.flagsMarkers, s.policeRecords
  end)
end

See ERS & CAD — pedData and PNC extras.

GetLicensesByCivilianId(civId, callback)
   
Parameters civId (number) — nsmdt_civilians.id. callback (function) — callback(licenses).
Returns Nothing synchronously. callback receives an array of nsmdt_licenses rows (plus officerFirstName / officerLastName).
Limitations Server-only. Async. Invalid civId or non-function callback → ignored.
exports['night_shifts_mdt']:GetLicensesByCivilianId(cid, function(licenses)
  for _, lic in ipairs(licenses) do
    print(lic.licenseType, lic.licenseNumber, lic.status)
  end
end)
GetAllFlagsMarkersByCivilianId(civId [, callback])
   
Parameters civId (number) — nsmdt_civilians.id. Optional callback(flags).
Returns Sync without callback: warm-cache array (often empty). With callback: all nsmdt_flags_markers rows for that civilian (active + inactive) — same source as the PNC profile. Prefer over GetFlagsMarkersByCivilianId.
Limitations Server-only. Always pass a callback for SSOT.
exports['night_shifts_mdt']:GetAllFlagsMarkersByCivilianId(cid, function(flags)
  for _, f in ipairs(flags) do
    print(f.id, f.flagType, f.isActive, f.description)
  end
end)
GetPoliceRecordsByCivilianId(civId [, callback])
   
Parameters civId (number) — nsmdt_civilians.id. Optional callback(records).
Returns Sync without callback: warm-cache array (often empty). With callback: rows from nsmdt_criminal_records for that civilian. Export name is legacy (there is no nsmdt_police_records table).
Limitations Server-only. Always pass a callback for SSOT.
exports['night_shifts_mdt']:GetPoliceRecordsByCivilianId(cid, function(records)
  for _, r in ipairs(records) do
    print(r.id, r.recordNumber, r.caseStatus)
  end
end)
GetActiveWarrants(limitOrOpts, callback)
   
Parameters Optional limit (number, 1–1000, default 500) or a table with a limit field, then callback(warrants). Or just callback(warrants).
Returns Nothing synchronously. callback receives active, non-expired warrant rows (joined display fields such as civDisplayId, issuedByDisplayName).
Limitations Server-only. Async MySQL (warrants are not fully cached). Ungated read for integrators — enforce your own officer auth at the terminal.
exports['night_shifts_mdt']:GetActiveWarrants(function(warrants)
  print(#warrants)
end)
Board list getters (flags, vehicle BOLOs, ANPR)
Export Returns
GetActiveFlagsMarkers([callback]) Sync = warm cache; callback = active flags from MySQL (limit 500)
GetActiveVehicleBolos() Cached vehicles with bolo == 1
GetActiveANPRRegistry() Snapshot of active ANPR watchlist (loaded at boot)
GetANPRHitLog([limit], callback) Async hit history from nsmdt_anpr_hit_log (distinct from the watchlist)
GetVehiclesByCivilianId(civId [, callback]) Sync = warm cache (often empty); callback = MySQL SSOT
GetVersion() Sync resource metadata version string
local mdt = exports['night_shifts_mdt']
print(mdt:GetVersion())
mdt:GetActiveFlagsMarkers(function(flags)
  print('active flags', #flags)
end)
mdt:GetVehiclesByCivilianId(cid, function(vehicles)
  for _, v in ipairs(vehicles) do
    print(v.id, v.licensePlate, v.bolo)
  end
end)
mdt:GetANPRHitLog(50, function(hits)
  print(#hits)
end)

Limitations: Server-only. Civilian / vehicle / flag tables are not fully loaded into cache at boot — pass a callback for SSOT.

Identity, search & bridges
Token Meaning
civilianId / civId Numeric nsmdt_civilians.id — PNC person-file key
personalId Display CIV-…
frameworkId ESX/QB character id (unique when set; auto-sync)
isFrameworkLinked On list rows: true when frameworkId is set
rockstarLicense Rockstar account on the civilian row

MDT does not store an “active civilian” on a player. Resolve identity with the exports below.

Export Notes
SearchCivilians(query, limit, cb) Async PNC search (min 2 chars)
GetCiviliansByServerId / GetCiviliansByLicense SSOT list for that Rockstar license; filter isFrameworkLinked for characters only
ResolveFrameworkLinkedCivilianByServerId(serverId [, cb]) Live framework character → one civilian (no “pick one by license” fallback)
GetCivilianByFrameworkId / GetCivilianByPersonalId / GetCivilianByIdentifier Exact lookups (prefer callback). GetCivilianByIdentifier is an alias of framework id lookup.
GetActiveShifts() / GetAllActiveShifts() Duty-only feed (who’s clocked in); rows may include serverId
GetDepartmentRoster(departmentId, cb) Full department membership (Management roster SSOT) including offline; onShift / connected / certifications
HasPermissionByServerId(officerServerId, permission) Sync boolean for UI button hiding. Permission keys = rank keys (e.g. pnc.flags, pnc.registration, pnc.anpr.manage)
local mdt = exports['night_shifts_mdt']

mdt:SearchCivilians('Lowly', 20, function(rows)
  for _, r in ipairs(rows) do print(r.civilianId, r.lastName) end
end)

mdt:GetCiviliansByServerId(source, function(list)
  for _, c in ipairs(list) do
    if c.isFrameworkLinked then
      print('character', c.civilianId, c.frameworkId)
    end
  end
end)

mdt:ResolveFrameworkLinkedCivilianByServerId(source, function(civ)
  if civ then print('linked', civ.civilianId) end
end)

-- Duty vs full roster
for _, row in ipairs(mdt:GetActiveShifts()) do
  print(row.userName, row.serverId)
end
mdt:GetDepartmentRoster(deptId, function(result)
  if not result.success then return end
  for _, m in ipairs(result.members) do
    print(m.userName, m.onShift, m.connected)
  end
end)

if mdt:HasPermissionByServerId(source, 'pnc.flags') then
  -- show Add / Clear flag
end

…ByServerId naming: first arg is the acting officer’s FiveM server id (auth/audit), not the warrant/flag target. Targets are always in data (warrantId, flagId, civId, vehicleId/plate, …).

Do not use singular GetCivilianByLicense (first match only). Vehicle BOLO writes require a specific vehicleId or plate.

LookupVehicleByPlate(plate [, callback]) and GetCivilianByPlate(plate [, callback])
   
Parameters plate (string) — display or normalised plate. Optional callback(result).
Returns LookupVehicleByPlate{ vehicle, civilian } or nil. GetCivilianByPlate → civilian or nil. Sync = cache only; callback = DB fallback.
Limitations Server-only. Match is normalised (trim, upper, strip spaces/hyphens). Prefer the callback.
exports['night_shifts_mdt']:LookupVehicleByPlate('AB12 CDE', function(hit)
  if hit and hit.civilian then
    print(hit.vehicle.id, hit.civilian.firstName, hit.civilian.lastName)
  end
end)

Write reference lookups

Load these before building write UIs. Do not hardcode type strings — servers customise warrant/flag catalogs and the full penal code list.

Export Sync/async Returns
GetWarrantTypes() Sync Enabled types: { id, label, description } (defaults: arrest, search, bench)
GetFlagTypes(callback) Async MySQL callback(types) — enabled { flagTypeId, label, displayOrder, showInFilter }
GetPenalCodes(callback) Async MySQL callback(codes) — active codes (id, codeNumber, title, minFine/maxFine, category fields, …)

Fixed enums (no lookup export):

Field Allowed values
Flag severity low, medium, high, critical (default medium)
ANPR reasonType stolen, bolo, custom (unknown values coerce to custom)

Use id from GetWarrantTypes as warrantType, flagTypeId as flagType, and numeric id from GetPenalCodes as penalCodeId / entries in penalCodeIds. civId is always numeric nsmdt_civilians.id.

local mdt = exports['night_shifts_mdt']
local warrantTypes = mdt:GetWarrantTypes()
mdt:GetFlagTypes(function(types)
  -- populate flag-type dropdown from types[].flagTypeId
end)
mdt:GetPenalCodes(function(codes)
  -- optional fine / ANPR charge pickers
end)

Mutators (officer-scoped writes)

These require the officer’s server id as the first argument. The officer must be on shift with the listed permission. Same validation as the in-tablet PNC. Constrained fields must come from Write reference lookups or the fixed enums above.

Callback contract

All mutators are async: callback(ok, resultOrError).

ok Second argument
true Result table (ids / numbers — see success shapes below)
false Error string (show or log it; do not assume a fixed enum for every path)

Typical failure strings

Situation Warrant / flag / fine ANPR
Off shift English, e.g. You must be on shift to create warrants Machine code no_active_shift
Missing permission English, e.g. You do not have permission to create flags Machine code no_permission
Bad catalog key Invalid warrant type / Invalid flag type
Bad severity Invalid severity level
Duplicate active flag This person already has an active flag of this type
Bad / missing plate or id invalid_plate / invalid_id / not_found

Unknown ANPR reasonType values are not rejected — they coerce to custom.

Exports
Export Permission Payload (high level)
CreateWarrantByServerId(serverId, data, cb) pnc.registration civId, warrantType (from GetWarrantTypes), reason (max 2000), optional expiresAt, linked charge/record ids
CreateFlagByServerId(serverId, data, cb) pnc.flags civId, flagType (from GetFlagTypes), description, optional severity, expiresAt. One active flag per flagType per civilian.
CreateFineByServerId(serverId, data, cb) pnc.registration civId, fineDescription, fineAmount, fineLocation, optional fineDueDate, penalCodeId (from GetPenalCodes; amount checked against min/max when set), vehicle / property / business / licence links
AddANPRRegistryByServerId(serverId, data, cb) pnc.anpr.manage plate, reason, optional penalCodeIds (array of ids from GetPenalCodes), reasonType (stolen / bolo / custom)
RemoveANPRRegistryByServerId(serverId, data, cb) pnc.anpr.manage Prefer entryId from the add result, or plate (deactivates all active rows for that plate)
CancelWarrantByServerId(officerServerId, data, cb) pnc.registration Officer cancels warrant; data.warrantId
SetFlagActiveByServerId(officerServerId, data, cb) pnc.flags Officer updates flag; data.flagId, data.isActive (clear = false)
SetVehicleBoloByServerId(officerServerId, data, cb) pnc.registration Officer sets vehicle-file BOLO; vehicleId and/or plate, bolo, optional boloDescription
AssignUnitToCallByServerId(officerServerId, data, cb) on-shift Officer assigns unit; callId, optional targetServerId (default self)
Success shapes (ok == true)
Export Result table (main fields)
CreateWarrantByServerId { warrantId, warrantNumber }
CreateFlagByServerId { flagId }
CreateFineByServerId { fineId, fineNumber }
AddANPRRegistryByServerId { success = true, action = 'added', entry = { id, plate, reason, reasonType, charges, … } } — use entry.id as entryId for remove
RemoveANPRRegistryByServerId { success = true, action = 'removed', entryId = … } or { …, plate = …, normPlate = … } when removed by plate
local mdt = exports['night_shifts_mdt']
local types = mdt:GetWarrantTypes()
local warrantType = types[1] and types[1].id or 'arrest'

-- Create warrant (officer = source)
mdt:CreateWarrantByServerId(source, {
  civId = 42,
  warrantType = warrantType,
  reason = 'Failure to appear',
}, function(ok, result)
  if not ok then
    print('warrant failed', result) -- string
    return
  end
  print(result.warrantId, result.warrantNumber)
end)

-- Lifecycle: clear flag / vehicle BOLO / cancel warrant — target in data
mdt:SetFlagActiveByServerId(source, { flagId = 12, isActive = false }, function(ok, err)
  print(ok, err)
end)
mdt:SetVehicleBoloByServerId(source, {
  plate = 'AB12CDE',
  bolo = true,
  boloDescription = 'Wanted for questioning',
}, function(ok, err) end)
mdt:CancelWarrantByServerId(source, { warrantId = 55 }, function(ok, err) end)

-- ANPR add then remove by entryId
mdt:GetPenalCodes(function(codes)
  local codeId = codes[1] and codes[1].id
  mdt:AddANPRRegistryByServerId(source, {
    plate = 'AB12CDE',
    reason = 'Suspect vehicle',
    reasonType = 'bolo',
    penalCodeIds = codeId and { codeId } or {},
  }, function(ok, result)
    if not ok then return print(result) end
    local entryId = result.entry and result.entry.id
    mdt:RemoveANPRRegistryByServerId(source, { entryId = entryId }, function(rmOk, rm)
      print(rmOk, rm)
    end)
  end)
end)

BOLO note: There is no separate BOLO table. Person alerts = flags; plate watchlist = ANPR registry; vehicle-file BOLO bit = GetActiveVehicleBolos().

Dispatch board poll + live updates

GetActiveCalls() / GetCallById(callId)
   
Parameters GetCallById: callId (number).
Returns GetActiveCalls → array of non-archived calls from cache. GetCallById → one call table or nil.
Limitations Server-only. Sync cache snapshots. Prefer the events below for live updates; use these for initial poll / catch-up.
local mdt = exports['night_shifts_mdt']
for _, call in ipairs(mdt:GetActiveCalls()) do
  print(call.id, call.callType, call.status)
end
local one = mdt:GetCallById(callId)
Server events

Listen with AddEventHandler on the server (not net events):

Event Args
nightshifts:mdt:server:callCreated callId, callPayload (cache-shaped call table)
nightshifts:mdt:server:callUpdated callId, callPayloadOrNil
AddEventHandler('nightshifts:mdt:server:callCreated', function(callId, call)
  print('new call', callId, call.callType)
end)

AddEventHandler('nightshifts:mdt:server:callUpdated', function(callId, call)
  print('call updated', callId)
end)

Third-party terminal adapters: Detect resource name night_shifts_mdt. Prefer these documented exports over direct nsmdt_* SQL. Raw table reads are best-effort only (additive migrations); do not write MDT tables from outside the resource.

GetDepartments()
   
Parameters None.
Returns Array table of active department rows from cache (SELECT * from nsmdt_departments, filtered to isActive). Each element is a table with at least: id, departmentName, departmentShortName, departmentDescription, departmentIcon, departmentBanner, departmentLogo, departmentType, departmentColor, blipColour, blipSprite, displayOrder, isActive, createdAt, createdBy, modifiedAt, modifiedBy.
Limitations Server-only. Archived departments (isActive = 0) are omitted (clock-in pickers only see active rows).
for _, d in ipairs(exports['night_shifts_mdt']:GetDepartments()) do
    print(d.id, d.departmentName)
end
GetRanksByDepartmentId(departmentId)
   
Parameters departmentId (number).
Returns Array table of rank rows for that department from cache. Each element includes: id, departmentId, departmentName (joined from departments), rankName, rankShortName, rankDescription, rankOrder, permissions (array of permission strings, e.g. PNC/dispatch flags — parsed from nsmdt_rank_permissions).
Limitations Server-only. Empty {} if departmentId is invalid or there are no ranks.
local ranks = exports['night_shifts_mdt']:GetRanksByDepartmentId(1)
GetSubDepartmentsByDepartmentId(departmentId)
   
Parameters departmentId (number).
Returns Array table of sub-department rows for that department from cache. Each element includes: id, departmentId, departmentName (joined), subDepartmentName, subDepartmentShortName, subDepartmentDescription, displayOrder, createdAt. Use id as subDepartmentId when calling StartShiftByServerId.
Limitations Server-only. Empty {} if the department has no sub-departments or id is invalid.
local sub = exports['night_shifts_mdt']:GetSubDepartmentsByDepartmentId(1)
GetSetting(key)
   
Parameters key (string) — e.g. currency, currencyPosition, timeFormat, dateFormat, speedUnit, vehicleInspectionEnabled, vehicleInspectionLabel, alert duration keys.
Returns Value for that setting (type depends on key).
Limitations Server-only. Read-only.
local mdt = exports['night_shifts_mdt']
print(mdt:GetSetting('currency'), mdt:GetSetting('speedUnit'))
GetAllSettings()
   
Parameters None.
Returns Table — full settings (defaults merged with DB), including alertDurations and similar.
Limitations Server-only. Read-only.
local settings = exports['night_shifts_mdt']:GetAllSettings()
GetCurrencySymbol()
   
Parameters None.
Returns String — display symbol (e.g. $, ).
Limitations Server-only.
local symbol = exports['night_shifts_mdt']:GetCurrencySymbol()
GetCurrentLanguage()
   
Parameters None.
Returns String — language code (e.g. en).
Limitations Server-only.
GetAvailableLanguages()
   
Parameters None.
Returns Table — array of language codes.
Limitations Server-only.
for _, code in ipairs(exports['night_shifts_mdt']:GetAvailableLanguages()) do print(code) end
GetActiveShiftByServerId(serverId)
   
Parameters serverId (number) — player server id.
Returns Plain active-shift table, or nil if not on shift. Fields: isOnShift, departmentId, subDepartmentId, rankId, callsign, statusCode, statusColor, statusLabel, startTime, pausedTime.
Limitations Server-only. Cross-resource safe (no vector3, no nested locationData). For location while on shift, use GetUserShiftData.
local shift = exports['night_shifts_mdt']:GetActiveShiftByServerId(source)
if shift then print(shift.callsign, shift.departmentId, shift.statusCode) end
GetCurrentShiftDurationByServerId(serverId)
   
Parameters serverId (number) — player server id.
Returns Number — seconds in the current shift; 0 if not on shift.
Limitations Server-only.
local seconds = exports['night_shifts_mdt']:GetCurrentShiftDurationByServerId(source)

Actions — Shift

StartShiftByServerId(serverId, departmentId, subDepartmentId, rankId, callsign)
   
Parameters serverId — player server id. departmentId, subDepartmentId, rankId — from GetDepartments / GetRanksByDepartmentId / GetSubDepartmentsByDepartmentId. callsign — string you want for this shift (export does not load a saved callsign from the DB; empty → "UNASSIGNED").
Returns success (boolean), result (table or error string). On success, result.callsign reflects what was stored.
Limitations Server-only. Player must already have an MDT session.
local mdt = exports['night_shifts_mdt']
local depts = mdt:GetDepartments()
local dept = nil
for _, d in ipairs(depts) do
    if d.departmentName == "LSPD" then dept = d; break end
end
if not dept then return end
local ranks = mdt:GetRanksByDepartmentId(dept.id)
local rank = nil
for _, r in ipairs(ranks) do
    if r.rankName == "Officer" then rank = r; break end
end
if not rank then return end
local success, result = mdt:StartShiftByServerId(source, dept.id, nil, rank.id, "L-42")
if success then print("Clocked in:", result.callsign) else print("Failed:", tostring(result)) end
EndShiftByServerId(serverId [, callback])
   
Parameters serverId (number). callback (optional) — function(success, durationOrError, totalTime).
Returns success (boolean), duration (number or error string), totalTime (number).
Limitations Server-only.
local mdt = exports['night_shifts_mdt']
local ok, duration, total = mdt:EndShiftByServerId(source)
mdt:EndShiftByServerId(source, function(success, durationOrErr, totalTime)
    if success then print("Ended. Duration:", durationOrErr) end
end)
UpdateShiftStatusByServerId(serverId, statusCode [, callback])
   
Parameters serverId (number). statusCode (string) — e.g. 10-8, 10-6 (must exist for the department).
Returns success (boolean), result (string or nil).
Limitations Server-only.
local ok, err = exports['night_shifts_mdt']:UpdateShiftStatusByServerId(source, "10-8")
UpdateShiftStatusByBindingByServerId(serverId, binding [, callback])
   
Parameters serverId (number). binding (string) — one of available, responding, on_scene, panic. callback (optional) — function(success, resultOrError).
Returns success (boolean), resultOrError (string or nil). On success, the resolved statusCode.
Limitations Server-only. Silent no-op when the department has no status configured for the binding. Requires night_shifts_mdt v1.4.1+.
local mdt = exports['night_shifts_mdt']
mdt:UpdateShiftStatusByBindingByServerId(source, 'responding')
mdt:UpdateShiftStatusByBindingByServerId(source, 'on_scene')
mdt:UpdateShiftStatusByBindingByServerId(source, 'available')
mdt:UpdateShiftStatusByBindingByServerId(source, 'panic')
UpdateCallsignByServerId(serverId, newCallsign)
   
Parameters serverId (number). newCallsign (string) — alphanumeric, spaces, hyphens; max 20 characters.
Returns success (boolean), result (table or error string).
Limitations Server-only.
exports['night_shifts_mdt']:UpdateCallsignByServerId(source, "L-99")

Actions — Dispatch

ForwardCallToMDT(callData [, callback])
   
Parameters callData (table) — see required fields below. callback (optional) — function(success, callId).
Returns Nothing useful synchronously; use callback when you need callId.
Limitations Server-only. Validation rejects if callType or description is empty; x/y missing or both zero; or no routing flag is set. At least one of requiresPolice, requiresAmbulance, requiresFire, requiresTow, requiresCouncil must be 1.

Required callData

Field Rule
callType Non-empty string
description Non-empty string
x, y Numbers; not both zero
requiresPolice / requiresAmbulance / requiresFire / requiresTow / requiresCouncil At least one 1

Optional callData (examples)

Field Notes
priority Default 3 (grades 1–5).
priorityLabel, priorityColor Override from settings.
incidentRef Dispatcher reference (e.g. CAD).
callerName, contactDetails Reporting party.
z Optional height.
street, postal, zone Display on call card.
exports['night_shifts_mdt']:ForwardCallToMDT({
    callType = "Road Traffic Collision",
    description = "Two vehicles, one driver unconscious.",
    x = -561.3, y = -199.7, z = 37.9,
    requiresPolice = 1, requiresAmbulance = 1,
    requiresFire = 0, requiresTow = 0, requiresCouncil = 0,
    priority = 2, callerName = "Dispatch", contactDetails = "555-0100",
}, function(success, callId)
    if success then print("Call #" .. tostring(callId)) end
end)

Client — integration exports

Getters

IsMenuOpen()
   
Returns Boolean — whether the MDT NUI/tablet is considered open.
Limitations Client-only.
if exports['night_shifts_mdt']:IsMenuOpen() then
    -- tablet is up
end
IsOnPoliceShift() · IsOnAmbulanceShift() · IsOnFireShift() · IsOnTowShift() · IsOnCouncilShift()
   
Returns Boolean each — whether the local player is clocked into that department type (synced from MDT state).
Limitations Client-only. At most one shift type at a time. Cached; MDT does not need to be open.
local mdt = exports['night_shifts_mdt']
if mdt:IsOnPoliceShift() then
    -- police shift HUD branch
elseif mdt:IsOnAmbulanceShift() then
    -- ambulance shift HUD branch
end
GetPlayerCallsign()
   
Parameters None.
Returns String — the local player’s current shift callsign (e.g. "L-42"), or nil when the player is not on shift.
Limitations Client-only. Cached from receiveShiftData, shiftStarted, and callsignUpdated events; the MDT does not need to be open. The player must have opened the MDT at least once during the session for the server to start sending shift updates (same constraint as the IsOn*Shift exports).
if GetResourceState("night_shifts_mdt") == "started" then
    local callsign = exports['night_shifts_mdt']:GetPlayerCallsign()
    if callsign then
        print("Callsign: " .. callsign)
    else
        print("Player is not on shift")
    end
else
    print("[ERROR] You have enabled the callsign feature but night_shifts_mdt is not started.")
end

Actions (tablet / UI)

OpenMenu() · CloseMenu() · ToggleMenu()
   
Parameters None.
Returns Depends on internal helpers; use for control flow, not strict contracts.
Limitations Client-only. May interact with focus/NUI; avoid re-entrancy spam.
exports['night_shifts_mdt']:OpenMenu()

Actions (dispatch)

ForwardCallToMDT(callData)
   
Parameters Same validation rules as the server export (callType, description, x/y, at least one requires* = 1). Optional: attachCreatingUnit = true or 1 — attach the local player as a unit on the new call (must be clocked in).
Returns Nothing.
Limitations Client-only. No callback — cannot read callId here. Use server ForwardCallToMDT if you need callId. Server receives attach intent as 1/0 for reliable serialization.
exports['night_shifts_mdt']:ForwardCallToMDT({
    callType = "Medical Emergency",
    description = "Person down near the pier.",
    x = -1850.0, y = -1230.0, z = 13.0,
    requiresPolice = 0, requiresAmbulance = 1,
    requiresFire = 0, requiresTow = 0, requiresCouncil = 0,
    callerName = "Civilian", contactDetails = "555-0199",
})

🚑 Medical Records (Ambulance Panel)

The Medical Records panel is an ambulance-only module accessible from the MDT sidebar when a user is on shift in a department of type ambulance and holds the medical_records.view permission. It mirrors the PNC structure (search → patient detail → tabbed file) and provides:

  • Patient search — find civilians by name, phone, or personal id.
  • Patient file with five tabs: Overview/Vitals, Diagnoses, Treatments, Medications, and Immunizations.
  • Medical alerts banner at the top of every patient file (DNR, contagious, organ donor, …).

Tiered permissions

Granted per rank under Admin Panel → Departments → Edit ranks → Permissions (only ambulance departments expose these):

Permission Grants
medical_records.view Page access + read-only of all patient files
medical_records.add_treatment Log treatments, allergies, vitals, immunizations (operational ranks)
medical_records.diagnose Add diagnoses + prescriptions (paramedic+, standing-order scope)
medical_records.flags Add/remove medical alerts (supervisory)
medical_records.delete Delete records (top brass — destructive corrections / cleanup)

🩺 Configuring medical types (admin)

Two of the dropdowns and the alert-banner styling are admin-curated rather than hardcoded so each server can model the alert types and treatment categories that fit their RP setting.

Where: Admin Panel → Medical Types (requires medical_types.view; create / edit / delete are separately gated).

Sub-tabs:

  • Alert Types — drives the patient-file alert banner and the Add Medical Alert dropdown. Each type has an identifier (immutable string id used to link existing records), a label, a FontAwesome icon (e.g. fa-ban, fa-virus), a hex color for the badge, a display order, and an enabled toggle.
  • Treatment Types — drives the Log Treatment dropdown. Slimmer fields: identifier, label, display order, enabled.

What is configurable:

Type / scale Configurable?
Alert types (DNR / Pregnant / …) ✅ Add, edit, disable, delete from the admin panel.
Treatment categories (On scene / Transport / …) ✅ Same.
Allergy severity (mild / moderate / …) ❌ Hardcoded — clinical standard. Localize via translation keys medical.severity_*.
Diagnosis status (active / chronic / resolved) ❌ Hardcoded — clinical standard. Localize via translation keys medical.diagnosis_status_*.
Prescription status (active / discontinued / completed) ❌ Hardcoded — clinical standard. Localize via translation keys medical.prescription_status_*.
Blood types (A+, A-, …) ❌ Hardcoded — universal biological set.

Default seed: On first install (when the lookup tables are empty) the MDT seeds the seven default alert types and six default treatment types from server/presets/medical_flag_type_presets.lua and server/presets/medical_treatment_type_presets.lua. After that, only the admin panel writes to those tables — the preset files are ignored, so editing them on a live server has no effect.

Creating a custom alert type:

  1. Open Admin Panel → Medical TypesAlert Types tab.
  2. Click Add Alert Type.
  3. Fill in:
    • Label — e.g. Mental Health Hold. The identifier is auto-derived (mental_health_hold).
    • Icon — any FontAwesome 6 free class without the fas prefix (e.g. fa-brain).
    • Color — any hex code; the live preview shows exactly how the banner will render it.
    • Display order — lower numbers appear first in the dropdown.
  4. Save. The new type is immediately available the next time medical staff open a patient file.

Disabling vs deleting:

  • Disabling keeps every existing record’s tag intact and only hides the type from new-entry dropdowns. Safe and reversible.
  • Deleting is blocked if any patient records still reference the type — the toast will tell you how many. To delete a type that’s in use, either reassign those records first or simply disable it instead.

Translations:

Each preset id has a matching translation key (medical.flag_type_<id>, medical.type_<id>). When you add a custom type, the admin label is shown until you also add a translation key — useful if your server runs multiple languages. The lookup order for a given type id is:

  1. Translation key (if defined) — wins.
  2. Admin-configured label.
  3. Raw id (last resort).

Database

The medical records system uses six patient-record tables and two admin-curated lookup tables, all auto-created on first start:

Table Purpose
nsmdt_medical_allergies Per-civilian allergies + severity
nsmdt_medical_diagnoses Active / chronic / resolved diagnoses
nsmdt_medical_treatments Chronological treatment log
nsmdt_medical_prescriptions Active / discontinued / completed prescriptions
nsmdt_medical_immunizations Vaccination records
nsmdt_medical_flags Medical alerts (DNR, contagious, …)
nsmdt_medical_flag_types (admin) Curated alert type registry (label + icon + color)
nsmdt_medical_treatment_types (admin) Curated treatment category registry

All patient-record tables CASCADE on civilian delete, so the Purge NPC Data admin action automatically cleans NPC medical history. The lookup tables are referenced by string id (not hard FK) so renaming or re-creating a preset doesn’t orphan history.


🛠️ Troubleshooting

Common Issues

Parsing Errors in F8 Console

  • Ensure files are transferred in binary mode via FTP
  • Follow the installation order: ZIP → Unpack → Binary FTP → Resources → server.cfg

Database Connection Issues

  • Verify MySQL connection string is correct
  • Check database credentials and accessibility
  • Ensure oxmysql is properly installed and started before the scripts that use it.

FiveM ID Not Found

  • Log into FiveM app when inside the app
  • Close and reopen FiveM app
  • Join server as a logged in user

Resource Naming

  • Use the shipped resource folder name (v1 default: night_shifts_mdt). Renaming breaks exports['…'] calls and ERS checks that expect the MDT resource name.
  • Keep config/, client/, server/, and fxmanifest.lua layout intact.

💡 Best Practices

Configuration Tips

  • Role Planning - Plan departments, ranks, and in-tablet permission matrices before go-live
  • Department Structure - Plan department, sub-department, and rank hierarchy
  • Language Localization - Configure for your country’s emergency services
  • Backup Configurations - Keep backups of working configurations

Database Management

  • Regular Backups - Backup your database regularly
  • Performance Monitoring - Monitor database performance
  • Table Maintenance - Periodically optimize database tables

User Experience

  • Clear Documentation - Provide users with MDT usage guidelines
  • Role Training - Train users on department-specific features
  • Emergency Procedures - Establish clear emergency call procedures

🆘 Support

Read through the instructions again if you have not managed to install the resource. Can’t get it to work still? Create a ticket through our dedicated support system in Discord:

Nights Software Discord


Back to top

Copyright © 2025 Nights Software

Page last modified: July 29, 2026 at 12:00 AM.

This site uses Just the Docs, a documentation theme for Jekyll.