### Complete NPWD server.cfg Example Source: https://projecterror.dev/docs/npwd/start/installation A comprehensive example showing the recommended order of operations and variable definitions in the server.cfg file. ```bash set mysql_connection_string "mysql://root:12345@localhost/es_extended?charset=utf8mb4" set SCREENSHOT_BASIC_TOKEN XXXXXXXXXXXXXXX set NPWD_DISCORD_TOKEN "my_discord_webhook" ensure screenshot-basic ensure pma-voice ensure my_framework_here ensure esx-npwd ensure npwd ``` -------------------------------- ### Server Configuration for NPWD Features Source: https://projecterror.dev/docs/npwd/start/installation Examples of server.cfg entries required to set tokens and webhooks for NPWD features like screenshots, audio, and Discord logging. ```bash set SCREENSHOT_BASIC_TOKEN insert_token set NPWD_AUDIO_TOKEN your_api_token set NPWD_DISCORD_TOKEN "my_discord_webhook" ``` -------------------------------- ### QBCore Server Configuration for PEFCL Source: https://projecterror.dev/docs/pefcl/developers/framework_integration Server configuration snippet for QBCore, specifying the order in which PEFCL and its QBCore integration resource should be started. ```cfg ensure qb-pefcl ensure pefcl ``` -------------------------------- ### Configure Resource Loading Order Source: https://projecterror.dev/docs/npwd/faq Example of the server configuration order required to ensure custom applications are loaded before the main NPWD resource. ```text ensure npwd_crypto ensure npwd_qb_garage ensure ... ensure npwd ``` -------------------------------- ### ESX Server Configuration for PEFCL Source: https://projecterror.dev/docs/pefcl/developers/framework_integration Server configuration snippet for ESX, specifying the order in which PEFCL and its ESX integration resource should be started. ```cfg ensure pefcl-esx ensure pefcl ``` -------------------------------- ### ExampleApp Component in React (TypeScript) Source: https://projecterror.dev/docs/npwd/dev/basics The main React component for the ExampleApp. It imports and uses several UI components and custom hooks to display application data. It fetches an example string using the 'useExample' hook and displays it within an h3 tag. ```typescript // ExampleApp.tsx import React from 'react'; import { AppWrapper } from '../../../ui/components'; import { AppTitle } from '../../../ui/components/AppTitle'; import { AppContent } from '../../../ui/components/AppContent'; import { useApp } from '../../../os/apps/hooks/useApps'; import { useExample } from '../hooks/useExample'; export const ExampleApp = () => { // calling the example hook, and we assign the value to a variable const exampleString = useExample(); const example = useApp('EXAMPLE'); return (

This is an example

{/* Here we are using the value in a h3 tag */}

