├── .gitignore ├── LICENSE.md ├── README.md ├── classes ├── coords.d.ts ├── esx_client_player_data.d.ts ├── esx_client_ui_menu_data.d.ts ├── esx_client_vehicle_props.d.ts ├── esx_server_account.d.ts ├── esx_server_xplayer.d.ts ├── esx_weapon.d.ts └── weapon.d.ts ├── client ├── esx_client.d.ts ├── esx_client_game.d.ts ├── esx_client_scaleform.d.ts ├── esx_client_streaming.d.ts └── esx_client_ui.d.ts ├── common ├── citizenfx_native.d.ts ├── esx_common.d.ts └── esx_common_math.d.ts ├── npmignore ├── package-lock.json ├── package.json └── server ├── esx_server.d.ts └── esx_xplayer.d.ts /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .idea/ 3 | node_modules/ 4 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2019 Darkotus 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fivem-esx-js 2 | 3 | [![HitCount](http://hits.dwyl.io/GiroudMathias/fivem-esx-js.svg)](http://hits.dwyl.io/GiroudMathias/fivem-esx-js) 4 | [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/GiroudMathias/fivem-esx-js/issues) 5 | 6 | [![https://nodei.co/npm/fivem-esx-js.png?downloads=true&downloadRank=true&stars=true](https://nodei.co/npm/fivem-esx-js.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/fivem-esx-js) 7 | 8 | _Javascript/Typescript wrapper for the FiveM ESX Framework natives._ 9 | 10 | Features based on the [**ESX framework for FiveM**](https://esx-org.github.io/). This module will allow you to fully exploit ESX from your JavaScript/TypeScript developments. 11 | ## Features 12 | 13 | - Two dependencies [@citizenfx/client](https://www.npmjs.com/package/@citizenfx/client) and [fivem-js](https://www.npmjs.com/package/fivem-js) 14 | - Integration of ESX Class (and functions) client and server side 15 | 16 | In other words, whatever the FiveM ESX Lua Framework wrapper can do, this package can as well. 17 | 18 | _Note: Not all features are currently available. They will be added as development continues as well as additional language specific features._ 19 | 20 | ## Usage 21 | 22 | ### Typescript 23 | #### Client side 24 | Create a file "esx.ts" containing: 25 | ```typescript 26 | import {ESXClient} from "fivem-esx-js/client/esx_client"; 27 | 28 | export let ESX: ESXClient; 29 | emit('esx:getSharedObject', (obj) => { 30 | ESX = obj; 31 | }); 32 | ``` 33 | ESX is now available! example on "test.ts": 34 | ```typescript 35 | import {ESX} from "../esx"; 36 | ESX.ShowNotification('Hello World !'); 37 | ``` 38 | 39 | #### Server side 40 | Create a file "esx.ts" containing: 41 | ```typescript 42 | import {ESXServer} from "fivem-esx-js/server/esx_server"; 43 | 44 | export let ESX: ESXServer; 45 | emit('esx:getSharedObject', (obj) => { 46 | ESX = obj; 47 | }); 48 | ``` 49 | ESX is now available! example on "test.ts": 50 | ```typescript 51 | import {ESX} from "../esx"; 52 | let player = ESX.GetPlayerFromId(1); 53 | player.addBank(10000); 54 | ``` 55 | 56 | ### Javascript 57 | TODO 58 | 59 | ### Contributing 60 | 61 | You are more than welcome to contribute to this project by submitting a pull request and creating issues. 62 | 63 | [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/GiroudMathias/fivem-esx-js/issues) 64 | -------------------------------------------------------------------------------- /classes/coords.d.ts: -------------------------------------------------------------------------------- 1 | export declare interface Coords { 2 | x: number, 3 | y: number, 4 | z: number 5 | } 6 | -------------------------------------------------------------------------------- /classes/esx_client_player_data.d.ts: -------------------------------------------------------------------------------- 1 | export declare interface ESXClientPlayerData { 2 | identifier: string, 3 | inventory: ESXClientPlayerInventoryItem[], 4 | loadout: any[], 5 | money: number, 6 | lastPosition: { 7 | x: number, 8 | y: number, 9 | z: number 10 | }, 11 | job: ESXClientPlayerJob, 12 | secondaryJob: ESXClientPlayerJob, 13 | accounts: ESXClientPlayerAccount[] 14 | } 15 | 16 | export declare interface ESXClientPlayerInventoryItem { 17 | count: number, 18 | rare: boolean, 19 | limit: number, 20 | label: string, 21 | name: string, 22 | usable: boolean, 23 | canRemove: boolean 24 | } 25 | 26 | export declare interface ESXClientPlayerJob { 27 | name: string, 28 | grade: number, 29 | grade_name: string, 30 | grade_salary: number, 31 | label: string, 32 | skin_female: any[], 33 | skin_male: any[] 34 | } 35 | 36 | export declare interface ESXClientPlayerAccount { 37 | money: number, 38 | name: string, 39 | label: string 40 | } 41 | -------------------------------------------------------------------------------- /classes/esx_client_ui_menu_data.d.ts: -------------------------------------------------------------------------------- 1 | export declare interface ESXClientUIMenuData { 2 | title: string, 3 | align: string, 4 | elements?: { 5 | label: string, 6 | [key: string]: any 7 | }[], 8 | } 9 | -------------------------------------------------------------------------------- /classes/esx_client_vehicle_props.d.ts: -------------------------------------------------------------------------------- 1 | export declare interface ESXClientVehicleProps { 2 | model?: number, 3 | plate?: string, 4 | plateIndex?: number, 5 | bodyHealth?: number, 6 | engineHealth?: number, 7 | fuelLevel?: number, 8 | dirtLevel?: number, 9 | color1?: number, 10 | color2?: number, 11 | pearlescentColor?: number, 12 | wheelColor?: number, 13 | wheels?: number, 14 | windowTint?: number, 15 | neonEnabled?: [number, number, number, number] 16 | extras?: any, 17 | neonColor?: [number, number, number], 18 | tyreSmokeColor?: [number, number, number], 19 | modSpoilers?: number, 20 | modFrontBumper?: number, 21 | modRearBumper?: number, 22 | modSideSkirt?: number, 23 | modExhaust?: number, 24 | modFrame?: number, 25 | modGrille?: number, 26 | modHood?: number, 27 | modFender?: number, 28 | modRightFender?: number, 29 | modRoof?: number, 30 | modEngine?: number, 31 | modBrakes?: number, 32 | modTransmission?: number, 33 | modHorns?: number, 34 | modSuspension?: number, 35 | modArmor?: number, 36 | modTurbo?: boolean, 37 | modSmokeEnabled?: boolean, 38 | modXenon?: number, 39 | modFrontWheels?: number, 40 | modBackWheels?: number, 41 | modPlateHolder?: number, 42 | modVanityPlate?: number, 43 | modTrimA?: number, 44 | modOrnaments?: number, 45 | modDashboard?: number, 46 | modDial?: number, 47 | modDoorSpeaker?: number, 48 | modSeats?: number, 49 | modSteeringWheel?: number, 50 | modShifterLeavers?: number, 51 | modAPlate?: number, 52 | modSpeakers?: number, 53 | modTrunk?: number, 54 | modHydrolic?: number, 55 | modEngineBlock?: number, 56 | modAirFilter?: number, 57 | modStruts?: number, 58 | modArchCover?: number, 59 | modAerials?: number, 60 | modTrimB?: number, 61 | modTank?: number, 62 | modWindows?: number, 63 | modLivery?: number 64 | } 65 | -------------------------------------------------------------------------------- /classes/esx_server_account.d.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GiroudMathias/fivem-esx-js/4c9010401ddb61a92cb7f8a81c093791dc93da25/classes/esx_server_account.d.ts -------------------------------------------------------------------------------- /classes/esx_server_xplayer.d.ts: -------------------------------------------------------------------------------- 1 | import {Coords} from "./coords"; 2 | 3 | export class ESXServerXPlayer { 4 | name: string; 5 | source: number; 6 | accounts: ESXServerXPlayerAccount[]; 7 | inventory: ESXServerXPlayerInventoryItem[]; 8 | job: ESXServerXPlayerJob; 9 | lastPosition: Coords; 10 | } 11 | export interface ESXServerXPlayerAccount { 12 | name: string, 13 | label: string, 14 | money: number 15 | } 16 | 17 | export interface ESXServerXPlayerInventoryItem { 18 | name: string, 19 | count: number, 20 | label: string, 21 | limit: number, 22 | usable: boolean, 23 | rare: boolean, 24 | canRemove: boolean 25 | } 26 | 27 | export interface ESXServerXPlayerJob { 28 | id: number, 29 | name: string, 30 | type: string, 31 | label: string, 32 | grade: number, 33 | grade_name: string, 34 | grade_label: string, 35 | grade_salary: number, 36 | skin_male: any, 37 | skin_female: any 38 | } -------------------------------------------------------------------------------- /classes/esx_weapon.d.ts: -------------------------------------------------------------------------------- 1 | export interface ESXWeapon { 2 | name: string, 3 | label: string, 4 | components: ESXWeaponComponent[] 5 | } 6 | export interface ESXWeaponComponent { 7 | name: string, 8 | hash: number, 9 | label: string 10 | } -------------------------------------------------------------------------------- /classes/weapon.d.ts: -------------------------------------------------------------------------------- 1 | export interface Weapon { 2 | name: string, 3 | label: string, 4 | components: { 5 | name: string, 6 | hash: number, 7 | label: string 8 | }[] 9 | } 10 | -------------------------------------------------------------------------------- /client/esx_client.d.ts: -------------------------------------------------------------------------------- 1 | import {ESXGame} from "./esx_client_game"; 2 | import {ESXClientUI} from "./esx_client_ui"; 3 | import {ESXStreaming} from "./esx_client_streaming"; 4 | import {ESXClientScaleform} from "./esx_client_scaleform"; 5 | import {ESXCommon} from "../common/esx_common"; 6 | import {ESXClientPlayerData} from "../classes/esx_client_player_data"; 7 | 8 | export as namespace ESXClient; 9 | 10 | export class ESXClient extends ESXCommon{ 11 | /** 12 | * This function gets player data. 13 | */ 14 | GetPlayerData(): ESXClientPlayerData; 15 | 16 | /** 17 | * This function checks if the player is loaded 18 | */ 19 | IsPlayerLoaded(): boolean; 20 | 21 | /** 22 | * This function sets player data. 23 | * @param key 24 | * @param value 25 | */ 26 | SetPlayerData(key: string, value: any); 27 | 28 | /** 29 | * This function shows an advanced notification. See Arguments Explained for an explanation of what each argument does. 30 | * @param title 31 | * @param subject 32 | * @param message 33 | * @param icon 34 | * @param iconType 35 | */ 36 | ShowAdvancedNotification(title: string, subject: string, message: string, icon: string, iconType: number); 37 | 38 | /** 39 | * This function shows a help notification with the parsed message. These help notification support displaying button inputs, see this list 40 | * @param message 41 | */ 42 | ShowHelpNotification(message: string); 43 | 44 | /** 45 | * This function shows the inventory. 46 | */ 47 | ShowInventory(); 48 | 49 | /** 50 | * This function shows a basic notification to the player. 51 | * @param message 52 | */ 53 | ShowNotification(message: string); 54 | 55 | /** 56 | * This function triggers a server callback. 57 | * @param eventName 58 | * @param callback 59 | * @param args 60 | */ 61 | TriggerServerCallback(eventName: string, callback: Function, ...args: any[]); 62 | 63 | Game: ESXGame; 64 | 65 | Scaleform: ESXClientScaleform; 66 | 67 | Streaming: ESXStreaming; 68 | 69 | UI: ESXClientUI; 70 | 71 | GetWeaponLabel(weaponName: string): string; 72 | GetWeaponList(): any[] 73 | } 74 | -------------------------------------------------------------------------------- /client/esx_client_game.d.ts: -------------------------------------------------------------------------------- 1 | import {Coords} from "../classes/coords"; 2 | import {ESXClientVehicleProps} from "../classes/esx_client_vehicle_props"; 3 | 4 | export declare class ESXGame { 5 | /** 6 | * This function deletes an object. 7 | * @param object 8 | */ 9 | DeleteObject(object: number); 10 | 11 | /** 12 | * This function deletes the parsed vehicle. 13 | * @param vehicle 14 | */ 15 | DeleteVehicle(vehicle: number); 16 | 17 | /** 18 | * This function gets the closest object. 19 | * @param filter 20 | * @param coords 21 | */ 22 | GetClosestObject(filter: string | string[], coords: Coords): [number, number]; 23 | 24 | /** 25 | * This function gets the closest ped. 26 | * @param coords 27 | * @param ignoreList 28 | */ 29 | GetClosestPed(coords: Coords, ignoreList?: string[]): [number, number]; 30 | 31 | /** 32 | * This function gets the closest player. 33 | * @param coords 34 | */ 35 | GetClosestPlayer(coords: Coords): [number, number]; 36 | 37 | /** 38 | * This function gets the closest vehicle. 39 | * @param coords 40 | */ 41 | GetClosestVehicle(coords: Coords): [number, number]; 42 | 43 | /** 44 | * This function gets objects. 45 | */ 46 | GetObjects(): [number]; 47 | 48 | /** 49 | * This function generates a Mugshot of the current player usable in various applications. 50 | * @param ped 51 | */ 52 | GetPedMugshot(ped: number): [number, string]; 53 | 54 | /** 55 | * This function gets peds. 56 | * @param ignoreList 57 | */ 58 | GetPeds(ignoreList: string[]): number[]; 59 | 60 | /** 61 | * This function gets players. 62 | */ 63 | GetPlayers(): number[]; 64 | 65 | /** 66 | * This function gets players in a given radius. 67 | * @param coords 68 | * @param radius 69 | */ 70 | GetPlayersInArea(coords: Coords, radius: number): number[]; 71 | 72 | /** 73 | * This function gets the closest vehicle in the players' direction within 5 units, utilizes ray-casts. 74 | */ 75 | GetVehicleInDirection(): number; 76 | 77 | /** 78 | * This function gets a vehicles properties. 79 | * @param vehicle 80 | */ 81 | GetVehicleProperties(vehicle: number): ESXClientVehicleProps; 82 | 83 | /** 84 | * This function gets vehicles. 85 | * @constructor 86 | */ 87 | GetVehicles(): number[]; 88 | 89 | /** 90 | * This function gets vehicles in a given radius. 91 | * @param coords 92 | * @param radius 93 | */ 94 | GetVehiclesInArea(coords: Coords, radius: number): number[]; 95 | 96 | /** 97 | * Returns (boolean) if the spawn point coords area clear with no other vehicle in the parsed radius. 98 | * @param coords 99 | * @param radius 100 | */ 101 | IsSpawnPointClear(coords: Coords, radius: number): boolean; 102 | 103 | /** 104 | * This function sets the properties for a vehicle. 105 | * @param vehicle 106 | * @param props 107 | */ 108 | SetVehicleProperties(vehicle: number, props: ESXClientVehicleProps); 109 | 110 | /** 111 | * This function spawns a local object, only visible to the local player and no one else. 112 | * @param modelOrHash 113 | * @param coords 114 | * @param callback 115 | */ 116 | SpawnLocalObject(modelOrHash: number | string, coords: Coords, callback?: Function); 117 | 118 | /** 119 | * This function spawns a local vehicle, only visible to the local player and no one else. 120 | * @param modelOrHash 121 | * @param coords 122 | * @param heading 123 | * @param callback 124 | */ 125 | SpawnLocalVehicle(modelOrHash: number | string, coords: Coords, heading: number, callback?: Function); 126 | 127 | /** 128 | * This function spawns an object. 129 | * @param modelOrHash 130 | * @param coords 131 | * @param callback 132 | */ 133 | SpawnObject(modelOrHash: number | string, coords: Coords, callback?: Function); 134 | 135 | /** 136 | * This function spawns a vehicle. 137 | * @param modelOrHash 138 | * @param coords 139 | * @param heading 140 | * @param callback 141 | */ 142 | SpawnVehicle(modelOrHash: number | string, coords: Coords, heading: number, callback?: Function); 143 | 144 | /** 145 | * This function teleports an entity. 146 | * @param entity 147 | * @param coords 148 | * @param callback 149 | */ 150 | Teleport(entity: number, coords: Coords, callback?: Function); 151 | 152 | Utils: ESXGameUtil; 153 | } 154 | 155 | declare class ESXGameUtil { 156 | /** 157 | * This function draws 3D text. 158 | * @param coords 159 | * @param text 160 | * @param size 161 | */ 162 | DrawText3D(coords: Coords, text: string, size: number); 163 | } 164 | -------------------------------------------------------------------------------- /client/esx_client_scaleform.d.ts: -------------------------------------------------------------------------------- 1 | export declare class ESXClientScaleform { 2 | /** 3 | * This function shows the 'Breaking News' scaleform used multiple times in the campaign. 4 | * The msg and bottom variables support HTML. 5 | * @param title 6 | * @param message 7 | * @param bottom 8 | * @param seconds 9 | */ 10 | ShowBreakingNews(title: string, message: string, bottom: string, seconds: number); 11 | 12 | /** 13 | * This function displays a freemode message for the player. 14 | * @param title 15 | * @param message 16 | * @param seconds 17 | */ 18 | ShowFreemodeMessage(title: string, message: string, seconds: number); 19 | 20 | /** 21 | * This function shows a basic popup warning, like the quit confirmation warning. 22 | * @param title 23 | * @param message 24 | * @param bottom 25 | * @param seconds 26 | */ 27 | ShowPopupWarning(title: string, message: string, bottom: string, seconds: number); 28 | 29 | /** 30 | * This function starts the traffic scaleform movie used in the campaign. 31 | * @param seconds 32 | */ 33 | ShowTrafficMovie(seconds: number); 34 | 35 | Utils: ESXClientScaleformUtils; 36 | } 37 | 38 | declare class ESXClientScaleformUtils { 39 | /** 40 | * This function requests and returns the scaleform movie parsed. 41 | * Here's a list of available scaleforms. 42 | * @param movie 43 | */ 44 | RequestScaleformMovie(movie: string); 45 | } 46 | -------------------------------------------------------------------------------- /client/esx_client_streaming.d.ts: -------------------------------------------------------------------------------- 1 | export declare class ESXStreaming { 2 | /** 3 | * This function requests and returns the animation directory parsed. A very common usage it to play animations using TaskPlayAnim(). You can use Alex Guirre's Animations List found on Github. 4 | * @param animDict 5 | * @param callback 6 | */ 7 | RequestAnimDict(animDict: string, callback?: Function); 8 | 9 | /** 10 | * This function requests and returns the animation set parsed. Animation sets provide movement styles, commonly used with SetPedMovementClipset(). 11 | * @param animSet 12 | * @param callback 13 | */ 14 | RequestAnimSet(animSet: string, callback?: Function); 15 | 16 | /** 17 | * This function requests and returns the specified model parsed, a very common usage is spawning objects, etc. 18 | * @param model 19 | * @param callback 20 | */ 21 | RequestModel(model: number | string, callback?: Function); 22 | 23 | /** 24 | * 25 | * @param assetName 26 | * @param callback 27 | */ 28 | RequestNamedPtfxAsset(assetName: string, callback?: Function); 29 | 30 | /** 31 | * This function requests and returns the texture directory parsed. This is commonly used when loading sprites, then draw them on screen using DrawSprite(), an example would be drawing a speedometer. 32 | * @param textureDict 33 | * @param callback 34 | */ 35 | RequestStreamedTextureDict(textureDict: string, callback?: Function); 36 | 37 | /** 38 | * 39 | * @param weaponHash 40 | * @param callback 41 | */ 42 | RequestWeaponAsset(weaponHash: number | string, callback?: Function); 43 | } 44 | -------------------------------------------------------------------------------- /client/esx_client_ui.d.ts: -------------------------------------------------------------------------------- 1 | import {ESXClientUIMenuData} from "../classes/esx_client_ui_menu_data"; 2 | 3 | export declare class ESXClientUI { 4 | 5 | /** 6 | * This function shows an inventory item notification. 7 | * @param add 8 | * @param item 9 | * @param count 10 | */ 11 | ShowInventoryItemNotification(add: string, item: string, count: number); 12 | 13 | HUD: ESXClientUIHUD; 14 | 15 | Menu: ESXClientUIMenu; 16 | } 17 | 18 | declare class ESXClientUIHUD { 19 | /** 20 | * This function registers a HUD element. 21 | * @param name 22 | * @param index 23 | * @param priority 24 | * @param html 25 | * @param data 26 | */ 27 | RegisterElement(name: string, index: number, priority: number, html: string, data: string); 28 | 29 | /** 30 | * This function removes a HUD element. 31 | * @param name 32 | */ 33 | RemoveElement(name: string); 34 | 35 | /** 36 | * This function sets the HUD opacity. 37 | * @param opacity 38 | */ 39 | SetDisplay(opacity: number); 40 | 41 | /** 42 | * This function updates HUD elements. 43 | * @param name 44 | * @param data 45 | */ 46 | UpdateElement(name: string, data: string); 47 | } 48 | 49 | declare class ESXClientUIMenu { 50 | /** 51 | * This function closes a menu. 52 | * @param type 53 | * @param namespace 54 | * @param name 55 | */ 56 | Close(type: string, namespace: string, name: string); 57 | 58 | /** 59 | * This function closes all open menus. 60 | * @constructor 61 | */ 62 | CloseAll(); 63 | 64 | /** 65 | * This function gets all opened menus. 66 | * @param type 67 | * @param namespace 68 | * @param name 69 | */ 70 | GetOpened(type: string, namespace: string, name: string): ESXClientUIMenuData; 71 | 72 | /** 73 | * This function checks if a menu is open. 74 | * @param type 75 | * @param namespace 76 | * @param name 77 | */ 78 | IsOpen(type: string, namespace: string, name: string): ESXClientUIMenuData; 79 | 80 | /** 81 | * This function opens a menu. 82 | * @param type 83 | * @param namespace 84 | * @param name 85 | * @param data 86 | * @param submit 87 | * @param cancel 88 | * @param change 89 | * @param close 90 | */ 91 | Open(type: string, namespace: string, name: string, data: ESXClientUIMenuData, submit: Function, cancel: Function, change?: Function, close?: Function); 92 | 93 | /** 94 | * This function registers a menu type. 95 | * @param type 96 | * @param open 97 | * @param close 98 | */ 99 | RegisterType(type: string, open: Function, close: Function); 100 | } 101 | -------------------------------------------------------------------------------- /common/citizenfx_native.d.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GiroudMathias/fivem-esx-js/4c9010401ddb61a92cb7f8a81c093791dc93da25/common/citizenfx_native.d.ts -------------------------------------------------------------------------------- /common/esx_common.d.ts: -------------------------------------------------------------------------------- 1 | import {ESXWeapon, ESXWeaponComponent} from "../classes/esx_weapon"; 2 | import {ESXCommonMath} from "./esx_common_math"; 3 | 4 | export class ESXCommon { 5 | /** 6 | * This function gets a random string, with the defined length. 7 | * @param length 8 | */ 9 | GetRandomString(length: number): string; 10 | 11 | /** 12 | * This function returns the weapon component object for a weapon. Includes the component label, name and hash key. See the weapon config file for the available components. 13 | * @param weaponName 14 | * @param weaponComponent 15 | */ 16 | GetWeaponComponent(weaponName: string, weaponComponent: string): ESXWeaponComponent; 17 | 18 | /** 19 | * This function gets the weapon label for a given weapon. 20 | * @param weaponName 21 | */ 22 | GetWeaponLabel(weaponName: string): string; 23 | 24 | /** 25 | * This function gets the complete weapon list and label. 26 | */ 27 | GetWeaponList(): ESXWeapon[]; 28 | 29 | /** 30 | * This function sets a timeout requiring two arguments, msec (milliseconds), and cb (callback). 31 | * @param milliseconds 32 | * @param callback 33 | */ 34 | SetTimeout(milliseconds: number, callback: Function); 35 | 36 | /** 37 | * This function clears a timeout from the ESX.SetTimeout function. 38 | * @param id 39 | */ 40 | ClearTimeout(id: number); 41 | 42 | Math: ESXCommonMath; 43 | } -------------------------------------------------------------------------------- /common/esx_common_math.d.ts: -------------------------------------------------------------------------------- 1 | export class ESXCommonMath { 2 | /** 3 | * This function groups numbers, making them easier to understand by humans. Used in most nofications when money is showed, for example when buying a new car at the vehicle shop. 4 | * @param number 5 | */ 6 | GroupDigits(number: number): string; 7 | 8 | /** 9 | * This function rounds off a number, and optionally you can parse how many decimals you want (defaults to 0) 10 | * @param value 11 | * @param numDecimalPlaces 12 | */ 13 | Round(value: number, numDecimalPlaces?: number): number; 14 | 15 | /** 16 | * This function trims an text, removing all trailing whitespaces. Often used when sanitizing the GetVehicleNumberPlateText() native. 17 | * @param value 18 | */ 19 | Trim(value: string): string; 20 | } -------------------------------------------------------------------------------- /npmignore: -------------------------------------------------------------------------------- 1 | tsconfig.json 2 | src 3 | .git 4 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fivem-esx-js", 3 | "version": "0.1.17", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "fivem-esx-js", 9 | "version": "0.1.17", 10 | "license": "MIT", 11 | "dependencies": { 12 | "@citizenfx/client": "^1.0.1971-1", 13 | "@citizenfx/server": "^1.0.1971-1", 14 | "fivem-js": "^1.3.1" 15 | } 16 | }, 17 | "node_modules/@citizenfx/client": { 18 | "version": "1.0.1971-1", 19 | "resolved": "https://npm.monaco-rp.com/@citizenfx%2fclient/-/client-1.0.1971-1.tgz", 20 | "integrity": "sha512-cKrGoRIdCAZpdwL4fyHNE2vjDRobxoEACkcguIkz8IIHXN10dsfUbSZp8KIFDhc6ee+XGnoWIDD2lk4rvD7/eg==" 21 | }, 22 | "node_modules/@citizenfx/server": { 23 | "version": "1.0.1971-1", 24 | "resolved": "https://npm.monaco-rp.com/@citizenfx%2fserver/-/server-1.0.1971-1.tgz", 25 | "integrity": "sha512-YvEQAHSc5633UKF7LdUeFtWn4w3qNK5iWJyAyjNwUhygBczAIYZELSZVANcoTwsEIdI+eBbI7EPrQ8RsB1lQHA==" 26 | }, 27 | "node_modules/fivem-js": { 28 | "version": "1.3.1", 29 | "resolved": "https://registry.npmjs.org/fivem-js/-/fivem-js-1.3.1.tgz", 30 | "integrity": "sha512-HjSKvwwEckWIXk/VeRWkCiEs9Cq344sNzHIH2pyKWT2oBLbpMCqTtetoSfCbdm68lAm5E34VWUc/J54hjRsJYg==", 31 | "dependencies": { 32 | "@citizenfx/client": "^1.0.1626-1" 33 | } 34 | }, 35 | "node_modules/fivem-js/node_modules/@citizenfx/client": { 36 | "version": "1.0.1626-1", 37 | "resolved": "https://registry.npmjs.org/@citizenfx/client/-/client-1.0.1626-1.tgz", 38 | "integrity": "sha512-EkjTzvQnfysjJfr2+xWIS43+dZknInICYU7AjvbCr5up9ALmuGgqlOBiwm6mftBK5T9pk2n0KYhWFU1+YTwSSg==" 39 | } 40 | }, 41 | "dependencies": { 42 | "@citizenfx/client": { 43 | "version": "1.0.1971-1", 44 | "resolved": "https://npm.monaco-rp.com/@citizenfx%2fclient/-/client-1.0.1971-1.tgz", 45 | "integrity": "sha512-cKrGoRIdCAZpdwL4fyHNE2vjDRobxoEACkcguIkz8IIHXN10dsfUbSZp8KIFDhc6ee+XGnoWIDD2lk4rvD7/eg==" 46 | }, 47 | "@citizenfx/server": { 48 | "version": "1.0.1971-1", 49 | "resolved": "https://npm.monaco-rp.com/@citizenfx%2fserver/-/server-1.0.1971-1.tgz", 50 | "integrity": "sha512-YvEQAHSc5633UKF7LdUeFtWn4w3qNK5iWJyAyjNwUhygBczAIYZELSZVANcoTwsEIdI+eBbI7EPrQ8RsB1lQHA==" 51 | }, 52 | "fivem-js": { 53 | "version": "1.3.1", 54 | "resolved": "https://registry.npmjs.org/fivem-js/-/fivem-js-1.3.1.tgz", 55 | "integrity": "sha512-HjSKvwwEckWIXk/VeRWkCiEs9Cq344sNzHIH2pyKWT2oBLbpMCqTtetoSfCbdm68lAm5E34VWUc/J54hjRsJYg==", 56 | "requires": { 57 | "@citizenfx/client": "^1.0.1626-1" 58 | }, 59 | "dependencies": { 60 | "@citizenfx/client": { 61 | "version": "1.0.1626-1", 62 | "resolved": "https://registry.npmjs.org/@citizenfx/client/-/client-1.0.1626-1.tgz", 63 | "integrity": "sha512-EkjTzvQnfysjJfr2+xWIS43+dZknInICYU7AjvbCr5up9ALmuGgqlOBiwm6mftBK5T9pk2n0KYhWFU1+YTwSSg==" 64 | } 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fivem-esx-js", 3 | "version": "0.1.17", 4 | "description": "Javascript/Typescript wrapper for the FiveM ESX core natives", 5 | "dependencies": { 6 | "@citizenfx/client": "^1.0.1971-1", 7 | "@citizenfx/server": "^1.0.1971-1", 8 | "fivem-js": "^1.3.1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/GiroudMathias/fivem-esx-js.git" 13 | }, 14 | "keywords": [ 15 | "fivem", 16 | "wrapper", 17 | "esx", 18 | "citizenfx", 19 | "typescript", 20 | "javascript" 21 | ], 22 | "bugs": { 23 | "url": "https://github.com/GiroudMathias/fivem-esx-js/issues" 24 | }, 25 | "homepage": "https://github.com/GiroudMathias/fivem-esx-js#readme", 26 | "author": "Giroud Mathias ", 27 | "license": "MIT" 28 | } 29 | -------------------------------------------------------------------------------- /server/esx_server.d.ts: -------------------------------------------------------------------------------- 1 | import {ESXCommon} from "../common/esx_common"; 2 | import {ESXPlayer} from "./esx_xplayer"; 3 | 4 | export as namespace ESXServer; 5 | 6 | export class ESXServer extends ESXCommon { 7 | /** 8 | * This function creates a pickup. 9 | * @param type 10 | * @param name 11 | * @param count 12 | * @param label 13 | * @param player 14 | */ 15 | CreatePickup(type: string, name: string, count: number, label: string, player: number); 16 | 17 | /** 18 | * This function returns the item label. 19 | * @param itemName 20 | */ 21 | GetItemLabel(itemName: string): string; 22 | 23 | /** 24 | * This function gets a player from the ID. 25 | * @param source 26 | */ 27 | GetPlayerFromId(source: number): ESXPlayer; 28 | 29 | /** 30 | * This function gets a player from the identifier. 31 | * @param identifier 32 | */ 33 | GetPlayerFromIdentifier(identifier: string): ESXPlayer; 34 | 35 | /** 36 | * This function returns an array of all online players ID's. 37 | * You can use this to access each players data. 38 | */ 39 | GetPlayers(): number[]; 40 | 41 | /** 42 | * This function registers a server callback. 43 | * @param name 44 | * @param callback 45 | */ 46 | RegisterServerCallback(name: string, callback?: Function); 47 | 48 | /** 49 | * This function registers a usable item. 50 | * @param itemName 51 | * @param callback 52 | */ 53 | RegisterUsableItem(itemName: string, callback?: Function); 54 | 55 | /** 56 | * This function saves a player. 57 | * @param xPlayer 58 | * @param callback 59 | */ 60 | SavePlayer(xPlayer: ESXPlayer, callback?: Function); 61 | 62 | /** 63 | * This function saves players. 64 | * @param callback 65 | */ 66 | SavePlayers(callback?: Function); 67 | 68 | /** 69 | * This function shows a debug line if Config.EnableDebug is true. 70 | * @param message 71 | */ 72 | Trace(message: string); 73 | 74 | /** 75 | * This function uses an item. 76 | * @param itemName 77 | * @param source 78 | */ 79 | UseItem(itemName: string, source:number); 80 | } 81 | -------------------------------------------------------------------------------- /server/esx_xplayer.d.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ESXServerXPlayer, 3 | ESXServerXPlayerAccount, 4 | ESXServerXPlayerInventoryItem, 5 | ESXServerXPlayerJob 6 | } from "../classes/esx_server_xplayer"; 7 | import {Coords} from "../classes/coords"; 8 | import {ESXWeapon} from "../classes/esx_weapon"; 9 | 10 | export class ESXPlayer extends ESXServerXPlayer { 11 | /** 12 | * This function adds account money. 13 | * @param account 14 | * @param money 15 | */ 16 | addAccountMoney(account: string, money: number); 17 | 18 | /** 19 | * This function adds bank money. 20 | * @param money 21 | */ 22 | addBank(money: number); 23 | 24 | /** 25 | * This function adds an inventory item. 26 | * @param item 27 | * @param count 28 | */ 29 | addInventoryItem(item: string, count: number); 30 | 31 | /** 32 | * This function adds money. 33 | * @param money 34 | */ 35 | addMoney(money: number); 36 | 37 | /** 38 | * This function adds a weapon. 39 | * @param weaponName 40 | * @param ammo 41 | */ 42 | addWeapon(weaponName: string, ammo?: number); 43 | 44 | /** 45 | * This function adds a weapon component to a weapon, if the player has it. 46 | * The available component list can be found in the weapon config file. 47 | * @param weaponName 48 | * @param weaponComponent 49 | */ 50 | addWeaponComponent(weaponName: string, weaponComponent: string); 51 | 52 | /** 53 | * This function displays bank money. 54 | * @param money 55 | */ 56 | displayBank(money: number); 57 | 58 | /** 59 | * This function displays money. 60 | * @param money 61 | */ 62 | displayMoney(money: number); 63 | 64 | /** 65 | * This function set a xPlayer variable. 66 | * @param key key to set 67 | * @param value value to set 68 | */ 69 | set(key: string, value: T); 70 | 71 | /** 72 | * This function gets a xPlayer variable. 73 | * @param key key to get 74 | */ 75 | get(key: string): T; 76 | 77 | /** 78 | * This function gets an account. 79 | * @param name 80 | */ 81 | getAccount(name: string): ESXServerXPlayerAccount; 82 | 83 | /** 84 | * This function gets accounts. 85 | */ 86 | getAccounts(): ESXServerXPlayerAccount[]; 87 | 88 | /** 89 | * This function gets bank balance. 90 | */ 91 | getBank(): number; 92 | 93 | /** 94 | * This function gets coordinates. 95 | */ 96 | getCoords(): Coords; 97 | 98 | /** 99 | * This function gets a group. 100 | */ 101 | getGroup(): string; 102 | 103 | /** 104 | * This function displays gets an identifier. 105 | */ 106 | getIdentifier(): string; 107 | 108 | /** 109 | * This functions gets inventory. 110 | */ 111 | getInventory(): ESXServerXPlayerInventoryItem[]; 112 | 113 | /** 114 | * This function gets an inventory item. 115 | * @param itemName 116 | */ 117 | getInventoryItem(itemName: string): ESXServerXPlayerInventoryItem; 118 | 119 | /** 120 | * This function gets a job. 121 | */ 122 | getJob(): ESXServerXPlayerJob; 123 | 124 | /** 125 | * This function gets a job. 126 | */ 127 | getSecondaryJob(): ESXServerXPlayerJob; 128 | 129 | /** 130 | * This functions gets the last position of stuff. 131 | */ 132 | getLastPosition(): Coords; 133 | 134 | /** 135 | * This function gets a loadout. 136 | */ 137 | getLoadout(): ESXWeapon[]; 138 | 139 | /** 140 | * This function gets missing accounts. 141 | */ 142 | getMissingAccounts(): ESXServerXPlayerAccount[]; 143 | 144 | /** 145 | * This function gets money. 146 | */ 147 | getMoney(): number; 148 | 149 | /** 150 | * This function gets a name. 151 | */ 152 | getName(): string; 153 | 154 | /** 155 | * This function gets a permission level. 156 | */ 157 | getPermissions(): number; 158 | 159 | /** 160 | * This function gets the EssentialMode player object. 161 | */ 162 | getPlayer(): ESXPlayer; 163 | 164 | /** 165 | * This function gets a session variable. 166 | * @param key 167 | */ 168 | getSessionVar(key: string): string; 169 | 170 | /** 171 | * This functions returns if the loadoutNum and a weapon object for the weapon if the player has it. 172 | * @param weaponName 173 | */ 174 | getWeapon(weaponName: string): ESXWeapon; 175 | 176 | /** 177 | * This functions returns if the player has the specified weapon. 178 | * @param weaponName 179 | */ 180 | hasWeapon(weaponName: string): boolean; 181 | 182 | /** 183 | * This functions returns (boolean) if the player has the specified weapon component for a given weapon.The available component list can be found in the weapon config file. 184 | * @param weaponName 185 | * @param weaponComponent 186 | */ 187 | hasWeaponComponent(weaponName: string, weaponComponent: string): boolean; 188 | 189 | /** 190 | * This function kicks a player with a reason. 191 | * @param reason 192 | */ 193 | kick(reason: string); 194 | 195 | /** 196 | * This function removes account money. 197 | * @param account 198 | * @param money 199 | */ 200 | removeAccountMoney(account: string, money: number); 201 | 202 | /** 203 | * This function removes bank money. 204 | * @param money 205 | */ 206 | removeBank(money: number); 207 | 208 | /** 209 | * This function removes an inventory item. 210 | * @param itemName 211 | * @param count 212 | */ 213 | removeInventoryItem(itemName: string, count:number); 214 | 215 | /** 216 | * This function removes money. 217 | * @param money 218 | */ 219 | removeMoney(money: number); 220 | 221 | /** 222 | * This function removes a weapon from the player. 223 | * @param weaponName 224 | * @param ammo 225 | */ 226 | removeWeapon(weaponName: string, ammo?: number); 227 | 228 | /** 229 | * This function removes a weapon component from a player, if the player has it.The available component list can be found in the weapon config file. 230 | * @param weaponName 231 | * @param weaponComponent 232 | */ 233 | removeWeaponComponent(weaponName: string, weaponComponent: string); 234 | 235 | /** 236 | * This function sets account money. 237 | * @param accountName 238 | * @param money 239 | */ 240 | setAccountMoney(accountName: string, money: number); 241 | 242 | /** 243 | * This function sets bank balance. 244 | * @param money 245 | */ 246 | setBankBalance(money: number); 247 | 248 | /** 249 | * This function sets coordinates. 250 | * @param x 251 | * @param y 252 | * @param z 253 | */ 254 | setCoords(x: number, y: number, z: number); 255 | 256 | /** 257 | * 258 | * @param itemName 259 | * @param count 260 | */ 261 | setInventoryItem(itemName: string, count: number); 262 | 263 | /** 264 | * This functions sets a job for a player. 265 | * @param name 266 | * @param grade 267 | */ 268 | setJob(name: string, grade: number); 269 | 270 | /** 271 | * This functions sets a secondary job for a player. 272 | * @param name 273 | * @param grade 274 | */ 275 | setSecondaryJob(name: string, grade: number); 276 | 277 | /** 278 | * This function sets money. 279 | * @param money 280 | */ 281 | setMoney(money: number); 282 | 283 | /** 284 | * This function sets the player name. 285 | * @param name 286 | */ 287 | setName(name: string); 288 | 289 | /** 290 | * This function sets a permission level. 291 | * @param permissionLevel 292 | */ 293 | setPermissions(permissionLevel: number); 294 | 295 | /** 296 | * This function sets a session variable. 297 | * @param key 298 | * @param value 299 | */ 300 | setSessionVar(key: string, value: string); 301 | 302 | /** 303 | * This function sends a help notification to the player. These help notification support displaying button inputs, see this list 304 | * https://pastebin.com/HPg8pYwi 305 | * @param msg 306 | */ 307 | showHelpNotification(msg: string); 308 | 309 | /** 310 | * This function sends a notification to the player 311 | * @param msg 312 | */ 313 | showNotification(msg: string); 314 | } 315 | --------------------------------------------------------------------------------