This package is available as an npm package.
# npm installation
npm install @project-error/pe-utils
# yarn installation
yarn add @project-error/pe-utils- Promisified net events
- RPC system allowing for remote client calls from the server
- TypeScript wrapped natives allowing for more fluid static typing through generics
- NUI Proxy system that allows for NUI to fetch server side data without breaking the HTTP request
- TypeScript first with declarations generated from source (vanilla JavaScript is still compatible)
- General wrappers to make development easier within the runtime
You can find official examples at this GitHub Repo. These are both in TypeScript as well as regular JavaScript
Inline documentations is also included for almost all of the current functions & methods.
This package adds the ability to utilize promisified net events. Essentially a small promise wrapper around events. When using this system it is wise to keep in mind that events are transmitted over UDP and not TCP, this can lead to issues if a player has poor internet speeds. There is a default timeout of 15 seconds which can be lowered or raised.
Example
// Client Sideimport{ClientUtils,RegisterNuiCB,ServerPromiseResp}from"@project-error/pe-utils";interfaceServerResponseData{data1: number;data2: number;data3: number;}constclUtils=newClientUtils();// NUI Callback wrapped for v8RegisterNuiCB("someCallbackEvent",async(data: unknown,cb: (any)=>void)=>{try{constserverResp=awaitclUtils.emitNetPromise<ServerPromiseResp<ServerResponseData>>("fetchEvent");cb(serverResp);}catch(e){console.error(`Error encountered: ${e.message}`);}});// Server Sideimport{ServerUtils,ServerPromiseResp}from"@project-error/pe-utils";interfaceIncomingData{thing1: string;thing2: number;}interfaceReturnData{respData1: number;respData2: string;}constsvUtils=newServerUtils();svUtils.onNetPromise<RequestData,ReturnData>("fetchEvent",(req,resp)=>{constplayerSrc=req.source;// Do some logic to get resp data on the serverconstrespObj: ServerPromiseResp<ReturnData>={status: "ok",data: {respData1: 12345,respData2: "adadsadasda",},};// Sent back to the client to resolveresp(respObj);});// Client SideinterfaceServerDataObj{coolStuff: string;amICool: boolean;}clientUtils.registerRPCListener<ServerDataObj>("niceEvent",data=>{constplayerPed=PlayerPedId();// This is the optional data sent by the server, you can// use it for logic if neededconsole.dir(data);const[x,y,z]=GetEntityCoords(playerPed,false);// We return an object here to the server with x, y, zreturn{ x, y, z };});// Server SideRegisterCommand("debugTest",async(src: number)=>{try{// Lets call our RPC and print the result. This is a promise, so we must awaitconstcoordObj=awaitsvUtils.callClientRPC<Vector3>("niceEvent",src,{coolStuff: "adadadada",amICool: false,});console.log("Returned data:");console.dir(coordObj);}catch(e){console.error(e);}},false);TODO: Further Explanations