{exampleString}

); }; ``` -------------------------------- ### useExample Hook in React (TypeScript) Source: https://projecterror.dev/docs/npwd/dev/basics A custom React hook that retrieves a value from the Recoil state management library. It specifically uses 'useRecoilValue' to access the 'example' atom from 'exampleState'. This hook simplifies state access within components. ```typescript import { useRecoilValue } from 'recoil'; import { exampleState } from './state'; export const useExample = () => { const example = useRecoilValue(exampleState.example); return example; }; ``` -------------------------------- ### Configure Phone as Item Export Source: https://projecterror.dev/docs/npwd/start/config_reference Defines the JSON configuration for enabling phone-as-item functionality and provides a Lua export example to validate item possession. This allows NPWD to check for item requirements before allowing the phone to open. ```json { "PhoneAsItem": { "enabled": false, "exportResource": "my-core-resource", "exportFunction": "myCheckerFunction" } } ``` ```lua exports('myCheckerFunction', function() -- Now determine whether NPWD can be opened -- True Indicates that NPWD can be opened, if it returns false then NPWD cant be opened. return true end) ``` -------------------------------- ### Get Player Accounts by Identifier Source: https://projecterror.dev/docs/pefcl/developers/api/server Fetches all bank accounts for a player using their unique identifier. This operation does not require the player to be online. ```lua exports.pefcl:getAccountsByIdentifier(source, identifier) ``` ```javascript await exports.pefcl.getAccountsByIdentifier(source, identifier) ``` ```typescript await exports.pefcl.createAccount(source: number, identifier: string) ``` -------------------------------- ### Initiate Phone Call with NPWD Client Export Source: https://projecterror.dev/docs/npwd/api/client-exports Starts a phone call to a specified phone number. This function is used to programmatically initiate outgoing calls within the NPWD system. ```Lua exports.npwd:startPhoneCall('603-555-1212') ``` ```JavaScript exports.npwd.startPhoneCall('603-555-1212') ``` -------------------------------- ### Get Player Accounts Source: https://projecterror.dev/docs/pefcl/developers/api/server Retrieves all bank accounts associated with a player. This function can be called regardless of whether the player is currently online. ```lua exports.pefcl:getAccounts(source) ``` ```javascript await exports.pefcl.getAccounts(source) ``` ```typescript await exports.pefcl.createAccount(source: number) ``` -------------------------------- ### Get Bank Balance via PEFCL Source: https://projecterror.dev/docs/pefcl/developers/api/server Retrieves either the total bank balance or the balance of the default account for a specific player. ```lua exports.pefcl:getTotalBankBalance(source) exports.pefcl:getDefaultAccountBalance(source) ``` ```javascript await exports.pefcl.getTotalBankBalance(source) await exports.pefcl.getDefaultAccountBalance(source) ``` ```typescript await exports.pefcl.getTotalBankBalance(source: number) await exports.pefcl.getDefaultAccountBalance(source: number) ``` -------------------------------- ### Get Player Cash via PEFCL Source: https://projecterror.dev/docs/pefcl/developers/api/server Retrieves the current cash balance for a specific player. Requires the player source ID and supports framework-integrated environments. ```lua exports.pefcl:getCash(source) ``` ```javascript await exports.pefcl.getCash(source) ``` ```typescript await exports.pefcl.getCash(source: number) ``` -------------------------------- ### Handle Photo Mode Start Event in Lua Source: https://projecterror.dev/docs/npwd/api/npwd-events This Lua code snippet demonstrates how to handle the 'npwd:PhotoModeStarted' event. It sets a player state, hides the radar, removes cash displays, and triggers a custom HUD event when the player enters camera mode. This is useful for managing UI elements during photo mode. ```lua AddEventHandler('npwd:PhotoModeStarted', function() LocalPlayer.state:set('pictureMode', true, true) DisplayRadar(false) RemoveMultiplayerHudCash() RemoveMultiplayerBankCash() TriggerEvent('your-hide-hud-event') end) ``` -------------------------------- ### Get Client Phone Number with NPWD Export Source: https://projecterror.dev/docs/npwd/api/client-exports Retrieves the phone number associated with the client. This getter function returns the client's unique phone number within the NPWD system. ```Lua exports.npwd:getPhoneNumber() ``` ```JavaScript exports.npwd.getPhoneNumber() ``` -------------------------------- ### Create a basic application component Source: https://projecterror.dev/docs/npwd/dev/basics Demonstrates the use of AppWrapper and AppTitle components to structure a new application. It utilizes the useApp hook to retrieve application metadata. ```typescript export const ExampleApp = () => { // Calling the useApp hook, and passing in the app name. // The app name will the name you added in useApps. const example = useApp('EXAMPLE'); return ( ); }; ``` -------------------------------- ### Handle NUI Events and Requests Source: https://projecterror.dev/docs/npwd/dev/setup Demonstrates how to intercept NUI events using the useNuiEvent hook and how to define the resource name for fetchNui requests to ensure communication reaches the correct app. ```typescript const { data } = useNuiEvent({ event: "RANDOM" }); // ... const resourceName = "resourcename"; // ... ``` -------------------------------- ### Configure Image Upload Services for NPWD Source: https://projecterror.dev/docs/npwd/start/installation Configuration snippets for the npwd/config.json file to enable image uploads via Fivemanage, Imgur, or Discord webhooks. ```json "images": { "url": "https://api.fivemanage.com/api/image", "type": "image", "imageEncoding": "webp", "contentType": "multipart/form-data", "useContentType": false, "authorizationHeader": "Authorization", "authorizationPrefix": "", "useAuthorization": true, "returnedDataIndexes": ["url"] } ``` ```json "images": { "url": "https://api.imgur.com/3/image", "type": "imgur", "imageEncoding": "jpg", "contentType": "multipart/form-data", "useContentType": true, "authorizationHeader": "Authorization", "authorizationPrefix": "Client-ID", "useAuthorization": true, "returnedDataIndexes": ["data", "link"] } ``` ```json "images": { "useWebhook": true } ``` -------------------------------- ### Configure General Settings for PEFCL Source: https://projecterror.dev/docs/pefcl/configuration Defines the core operational settings for PEFCL, including framework integration, UI language, and currency formatting. These settings are essential for ensuring the system interacts correctly with external frameworks like QB-core or ESX. ```json { "general": { "useFrameworkIntegration": false, "language": "en", "currency": "USD" } } ``` -------------------------------- ### QBCore Framework Integration Configuration Source: https://projecterror.dev/docs/pefcl/developers/framework_integration Configuration for enabling and setting up the PEFCL integration with the QBCore framework. This includes enabling the integration, specifying the resource name, and optionally syncing the initial bank balance. ```json "frameworkIntegration": { "enabled": true, "resource": "qb-pefcl", "syncInitialBankBalance": true } ``` -------------------------------- ### Configure Audio Uploads for NPWD Source: https://projecterror.dev/docs/npwd/start/installation Settings to enable voice message functionality in NPWD by defining the audio API endpoint in the configuration file. ```json "voiceMessage": { "enabled": true, "authorizationHeader": "Authorization", "url": "https://api.fivemanage.com/api/audio", "returnedDataIndexes": ["url"] } ``` -------------------------------- ### Configure NPWD for Phone as Item (JSON) Source: https://projecterror.dev/docs/npwd/framework/qb-core This JSON configuration snippet enables the 'PhoneAsItem' feature in NPWD, specifying 'qb-npwd' as the export resource and 'HasPhone' as the function to check for the phone item. This is an alternative to using the 'npwd:framework' convar if you want to use qb-npwd. ```json "PhoneAsItem": { "enabled": true, "exportResource": "qb-npwd", "exportFunction": "HasPhone" }, "general": { "useResourceIntegration": true, "toggleKey": "f1", "toggleCommand": "phone" }, "database": { "useIdentifierPrefix": false, "playerTable": "players", "identifierColumn": "citizenid", "identifierType": "license", "profileQueries": true, "phoneNumberColumn": "phone_number" }, ``` ```json "PhoneAsItem": { "enabled": true, "exportResource": "qb-npwd", "exportFunction": "HasPhone" }, ``` -------------------------------- ### Configure Webpack Module Federation Source: https://projecterror.dev/docs/npwd/dev/setup Sets the module federation name to match the resource name, allowing NPWD to locate and load the application dynamically. ```javascript new ModuleFederationPlugin({ name: 'template', // ... ``` -------------------------------- ### Manage Player Integration Source: https://projecterror.dev/docs/pefcl/developers/api/server Bridge existing frameworks like QB or ESX with PEFCL by loading or unloading player data. ```Lua exports.pefcl:loadPlayer(source, { identifier = identifer, name = name, source = source }) exports.pefcl:unloadPlayer(source) ``` ```JavaScript await exports.pefcl.loadPlayer(source, { identifier, name, source }) await exports.pefcl.loadPlayer(source) ``` ```TypeScript await exports.pefcl.loadPlayer(source: number, { identifier, name, source }: { identifier: string, name: string, source: number }) await exports.pefcl.loadPlayer(source: number) ``` -------------------------------- ### Define a Recoil state atom Source: https://projecterror.dev/docs/npwd/dev/basics Shows how to define a global state atom using the Recoil library. The atom requires a unique key and an initial default value. ```typescript // state.ts import { atom } from 'recoil'; export const exampleState = { exampleArray: atom({ key: 'exampleArray', // make sure this is unique, globally. default: [] }) }; ``` -------------------------------- ### Getter Exports Source: https://projecterror.dev/docs/npwd/api/client-exports Endpoints for retrieving the current state of the phone or player information. ```APIDOC ## isPhoneDisabled ### Description Returns whether the phone is currently disabled. ### Response - **boolean** - Returns true if disabled. --- ## getPhoneNumber ### Description Returns the current client's phone number. ### Response - **string** - The phone number. ``` -------------------------------- ### Message Handling Source: https://projecterror.dev/docs/npwd/api/server-exports Listen for incoming messages or emit messages to players. Supports custom embeds for locations or contacts. ```lua exports.npwd:onMessage('911', function(ctx) TriggerEvent('roleplayEvent', ctx.data.message) end) 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' } }) ``` ```javascript exports.npwd.onMessage('911', (ctx) => { emit('roleplayEvent', ctx.data.message) }) 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' } }) ``` -------------------------------- ### Configure Marketplace Persistence Source: https://projecterror.dev/docs/npwd/configuration/defaults Controls whether marketplace listings are saved and persist across server restarts. ```json { "marketplace": { "persistListings": false } } ``` -------------------------------- ### Configure NPWD Application Source: https://projecterror.dev/docs/npwd/dev/setup Defines the application settings including unique ID, localization, icons, and the main application component. This configuration is exported from the app's main configuration file. ```typescript export default (settings: Settings) => ({ // ... id: "APP_NAME", nameLocale: localizedAppName[settings?.language ?? defaultLanguage], icon: AppIcon, notificationIcon: NotficationIcon, app: App, }); ``` -------------------------------- ### Fill New Note with NPWD Client Export Source: https://projecterror.dev/docs/npwd/api/client-exports Opens the notes app and pre-fills a new note with provided title and content. If a note with the same title exists, it will be edited. This function facilitates quick note creation. ```Lua exports.npwd:fillNewNote({ title = 'Some Note', content = 'This is the filled in content of the note' }) ``` ```JavaScript exports.npwd.fillNewNote({ title: 'Some Note', content: 'This is the filled in content of the note' }) ``` -------------------------------- ### Configure Match Application Source: https://projecterror.dev/docs/npwd/configuration/defaults Configures the settings for the Match application, specifically regarding profile name generation and user editing permissions. ```json { "match": { "generateProfileNameFromUsers": true, "allowEditableProfileName": true } } ``` -------------------------------- ### UI and Visibility Exports Source: https://projecterror.dev/docs/npwd/api/client-exports Endpoints for controlling the phone's UI state, visibility, and enabled status. ```APIDOC ## sendUIMessage ### Description Sends a NUI message to the phone interface. ### Parameters - **data** (object) - Required - The payload to send to the UI. ### Request Example { "type": "EVENT", "payload": { "dog": "woof" } } --- ## setPhoneVisible ### Description Shows or hides the phone UI. ### Parameters - **visible** (boolean) - Required - True to show, false to hide. --- ## setPhoneDisabled ### Description Disables or enables the phone. When disabled, the player cannot open the phone or receive notifications. ### Parameters - **disabled** (boolean) - Required - True to disable, false to enable. ``` -------------------------------- ### Set NPWD Framework Convar (CFG) Source: https://projecterror.dev/docs/npwd/framework/qb-core This configuration command sets the 'npwd:framework' convar in your server.cfg file to 'qbcore'. This tells NPWD to use QB-Core as its framework. This should be done after adding the phone_number column. ```cfg set npwd:framework qbcore ``` -------------------------------- ### Configure Debugging Options for PEFCL Source: https://projecterror.dev/docs/pefcl/configuration Sets the logging verbosity and development-specific behaviors for the PEFCL application. The debug level controls log output, while mockLicenses should be strictly avoided in production environments. ```json { "debug": { "level": "error", "mockLicenses": false } } ``` -------------------------------- ### Register service hook in main Phone component Source: https://projecterror.dev/docs/npwd/dev/basics Demonstrates how to initialize the service hook within the main Phone component to ensure event listeners are active. ```typescript // Phone.tsx import { usePhotoService } from './apps/example/hooks/useExampleService'; function Phone () { useExampleService(); } ``` -------------------------------- ### Create a custom Recoil hook Source: https://projecterror.dev/docs/npwd/dev/basics Implements a custom hook to read and write to a Recoil state. This abstracts the useRecoilState hook for easier component consumption. ```typescript // useExampleList.ts import { useRecoilState } from 'recoil'; export const useExampleList = () => { const [list, setList] = useRecoilState(exampleState.exampleArray); return { list, setList }; }; ``` -------------------------------- ### Retrieve Player Data Source: https://projecterror.dev/docs/npwd/api/server-exports Fetches stored player information using a source, identifier, or phone number. Returns an object containing user details. ```lua local playerData = exports.npwd.getPlayerData({ identifier = 'license:abcdefg123456' }) ``` ```javascript const { firstName, lastName, phoneNumber, identifier } = await exports.npwd.getPlayerData({ source: 1 }) ``` -------------------------------- ### Handle Financial Events Source: https://projecterror.dev/docs/pefcl/developers/api/server Listen for system-wide financial updates including account changes, cash updates, transactions, and new invoices. ```Lua AddEventHandler("pefcl:newAccountBalance", function(account: Account) end) AddEventHandler("pefcl:newAccountCreated", function(account: Account) end) AddEventHandler("pefcl:accountDeleted", function(account: Account) end) AddEventHandler("pefcl:newCash", function(cash: Cash) end) AddEventHandler("pefcl:newTransaction", function(transaction: Transaction) end) AddEventHandler("pefcl:newInvoice", function(invoice: Invoice) end) ``` -------------------------------- ### Configure Application Loading Source: https://projecterror.dev/docs/npwd/configuration/defaults Manages the loading of external applications and defines which apps should be disabled within the phone interface. ```json { "apps": [], "disabledApps": [] } ``` -------------------------------- ### ESX Framework Integration Configuration Source: https://projecterror.dev/docs/pefcl/developers/framework_integration Configuration for enabling and setting up the PEFCL integration with the ESX framework. This includes enabling the integration, specifying the resource name, and optionally syncing the initial bank balance. ```json "frameworkIntegration": { "enabled": true, "resource": "pefcl-esx", "syncInitialBankBalance": true } ``` -------------------------------- ### Retrieve Invoices Source: https://projecterror.dev/docs/pefcl/developers/api/server Fetches all invoices or specifically unpaid invoices for a player identified by their source ID. ```Lua exports.pefcl:getInvoices(source) exports.pefcl:getUnpaidInvoices(source) ``` ```JavaScript await exports.pefcl.getInvoices(source) await exports.pefcl.getUnpaidInvoices(source) ``` ```TypeScript await exports.pefcl.getInvoices(source: number) await exports.pefcl.getUnpaidInvoices(source: number) ``` -------------------------------- ### Configure image upload service Source: https://projecterror.dev/docs/npwd/configuration/defaults Defines the endpoint and authentication parameters for uploading images captured by the in-game camera. It supports custom API endpoints, encoding types, and authorization headers. ```JSON { "images": { "url": "https://api.imgur.com/3/image", "type": "imgur", "imageEncoding": "jpg", "contentType": "multipart/form-data", "authorizationPrefix": "Client-ID", "useAuthorization": true, "returnedDataIndexes": ["data", "link"] } } ``` -------------------------------- ### Implement a service hook for NUI events Source: https://projecterror.dev/docs/npwd/dev/basics Creates a service hook that listens for client-side NUI events using useNuiEvent and updates the application state accordingly. This ensures the app stays synchronized with client data. ```typescript // useExampleService.ts import { useExampleList } from './useExampleList'; import { exampleState } from './state'; import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { useSetRecoilState } from 'recoil'; export const useExampleService = () => { const setList = useSetRecoilState(exampleState.exampleArray); useNuiEvent('EXAMPLE', 'setList', setList); return useExampleList(); }; ``` -------------------------------- ### Register Application in NPWD Source: https://projecterror.dev/docs/npwd/dev/setup Adds the custom application resource name to the NPWD configuration file to enable it within the phone interface. ```json { // other configuration "apps": ["resourcename"] } ``` -------------------------------- ### Open Bank UI via PEFCL Export Source: https://projecterror.dev/docs/pefcl/developers/api/client Triggers the opening of the Bank user interface. Supports Lua, JavaScript, and TypeScript integrations. ```lua exports.pefcl:openBank() ``` ```javascript exports.pefcl.openBank() ``` ```typescript exports.pefcl.openBank() ``` -------------------------------- ### Create System Notification Source: https://projecterror.dev/docs/npwd/api/notification-api Triggers an OS-style system notification that supports interactive controls. Requires enabling 'controls' and 'keepOpen' to utilize 'onConfirm' and 'onCancel' callbacks. ```typescript type SystemNotificationDTO = { uniqId: string; content: string; secondaryTitle: string; keepOpen: boolean; duration: number; onConfirm?: () => void; onCancel?: () => void; controls?: boolean; }; ``` ```lua exports["npwd"]:createSystemNotification({ uniqId = "esxSurvey", content = "Do you like ESX?", secondaryTitle = "NPWD Survey", keepOpen = true, duration = 5000, controls = true, onConfirm = function() print("LIKES ESX") end, onCancel = function() print("DOES NOT LIKE ESX") end, }) ``` -------------------------------- ### Configure image safety filters Source: https://projecterror.dev/docs/npwd/configuration/defaults Sets up security policies for images, including URL filtering and embedding unsafe content. This helps prevent malicious or unwanted images from being displayed in the application. ```JSON { "imageSafety": { "filterUnsafeImageUrls": true, "embedUnsafeImages": false, "embedUrl": "https://i.example.com/embed", "safeImageUrls": [ "imgur.com", "file.glass", "dropbox.com", "tenor.com", "discord.com", "discordapp.com", "wikipedia.org" ] } } ``` -------------------------------- ### Define onCall Context Interface Source: https://projecterror.dev/docs/npwd/api/server-exports TypeScript interface definitions for the incoming caller context and the available methods within the onCall callback, such as forward, reply, and exit. ```typescript 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 } ``` -------------------------------- ### Custom Framework Integration Configuration Source: https://projecterror.dev/docs/pefcl/developers/framework_integration Configuration for enabling PEFCL integration with a custom framework. Requires specifying the resource name that contains the framework exports and optionally syncing the initial bank balance. ```json "frameworkIntegration": { "enabled": true, "resource": "your-resource", "syncInitialBankBalance": true } ``` -------------------------------- ### Open ATM UI via PEFCL Export Source: https://projecterror.dev/docs/pefcl/developers/api/client Triggers the opening of the ATM user interface. ```lua exports.pefcl:openAtm() ``` ```javascript exports.pefcl.openAtm() ``` ```typescript exports.pefcl.openAtm() ``` -------------------------------- ### Configure Word Filtering Source: https://projecterror.dev/docs/npwd/configuration/defaults Sets up the profanity filter to restrict specific words within the phone system. Input is a boolean toggle and an array of strings representing banned content. ```json { "profanityFilter": { "enabled": false, "badWords": ["esx", "chip"] } } ``` -------------------------------- ### Manage Player Lifecycle Source: https://projecterror.dev/docs/npwd/api/server-exports Functions to register or remove players from NPWD internal handling. Use newPlayer when a player connects and unloadPlayer when a player disconnects or switches characters. ```lua exports.npwd:newPlayer({ source = 1, firstname = 'Taso', lastname = 'Dev', identifier = 'dba4d971256a8bfb1a543cf0d46e342ad1cdd478', phoneNumber = '444-1312' }) exports.npwd:unloadPlayer(source) ``` ```javascript exports.npwd.newPlayer({ source: 1, firstname: 'Taso', lastname: 'Dev', identifier: 'dba4d971256a8bfb1a543cf0d46e342ad1cdd478', phoneNumber: '444-1312' }) exports.npwd.unloadPlayer(source) ``` -------------------------------- ### Configure Voice Messaging Settings Source: https://projecterror.dev/docs/npwd/configuration/defaults Defines the configuration for voice note functionality, including API endpoints and authorization headers. Requires an external API service to handle sound clip uploads. ```json { "voiceMessage": { "enabled": false, "authorizationHeader": "Authorization", "url": "", "returnedDataIndexes": ["url"] } } ``` -------------------------------- ### Handle New Transaction Event Source: https://projecterror.dev/docs/pefcl/developers/api/client Listens for the 'pefcl:newTransaction' event to perform actions when a transaction occurs. Includes interfaces for Account and Transaction objects. ```lua AddEventHandler('pefcl:newTransaction', function(transaction) ShowNotification("You got a new transaction of" .. transaction.amount) end) ``` ```javascript onNet('pefcl:newTransaction', (transaction) => { showNotification(`You got a new transaction of ${transaction.amount}`) }) ``` ```typescript onNet('pefcl:newTransaction', (transaction: Transaction) => { showNotification(`You got a new transaction of ${transaction.amount}`) }) ``` -------------------------------- ### Manage Bank Balance via PEFCL Source: https://projecterror.dev/docs/pefcl/developers/api/server Adds or removes funds from a player's default bank account. Supports an optional message for transaction logging. ```lua exports.pefcl:addBankBalance(source, { amount = amount, message = message }) exports.pefcl:removeBankBalance(source, { amount = amount, message = message }) ``` ```javascript await exports.pefcl.addBankBalance(source, amount, message) await exports.pefcl.removeBankBalance(source, {amount, message}) ``` ```typescript await exports.pefcl.addBankBalance(source: number, amount: number, message?: string) await exports.pefcl.removeBankBalance(source: number, {amount: number, message?: string}) ``` -------------------------------- ### Create Invoice for Nearest Player via PEFCL Export Source: https://projecterror.dev/docs/pefcl/developers/api/client Generates an invoice for the nearest player with a specific amount and descriptive message. ```lua exports.pefcl:createInvoiceForNearestPlayer(amount, message) ``` ```javascript exports.pefcl.createInvoiceForNearestPlayer(amount, message) ``` ```typescript exports.pefcl.createInvoiceForNearestPlayer(amount: number, message: string) ``` -------------------------------- ### Add phone_number Column to Players Table (SQL) Source: https://projecterror.dev/docs/npwd/framework/qb-core This SQL query adds a 'phone_number' column to the 'players' table, which is required for NPWD to function with QB-Core. Ensure this query is run before configuring other settings. ```sql ALTER TABLE players ADD COLUMN `phone_number` VARCHAR(20) DEFAULT NULL; ``` -------------------------------- ### Generate Phone Number Source: https://projecterror.dev/docs/npwd/api/server-exports Generates a random phone number for framework integration. Returns a string representing the new phone number. ```lua local phoneNumber = exports.npwd:generatePhoneNumber() ``` ```javascript const phoneNumber = await exports.npwd.generatePhoneNumber() ``` -------------------------------- ### Create App Notification Source: https://projecterror.dev/docs/npwd/api/notification-api Defines the structure and usage for creating notifications for specific phone applications. Requires a CreateNotificationDTO object to specify the app ID, content, and navigation path. ```typescript type CreateNotificationDTO = { appId: string; content: string; secondaryTitle: string; duration: number; keepOpen: boolean; path: string; notisId: string; }; ``` ```lua exports["npwd"]:createNotification({ notisId = "npwd:tweetBroadcast", appId = "TWITTER", content = "Hello, this is a new tweet", secondaryTitle = "Twitter bot", keepOpen = false, duration = 5000, path = "/twitter", }) ``` -------------------------------- ### Configure General Settings and Phone Number Format Source: https://projecterror.dev/docs/npwd/start/config_reference Configures general phone behavior including toggle keys and custom phone number formatting using regex patterns. The phoneNumberFormat property allows users to define how phone numbers are displayed in the UI. ```json "general": { "useResourceIntegration": false, "toggleKey": "f1", "toggleCommand": "phone", "defaultLanguage": "en", "showId": false, "phoneNumberFormat": "/(\\d{3})(\\d{3})(\\d{4})/" } ``` ```json "phoneNumberFormat": "/(\\d{3})(\\d{3})(\\d{4})/" // Result: 233-134-9533 ``` ```json "phoneNumberFormat": "/(\\d{8})" // Result: 34256475 ``` -------------------------------- ### Open NPWD App with Client Export Source: https://projecterror.dev/docs/npwd/api/client-exports Opens a specific NPWD application identified by its app ID. This export allows direct navigation to different sections of the NPWD interface, such as the contacts or settings. ```Lua exports.npwd:openApp('CONTACTS') ``` ```JavaScript exports.npwd.openApp('CONTACTS') ``` -------------------------------- ### Configure NPWD system settings Source: https://projecterror.dev/docs/npwd/configuration/defaults The primary configuration file for the NPWD phone system. It defines framework integration, database connectivity, and default behaviors for various modules like Twitter, Marketplace, and Browser. ```JSON { "PhoneAsItem": { "enabled": false, "exportResource": "my-core-resource", "exportFunction": "myCheckerFunction" }, "general": { "useResourceIntegration": false, "toggleKey": "f1", "toggleCommand": "phone", "defaultLanguage": "en", "showId": false, "phoneNumberFormat": "/(\\d{3})(\\d{3})(\\d{4})/" }, "database": { "useIdentifierPrefix": false, "playerTable": "users", "identifierColumn": "identifier", "identifierType": "license", "profileQueries": true, "phoneNumberColumn": "phone_number" }, "twitter": { "showNotifications": true, "characterLimit": 160 }, "debug": { "level": "error", "enabled": true, "sentryEnabled": true } } ``` -------------------------------- ### Control Phone Visibility with NPWD Client Export Source: https://projecterror.dev/docs/npwd/api/client-exports Sets the visibility state of the phone interface. Accepts a boolean value to show or hide the phone, respecting any disabled states. This is useful for managing when the player can interact with the phone. ```Lua exports.npwd:setPhoneVisible(true) ``` ```JavaScript exports.npwd.setPhoneVisible(true) ``` -------------------------------- ### Create Unique Account Source: https://projecterror.dev/docs/pefcl/developers/api/server Creates a new bank account for a player with a specified type and name. This operation can be performed even if the player is offline. It requires the player's source, identifier, account name, and type. ```lua exports.pefcl:createUniqueAccount(source, { identifier = identifier, name = name, type = type }) ``` ```javascript await exports.pefcl.createUniqueAccount(source, { identifier, name, type }) ``` ```typescript await exports.pefcl.createUniqueAccount(source, { identifier, name, type }: source: number, { identifier: string, name: string, type: AccountType }) ``` -------------------------------- ### Application and Call Exports Source: https://projecterror.dev/docs/npwd/api/client-exports Endpoints for managing phone applications and call states. ```APIDOC ## openApp ### Description Opens a specific NPWD application. ### Parameters - **appId** (string) - Required - The ID of the app to open (e.g., 'CONTACTS'). --- ## startPhoneCall ### Description Initiates a phone call to a specified number. ### Parameters - **number** (string) - Required - The phone number to call. --- ## fillNewContact ### Description Opens the contact app with pre-filled data. ### Parameters - **data** (object) - Required - Object containing name, number, and avatar. ``` -------------------------------- ### Create Invoice via PEFCL Source: https://projecterror.dev/docs/pefcl/developers/api/server Creates a new invoice for a player, allowing for custom sender information, amounts, and optional account routing. This function does not require the target player to be online. ```Lua exports.pefcl:createInvoice(source, { to = to, toIdentifier = toIdentifier, from = from, fromIdentifier = fromIdentifier, amount = amount, message = message, receiverAccountIdentifier = receiverAccountIdentifier, expiresAt = expiresAt }) ``` ```JavaScript await exports.pefcl.createInvoice(source, { to, toIdentifier, from, fromIdentifier, amount, message, recieverAccountId, expiresAt }) ``` ```TypeScript await exports.pefcl.createInvoice(source: number, { to, toIdentifier, from, fromIdentifier, amount, message, recieverAccountId, expiresAt }: { to: string; toIdentifier: string; from: string; fromIdentifier: string; amount: number; message: string, recieverAccountId?: number; expiresAt?: string }) ``` -------------------------------- ### Fill New Contact Form with NPWD Client Export Source: https://projecterror.dev/docs/npwd/api/client-exports Opens the contacts app and pre-fills a new contact form with provided data. The contact is not created until the player confirms the action. It accepts an object with name, number, and avatar. ```Lua exports.npwd:fillNewContact({ name = 'John Doe', number = '603-555-1212', avatar = 'https://i.imgur.com/j3UvwQA.png' }) ``` ```JavaScript exports.npwd.fillNewContact({ name: 'John Doe', number: '603-555-1212', avatar: 'https://i.imgur.com/j3UvwQA.png' }) ``` -------------------------------- ### Check Phone Visibility State with NPWD Client Export Source: https://projecterror.dev/docs/npwd/api/client-exports Retrieves the current visibility state of the phone interface. This getter function returns a boolean indicating whether the phone is currently visible and accessible to the player. ```Lua local isPhoneVisible = exports.npwd:isPhoneVisible() ``` ```JavaScript const isPhoneVisible = exports.npwd.isPhoneVisible() ``` -------------------------------- ### exports.npwd:onCall Source: https://projecterror.dev/docs/npwd/api/server-exports Registers a handler for incoming calls to a specific number, providing a context object to manage call flow. ```APIDOC ## [EXPORT] exports.npwd:onCall ### Description Intercepts incoming phone calls to a specified number. Allows developers to define custom logic to forward, reply, or exit the call session. ### Method Export / Middleware ### Parameters - **number** (string) - Required - The phone number to intercept (e.g., "911"). - **callback** (function) - Required - A function receiving the `OnCallExportCtx` object. ### Context Object (OnCallExportCtx) - **incomingCaller** (object) - Details about the caller (source, number, name). - **exit** (function) - Terminates the call for the caller. - **next** (function) - Passes the call to the default handler. - **reply** (function) - Sends a text message to the caller. - **forward** (function) - Forwards the call to a target number. ### Request Example (Lua) ```lua exports.npwd:onCall("911", function(ctx) ctx.forward("555-0100") end) ``` ### Request Example (JS) ```javascript exports.npwd.onCall("911", (ctx) => { ctx.reply("Service is currently unavailable."); ctx.exit(); }) ``` ``` -------------------------------- ### Trigger Custom Window Events Source: https://projecterror.dev/docs/npwd/api/notification-api Utilizes the @npwd/hooks library to dispatch custom events from external NUI applications to the NPWD system. ```typescript import { useNpwdEvent } from "@npwd/hooks"; import { CreateNotificationDTO } from "@npwd/types"; const dispatch = useNpwdEvent( "npwd:ext:createNotification", {} ); const triggerNotification = () => { dispatch({ appId: "External app id", content: "Hello from external app", secondaryTitle: "some secondary title", path: "/externalapproute", notisId: "testNOti", }); }; ``` -------------------------------- ### Retrieve Total Bank Balance by Identifier Source: https://projecterror.dev/docs/pefcl/developers/api/server Fetches the total bank balance for a given player identifier. This function is part of the pefcl module and requires a source and identifier as input. ```lua exports.pefcl:getTotalBankBalanceByIdentifier(source, identifier) ``` ```javascript await exports.pefcl.getTotalBankBalanceByIdentifier(source, identifier) ``` ```typescript await exports.pefcl.getTotalBankBalanceByIdentifier(source: number, identifier: string) ``` -------------------------------- ### Configure Custom Phone Number Generation Source: https://projecterror.dev/docs/npwd/configuration/defaults Enables integration with external resources for generating unique phone numbers. Requires specifying the resource name and the export function to be called. ```json { "customPhoneNumber": { "enabled": false, "exportResource": "number-generator-resource", "exportFunction": "generateNumber" } } ``` -------------------------------- ### Custom Framework Integration Required Exports (TypeScript) Source: https://projecterror.dev/docs/pefcl/developers/framework_integration Defines the server-side functions that must be exported by a custom framework integration resource for PEFCL to interact with player finances and cards. ```typescript export interface Card { id: number; account?: Account; accountId?: number; pin: number; isBlocked: boolean; holder: string; number: string; updatedAt?: string | number | Date; createdAt?: string | number | Date; } export interface InventoryCard { id: number; holder: string; number: string; } ``` -------------------------------- ### Intercept and Handle Calls with onCall Source: https://projecterror.dev/docs/npwd/api/server-exports The onCall export allows you to define custom logic for specific phone numbers. It provides a context object to forward calls, reply with messages, or exit the call flow based on server-side conditions. ```lua 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) ``` ```javascript 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() } }) ``` -------------------------------- ### Fix Database Collation Errors Source: https://projecterror.dev/docs/npwd/faq SQL commands to resolve collation mismatch errors by converting tables to utf8_unicode_ci. This ensures proper character encoding for messages and emojis. ```sql ALTER TABLE npwd_messages CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci; ALTER TABLE npwd_messages_conversations CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci; ``` -------------------------------- ### Add Bank Balance by Identifier Source: https://projecterror.dev/docs/pefcl/developers/api/server Adds funds to a player's default bank account. This operation does not require the player to be online and can include an optional transaction message. It's useful for recurring payments like salaries. ```lua exports.pefcl:addBankBalanceByIdentifier(source, { identifier = identifier, amount = amount, message = message }) ``` ```javascript await exports.pefcl.addBankBalanceByIdentifier(source, { identifier, amount, message }) ``` ```typescript await exports.pefcl.addBankBalanceByIdentifier(source, { identifier, amount, message }: { identifier: string, amount: number, message?: string }) ``` -------------------------------- ### Deposit Cash to Bank via PEFCL Source: https://projecterror.dev/docs/pefcl/developers/api/server Transfers cash from the player's inventory into their default bank account. Includes an optional transaction message. ```lua exports.pefcl:depositCash(source, { amount = amount, message = message }) ``` ```javascript await exports.pefcl.depositCash(source, { amount, message }) ``` ```typescript await exports.pefcl.depositCash(source: number, { amount, message }: { amount: number, message: string }) ``` -------------------------------- ### Add Player Cash via PEFCL Source: https://projecterror.dev/docs/pefcl/developers/api/server Adds a specified amount of cash to a player's inventory. Requires the player source ID and the amount to be added. ```lua exports.pefcl:addCash(source, amount) ``` ```javascript await exports.pefcl.addCash(source, amount) ``` ```typescript await exports.pefcl.addCash(source: number, amount: number) ``` -------------------------------- ### Check Player Status Source: https://projecterror.dev/docs/npwd/api/server-exports Checks if a specific player or phone number is currently busy on a call. Returns a boolean value. ```lua local isBusy = exports.npwd:isPlayerBusy(source) local isNumberBusy = exports.npwd:isPhoneNumberBusy(phoneNumber) ``` ```javascript const isBusy = exports.npwd.isPlayerBusy(source) const isNumberBusy = exports.npwd.isPhoneNumberBusy(phoneNumber) ``` -------------------------------- ### Configure Twitter Social Media Settings Source: https://projecterror.dev/docs/npwd/configuration/defaults Manages social media features including character limits, media support, and user permissions for tweets. Controls the behavior of notifications, profile editing, and reporting. ```json { "twitter": { "showNotifications": true, "generateProfileNameFromUsers": true, "allowEditableProfileName": true, "allowDeleteTweets": true, "allowReportTweets": true, "allowRetweet": true, "characterLimit": 160, "newLineLimit": 10, "enableAvatars": true, "enableEmojis": true, "enableImages": true, "maxImages": 3 } } ``` -------------------------------- ### Give Cash to Nearest Player via PEFCL Export Source: https://projecterror.dev/docs/pefcl/developers/api/client Transfers a specified amount of cash to the nearest player. Requires an amount parameter. ```lua exports.pefcl:giveNearestPlayerCash(amount) ``` ```javascript exports.pefcl.giveNearestPlayerCash(amount) ``` ```typescript exports.pefcl.giveNearestPlayerCash(amount: number) ``` -------------------------------- ### Check Phone Disabled State with NPWD Client Export Source: https://projecterror.dev/docs/npwd/api/client-exports Retrieves the current disabled state of the phone. This getter function returns a boolean indicating whether the phone is currently disabled and inaccessible to the player. ```Lua local isDisabled = exports.npwd:isPhoneDisabled() ``` ```JavaScript const isDisabled = exports.npwd.isPhoneDisabled() ``` -------------------------------- ### Deposit Money via PEFCL Export Source: https://projecterror.dev/docs/pefcl/developers/api/client Deposits a specified amount into the default account without requiring an ATM interface. ```lua exports.pefcl:depositMoney(amount) ``` ```javascript exports.pefcl.depositMoney(amount) ``` ```typescript exports.pefcl.depositMoney(amount: number) ``` -------------------------------- ### Send UI Message with NPWD Client Export Source: https://projecterror.dev/docs/npwd/api/client-exports Sends a UI message using the NPWD client export. This function is useful for inter-app communication within NPWD, accepting any data payload. It is designed for third-party applications interacting with NPWD's NUI system. ```Lua exports.npwd:sendUIMessage({ type = "EVENT", payload = { dog = "woof", cat = "meow" }}}) ``` ```JavaScript exports.npwd.sendUIMessage({ type: 'EVENT', payload: { dog: 'woof', cat: 'meow' }}) ``` -------------------------------- ### Set Phone Disabled State with NPWD Client Export Source: https://projecterror.dev/docs/npwd/api/client-exports Determines whether the phone is disabled. When disabled, players cannot open the phone or receive notifications. This function accepts a boolean to enable or disable the phone. ```Lua exports.npwd:setPhoneDisabled(true) ``` ```JavaScript exports.npwd.setPhoneDisabled(true) ``` -------------------------------- ### Close Bank UI via PEFCL Export Source: https://projecterror.dev/docs/pefcl/developers/api/client Closes the currently active Bank user interface. ```lua exports.pefcl:closeBank() ``` ```javascript exports.pefcl.closeBank() ``` ```typescript exports.pefcl.closeBank() ``` -------------------------------- ### Remove Bank Balance by Identifier Source: https://projecterror.dev/docs/pefcl/developers/api/server Deducts funds from a player's default bank account. This function can be used without the player being online and supports an optional transaction message. ```lua exports.pefcl:removeBankBalanceByIdentifier(source, { identifier = identifier, amount = amount, message = message }) ``` ```javascript await exports.pefcl.removeBankBalanceByIdentifier(source, { identifier, amount, message }) ``` ```typescript await exports.pefcl.removeBankBalanceByIdentifier(source, { identifier, amount, message }: source: number, { identifier: string, amount: number, message?: string }) ``` -------------------------------- ### Close ATM UI via PEFCL Export Source: https://projecterror.dev/docs/pefcl/developers/api/client Closes the currently active ATM user interface. ```lua exports.pefcl:closeAtm() ``` ```javascript exports.pefcl.closeAtm() ``` ```typescript exports.pefcl.closeAtm() ``` -------------------------------- ### Withdraw Cash from Bank via PEFCL Source: https://projecterror.dev/docs/pefcl/developers/api/server Transfers funds from the player's default bank account into their physical cash. Includes an optional transaction message. ```lua exports.pefcl:withdrawCash(source, { amount = amount, message = message }) ``` ```javascript await exports.pefcl.withdrawCash(source, { amount, message }) ``` ```typescript await exports.pefcl.withdrawCash(source: number, { amount, message }: { amount: number, message: string }) ``` -------------------------------- ### Withdraw Money via PEFCL Export Source: https://projecterror.dev/docs/pefcl/developers/api/client Withdraws a specified amount from the default account without requiring an ATM interface. ```lua exports.pefcl:withdrawMoney(amount) ``` ```javascript exports.pefcl.withdrawMoney(amount) ``` ```typescript exports.pefcl.withdrawMoney(amount: number) ``` -------------------------------- ### Check if In Phone Call with NPWD Client Export Source: https://projecterror.dev/docs/npwd/api/client-exports Determines if the player is currently engaged in a phone call. This getter function returns a boolean value indicating the active call status. ```Lua local isInCall = exports.npwd:isInCall() ``` ```JavaScript const isInCall = exports.npwd.isInCall() ```