Skip to main content

Available Server Exports

NPWD includes serveral available exports to easily interface with NPWD behavior and actions. You can find a list of the available server exports below.

generatePhoneNumber

Will generate a random phone number and return the value, this is useful for framework integration.

local phoneNumber = exports.npwd:generatePhoneNumber()

newPlayer

Adds a new player to NPWD internal handling. This is used with framework integration to load a player.

exports.npwd:newPlayer({ source = 1, firstname = 'Taso', lastname = 'Dev', identifier = 'dba4d971256a8bfb1a543cf0d46e342ad1cdd478', phoneNumber = '444-1312' })
danger

The export unloadPlayer currently doesn't perform correctly due to recoil limitations. You can track the issue here.

unloadPlayer

Removes a player from the player map. This should be triggered when swapping to another character where the player data changes.

exports.npwd:unloadPlayer(source)

onMessage

Listen to any message from a phone number

exports.npwd:onMessage('911', function(ctx)
TriggerEvent('roleplayEvent', ctx.data.message)
end)
interface OnMessageExportCtx {
data: PreDBMessage;

source: number;
}

interface PreDBMessage {
conversationId: string;
tgtPhoneNumber: string;
message: string;
}

emitMessage

Send a message to any player from any number

exports.npwd:emitMessage({
senderNumber = '911',
targetNumber = '123-456-7890',
message = 'Mission Row PD location!',
embed = {
type = "location",
coords = { 434.15, -981.71, 30.70 },
phoneNumber = '911'
}
})
interface EmitMessageExport {
senderNumber: string;
targetNumber: string;
message: string;
embed?: LocationEmbed | ContactEmbed;
}

interface LocationEmbed {
type: "location";
coords: { x: number, y: number, z: number };
phoneNumber: string;
};

interface ContactEmbed {
type: "contact";
display: string;
number: string;
avatar: string;
id: number;
}

getPlayerData

Returns all of the player data that npwd stores, can accept either a source, a license or a phone number in an object as the argument

local playerData = exports.npwd.getPlayerData({ identifier = 'license:abcdefg123456' })

Player data return in an object with the following format

interface ExportedPlayerData {
phoneNumber: string;
firstName: string;
lastName: string;
name: string;
identifier: string;
}

Fetch player data with an argument object with the following format, only use 1 at a time

interface PlayerDataArgument {
source?: string | number;
identifier?: string;
phoneNumber?: string;
}

onCall

Phone call middleware to intercept and handle calls with your own defined logic with provided context

exports.npwd:onCall("911", function(ctx)
local DispatcherSrc = 69 -- Get this via your own logic
-- If online, forward the 911 call to a real player, else send them a text message and hang up
if GetPlayerPing(DispatcherSrc) > 0 then
local DispatcherNum = exports.npwd:getPhoneNumber(DispatcherSrc)
ctx.forward(DispatcherNum)
else
ctx.reply("Sorry, we cannot find an active dispatcher to handle your call. Please try again later.")
ctx.exit()
end
end)
interface IncomingCallerCtx {
source: number;
number: string;
name: string;
}

interface OnCallExportCtx {
incomingCaller: IncomingCallerCtx; // incoming caller context
exit: () => void; // Exits the phone call for the caller
next: () => void; // Allows the number to ring out to the default handler
reply: (msg: string) => void; // Sends a text message to the caller
forward: (tgt: string) => void; // Forwards the call to a new number
}