diff --git a/docs/utilities/console-commands.md b/docs/utilities/console-commands.md new file mode 100644 index 000000000..0384f5d45 --- /dev/null +++ b/docs/utilities/console-commands.md @@ -0,0 +1,24 @@ +# Console Commands + +Console commands are commands that can be ran by opening your client-side `F8` console menu and typing a command. + +```sh +pos # Get local player position +floorpos # Get floor position at local player position +vehpos # Get vehicle position +rot # Get local player rotation +vehrot # Get vehicle rotation +dimension # Get local player dimension +weapons # Get local player equipped weapon hashes +weapon # Get local player weapon +id # Get local player id +remoteid # Get local player remote id +resources # Get loaded resources +ping # Get local player ping +fps # Get local player fps +debug #Check if debug is on +players # Get closest players +objects # Get closest objects +entities # Get closeset entities (Like virtual entities) +vehicles # Get closest vehicles +``` diff --git a/docs/utilities/index.yml b/docs/utilities/index.yml new file mode 100644 index 000000000..9a4910216 --- /dev/null +++ b/docs/utilities/index.yml @@ -0,0 +1,3 @@ +expanded: true +label: 'Utilities' +order: -1001 diff --git a/docs/webview/composables/index.yml b/docs/webview/composables/index.yml new file mode 100644 index 000000000..576c50669 --- /dev/null +++ b/docs/webview/composables/index.yml @@ -0,0 +1,3 @@ +expanded: false +label: 'Composables' +order: -1000 diff --git a/src/main/client/system/consoleCommand.ts b/src/main/client/system/consoleCommand.ts new file mode 100644 index 000000000..e4cb2a0ec --- /dev/null +++ b/src/main/client/system/consoleCommand.ts @@ -0,0 +1,124 @@ +import * as alt from 'alt-client'; +import { distance2d } from '../../shared/utility/vector.js'; + +const Commands = { + pos: () => { + return alt.Player.local.pos; + }, + floorpos: () => { + return alt.Player.local.pos.sub(0, 0, 1); + }, + vehpos: () => { + return alt.Player.local.vehicle ? alt.Player.local.vehicle.pos : 'Not in a vehicle.'; + }, + rot: () => { + return alt.Player.local.rot; + }, + vehrot: () => { + return alt.Player.local.vehicle ? alt.Player.local.vehicle.rot : 'Not in a vehicle.'; + }, + dimension: () => { + return alt.Player.local.dimension; + }, + weapons: () => { + return alt.Player.local.weapons; + }, + weapon: () => { + return alt.Player.local.currentWeapon; + }, + id: () => { + return alt.Player.local.id; + }, + remoteid: () => { + return alt.Player.local.remoteID; + }, + resources: () => { + if (!alt.debug) { + return 'Unavailable'; + } + + return alt.getAllResources(); + }, + ping: () => { + return alt.getPing(); + }, + fps: () => { + return alt.getFps(); + }, + debug: () => { + return alt.debug; + }, + players: () => { + if (!alt.debug) { + return 'Unavailable'; + } + + return alt.Player.all.map((x) => { + const dist = distance2d(alt.Player.local.pos, x.pos); + return { id: x.id, dimension: x.dimension, dist, pos: x.pos }; + }); + }, + objects: () => { + if (!alt.debug) { + return 'Unavailable'; + } + + return alt.Object.all.map((x) => { + const dist = distance2d(alt.Player.local.pos, x.pos); + return { id: x.id, dimension: x.dimension, dist, pos: x.pos, model: x.model }; + }); + }, + entities: () => { + if (!alt.debug) { + return 'Unavailable'; + } + + return JSON.stringify( + alt.VirtualEntity.all.map((x) => { + const dist = distance2d(alt.Player.local.pos, x.pos); + const keys = x.getStreamSyncedMetaKeys(); + + const data = {}; + for (let key of keys) { + data[key] = x.getStreamSyncedMeta(key); + } + + return { id: x.id, dimension: x.dimension, dist, pos: x.pos, data }; + }), + null, + '\t' + ); + }, + vehicles: () => { + if (!alt.debug) { + return 'Unavailable'; + } + + return alt.Vehicle.all.map((x) => { + const dist = distance2d(alt.Player.local.pos, x.pos); + return { id: x.id, dimension: x.dimension, dist, pos: x.pos, model: x.model }; + }); + }, +}; + +function handleConsoleCommand(name: string, ...args: string[]) { + name = name.toLowerCase(); + if (!Commands[name]) { + alt.log(`That command does not exist.`); + alt.log(`Here are the supported commands:`); + for (let key of Object.keys(Commands)) { + alt.log(key); + } + return; + } + + const result = Commands[name](...args); + if (!result) { + return; + } + + alt.log(`${name} - Command Result`); + alt.log(result); +} + +alt.on('consoleCommand', handleConsoleCommand); diff --git a/src/main/client/system/index.ts b/src/main/client/system/index.ts index 7bc2936fc..e0c2896a1 100644 --- a/src/main/client/system/index.ts +++ b/src/main/client/system/index.ts @@ -1,5 +1,6 @@ import * as alt from 'alt-client'; +import './consoleCommand.js'; import './native.js'; import './notification.js'; import './stats.js'; diff --git a/src/main/client/webview/index.ts b/src/main/client/webview/index.ts index fe46b91fe..c05a6c90d 100644 --- a/src/main/client/webview/index.ts +++ b/src/main/client/webview/index.ts @@ -11,7 +11,6 @@ let cursorCount: number = 0; let isPageOpen = false; let openPages: PageNames[] = []; - function handleServerEvent(event: string, ...args: any[]) { alt.emitServer(event, ...args); } @@ -139,7 +138,7 @@ export function useWebview(path = 'http://assets/webview/index.html') { isPageOpen = false; webview.emit(Events.view.hide, vueName); unfocus(); - const index = openPages.findIndex(page => page === vueName); + const index = openPages.findIndex((page) => page === vueName); if (index > -1) openPages.splice(index, 1); } @@ -163,12 +162,12 @@ export function useWebview(path = 'http://assets/webview/index.html') { /** * Check if specific page is open. - * + * * @param {PageNames} vueName * @returns {boolean} */ function isSpecificPageOpen(vueName: PageNames): boolean { - return openPages.findIndex(page => page === vueName) > -1; + return openPages.findIndex((page) => page === vueName) > -1; } if (!isInitialized) {