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.
- Lua Example
- JS Example
local phoneNumber = exports.npwd:generatePhoneNumber()
const phoneNumber = await exports.npwd.generatePhoneNumber()
newPlayer
Adds a new player to NPWD internal handling. This is used with framework integration to load a player.
- Lua Example
- JS Example
exports.npwd:newPlayer({ source = 1, firstname = 'Taso', lastname = 'Dev', identifier = 'dba4d971256a8bfb1a543cf0d46e342ad1cdd478', phoneNumber = '444-1312' })
exports.npwd.newPlayer({ source: 1, firstname: 'Taso', lastname: 'Dev', identifier: 'dba4d971256a8bfb1a543cf0d46e342ad1cdd478', phoneNumber: '444-1312' })
isPlayerBusy
Returns a boolean if a player is busy (on a phone call).
- Lua Example
- JS Example
exports.npwd:isPlayerBusy(source)
exports.npwd.isPlayerBusy(source)
isPhoneNumberBusy
Returns a boolean if a phone number is busy (on a phone call).
- Lua Example
- JS Example
exports.npwd:isPhoneNumberBusy(phoneNumber)
exports.npwd.isPhoneNumberBusy(phoneNumber)
unloadPlayer
Removes a player from the player map. This should be triggered when swapping to another character where the player data changes.
- Lua Example
- JS Example
exports.npwd:unloadPlayer(source)
exports.npwd.unloadPlayer(source)
onMessage
Listen to any message from a phone number
- Lua Example
- JS Example
exports.npwd:onMessage('911', function(ctx)
TriggerEvent('roleplayEvent', ctx.data.message)
end)
exports.npwd.onMessage('911', (ctx) => {
emit('roleplayEvent', ctx.data.message)
})
interface OnMessageExportCtx {
data: PreDBMessage;
source: number;
}
interface PreDBMessage {
conversationId: string;
tgtPhoneNumber: string;
message: string;
}
emitMessage
Send a message to any player from any number
- Lua Example
- JS Example
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'
}
})
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
- Lua Example
- JS Example
local playerData = exports.npwd.getPlayerData({ identifier = 'license:abcdefg123456' })
const { firstName, lastName, phoneNumber, identifier } = await exports.npwd.getPlayerData({ source: 1 })
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
- Lua Example
- JS Example
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)
exports.npwd.onCall("911", (ctx) => {
const 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) {
const 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()
}
})
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
}