mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 15:06:02 +01:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5fdd8a160 | ||
|
|
ba790f9830 | ||
|
|
9ec43862a2 | ||
|
|
2d2575963d | ||
|
|
8039539158 | ||
|
|
f59beb2af6 | ||
|
|
ab0dac8fde | ||
|
|
4491ad3599 | ||
|
|
a9728663ca |
12
.github/actions/bump-manifest-version.js
vendored
12
.github/actions/bump-manifest-version.js
vendored
@@ -1,10 +1,8 @@
|
|||||||
const fs = require('fs');
|
const fxManifest = await Bun.file('./fxmanifest.lua').text();
|
||||||
|
|
||||||
const version = process.env.TGT_RELEASE_VERSION;
|
let newVersion = process.env.TGT_RELEASE_VERSION;
|
||||||
const newVersion = version.replace('v', '');
|
newVersion = newVersion.replace('v', '')
|
||||||
|
|
||||||
const manifestFile = fs.readFileSync('fxmanifest.lua', { encoding: 'utf8' });
|
const newFileContent = fxManifest.replace(/\bversion\s+(.*)$/gm, `version '${newVersion}'`);
|
||||||
|
|
||||||
const newFileContent = manifestFile.replace(/\bversion\s+(.*)$/gm, `version '${newVersion}'`);
|
await Bun.write('./fxmanifest.lua', newFileContent);
|
||||||
|
|
||||||
fs.writeFileSync('fxmanifest.lua', newFileContent);
|
|
||||||
|
|||||||
12
.github/actions/bump-package-version.js
vendored
12
.github/actions/bump-package-version.js
vendored
@@ -1,10 +1,6 @@
|
|||||||
const fs = require('fs');
|
const packageJson = await Bun.file('./package/package.json').json();
|
||||||
|
|
||||||
const version = process.env.TGT_RELEASE_VERSION;
|
const newVersion = process.env.TGT_RELEASE_VERSION;
|
||||||
const newVersion = version.replace('v', '');
|
packageJson.version = newVersion.replace('v', '');
|
||||||
|
|
||||||
const packageFile = fs.readFileSync('package/package.json', { encoding: 'utf8' });
|
await Bun.write('./package/package.json', JSON.stringify(packageJson, null, 2));
|
||||||
|
|
||||||
const newFileContent = packageFile.replace(/"version":\s+"(.*)",$/gm, `"version": "${newVersion}",`);
|
|
||||||
|
|
||||||
fs.writeFileSync('package/package.json', newFileContent);
|
|
||||||
|
|||||||
74
.github/workflows/release.yml
vendored
74
.github/workflows/release.yml
vendored
@@ -7,44 +7,43 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
create-release:
|
create-release:
|
||||||
|
if: github.actor_id != 210085057
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Get latest code
|
- name: Install zip
|
||||||
uses: actions/checkout@v4
|
run: sudo apt install zip
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
ref: ${{ github.event.repository.default_branch }}
|
|
||||||
|
|
||||||
- name: Setup Bun
|
- name: Install Bun
|
||||||
uses: oven-sh/setup-bun@v2
|
uses: oven-sh/setup-bun@v2
|
||||||
with:
|
with:
|
||||||
bun-version: latest
|
bun-version: latest
|
||||||
|
|
||||||
|
|
||||||
- name: Install package dependencies
|
- name: Generate GitHub App token
|
||||||
run: bun install
|
id: app_token
|
||||||
working-directory: package
|
uses: tibdex/github-app-token@v2
|
||||||
|
with:
|
||||||
|
app_id: ${{ secrets.APP_ID }}
|
||||||
|
private_key: ${{ secrets.APP_PRIVATE_KEY }}
|
||||||
|
|
||||||
- name: Install web dependencies
|
- name: Get latest code
|
||||||
run: bun install
|
uses: actions/checkout@v4
|
||||||
working-directory: web
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
- name: Run web build script
|
ref: ${{ github.event.repository.default_branch }}
|
||||||
run: bun run build
|
token: ${{ steps.app_token.outputs.token }}
|
||||||
working-directory: web
|
|
||||||
|
|
||||||
|
|
||||||
- name: Bump package version
|
- name: Bump package version
|
||||||
run: bun .github/actions/bump-package-version.js
|
run: bun run .github/actions/bump-package-version.js
|
||||||
env:
|
env:
|
||||||
TGT_RELEASE_VERSION: ${{ github.ref_name }}
|
TGT_RELEASE_VERSION: ${{ github.ref_name }}
|
||||||
|
|
||||||
- name: Bump manifest version
|
- name: Bump manifest version
|
||||||
run: bun .github/actions/bump-manifest-version.js
|
run: bun run .github/actions/bump-manifest-version.js
|
||||||
env:
|
env:
|
||||||
TGT_RELEASE_VERSION: ${{ github.ref_name }}
|
TGT_RELEASE_VERSION: ${{ github.ref_name }}
|
||||||
|
|
||||||
|
|
||||||
- name: Push version bump change
|
- name: Push version bump change
|
||||||
uses: EndBug/add-and-commit@v9
|
uses: EndBug/add-and-commit@v9
|
||||||
with:
|
with:
|
||||||
@@ -53,25 +52,23 @@ jobs:
|
|||||||
default_author: github_actions
|
default_author: github_actions
|
||||||
message: 'chore: bump version to ${{ github.ref_name }}'
|
message: 'chore: bump version to ${{ github.ref_name }}'
|
||||||
|
|
||||||
- name: Update tag
|
|
||||||
uses: EndBug/latest-tag@v1
|
|
||||||
with:
|
|
||||||
ref: ${{ github.ref_name }}
|
|
||||||
|
|
||||||
|
- name: Install package dependencies
|
||||||
- name: Publish package to npm registry
|
run: bun install --frozen-lockfile
|
||||||
run: bun publish --access public
|
|
||||||
working-directory: package
|
working-directory: package
|
||||||
env:
|
|
||||||
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
||||||
|
|
||||||
- name: Install zip
|
- name: Install web dependencies
|
||||||
run: sudo apt install zip
|
run: bun install --frozen-lockfile
|
||||||
|
working-directory: web
|
||||||
|
|
||||||
|
- name: Run web build script
|
||||||
|
run: bun run build
|
||||||
|
working-directory: web
|
||||||
|
|
||||||
|
|
||||||
- name: Bundle files
|
- name: Bundle files
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ./temp/ox_lib
|
mkdir -p ./temp/ox_lib/web
|
||||||
mkdir -p ./temp/ox_lib/web/
|
|
||||||
cp ./{LICENSE,README.md,fxmanifest.lua,init.lua} ./temp/ox_lib
|
cp ./{LICENSE,README.md,fxmanifest.lua,init.lua} ./temp/ox_lib
|
||||||
cp -r ./{imports,resource,locales} ./temp/ox_lib
|
cp -r ./{imports,resource,locales} ./temp/ox_lib
|
||||||
cp -r ./web/build ./temp/ox_lib/web/
|
cp -r ./web/build ./temp/ox_lib/web/
|
||||||
@@ -79,11 +76,18 @@ jobs:
|
|||||||
|
|
||||||
- name: Create release
|
- name: Create release
|
||||||
uses: 'marvinpinto/action-automatic-releases@v1.2.1'
|
uses: 'marvinpinto/action-automatic-releases@v1.2.1'
|
||||||
id: auto_release
|
|
||||||
with:
|
with:
|
||||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
prerelease: false
|
prerelease: false
|
||||||
files: ox_lib.zip
|
files: ox_lib.zip
|
||||||
|
|
||||||
|
- name: Update tag
|
||||||
|
uses: EndBug/latest-tag@v1
|
||||||
|
with:
|
||||||
|
ref: ${{ github.ref_name }}
|
||||||
|
|
||||||
|
- name: Publish package to npm registry
|
||||||
|
run: bun publish --access public
|
||||||
|
working-directory: package
|
||||||
env:
|
env:
|
||||||
CI: false
|
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aw
|
|||||||
|
|
||||||
name 'ox_lib'
|
name 'ox_lib'
|
||||||
author 'Overextended'
|
author 'Overextended'
|
||||||
version '3.30.7'
|
version '3.30.8'
|
||||||
license 'LGPL-3.0-or-later'
|
license 'LGPL-3.0-or-later'
|
||||||
repository 'https://github.com/communityox/ox_lib'
|
repository 'https://github.com/communityox/ox_lib'
|
||||||
description 'A library of shared functions to utilise in other resources.'
|
description 'A library of shared functions to utilise in other resources.'
|
||||||
|
|||||||
@@ -8,16 +8,19 @@
|
|||||||
|
|
||||||
---@param coords vector3 The coords to check from.
|
---@param coords vector3 The coords to check from.
|
||||||
---@param maxDistance? number The max distance to check.
|
---@param maxDistance? number The max distance to check.
|
||||||
|
---@param ignorePlayerId? number|false The player server ID to ignore.
|
||||||
---@return number? playerId
|
---@return number? playerId
|
||||||
---@return number? playerPed
|
---@return number? playerPed
|
||||||
---@return vector3? playerCoords
|
---@return vector3? playerCoords
|
||||||
function lib.getClosestPlayer(coords, maxDistance)
|
function lib.getClosestPlayer(coords, maxDistance, ignorePlayerId)
|
||||||
local players = GetActivePlayers()
|
local players = GetActivePlayers()
|
||||||
local closestId, closestPed, closestCoords
|
local closestId, closestPed, closestCoords
|
||||||
maxDistance = maxDistance or 2.0
|
maxDistance = maxDistance or 2.0
|
||||||
|
|
||||||
for i = 1, #players do
|
for i = 1, #players do
|
||||||
local playerId = players[i]
|
local playerId = players[i]
|
||||||
|
|
||||||
|
if not ignorePlayerId or playerId ~= ignorePlayerId then
|
||||||
local playerPed = GetPlayerPed(playerId)
|
local playerPed = GetPlayerPed(playerId)
|
||||||
local playerCoords = GetEntityCoords(playerPed)
|
local playerCoords = GetEntityCoords(playerPed)
|
||||||
local distance = #(coords - playerCoords)
|
local distance = #(coords - playerCoords)
|
||||||
@@ -29,6 +32,7 @@ function lib.getClosestPlayer(coords, maxDistance)
|
|||||||
closestCoords = playerCoords
|
closestCoords = playerCoords
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return closestId, closestPed, closestCoords
|
return closestId, closestPed, closestCoords
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,14 +9,8 @@
|
|||||||
---@diagnostic disable: param-type-mismatch
|
---@diagnostic disable: param-type-mismatch
|
||||||
lib.marker = {}
|
lib.marker = {}
|
||||||
|
|
||||||
local defaultRotation = vector3(0, 0, 0)
|
---@enum (key) MarkerType
|
||||||
local defaultDirection = vector3(0, 0, 0)
|
local markerTypes = {
|
||||||
local defaultColor = { r = 255, g = 255, b = 255, a = 100 }
|
|
||||||
local defaultSize = { width = 2, height = 1 }
|
|
||||||
local defaultTextureDict = nil
|
|
||||||
local defaultTextureName = nil
|
|
||||||
|
|
||||||
local markerTypesMap = {
|
|
||||||
UpsideDownCone = 0,
|
UpsideDownCone = 0,
|
||||||
VerticalCylinder = 1,
|
VerticalCylinder = 1,
|
||||||
ThickChevronUp = 2,
|
ThickChevronUp = 2,
|
||||||
@@ -63,58 +57,12 @@ local markerTypesMap = {
|
|||||||
Unknown43 = 43,
|
Unknown43 = 43,
|
||||||
}
|
}
|
||||||
|
|
||||||
---@alias MarkerType
|
|
||||||
---| "UpsideDownCone"
|
|
||||||
---| "VerticalCylinder"
|
|
||||||
---| "ThickChevronUp"
|
|
||||||
---| "ThinChevronUp"
|
|
||||||
---| "CheckeredFlagRect"
|
|
||||||
---| "CheckeredFlagCircle"
|
|
||||||
---| "VerticleCircle"
|
|
||||||
---| "PlaneModel"
|
|
||||||
---| "LostMCTransparent"
|
|
||||||
---| "LostMC"
|
|
||||||
---| "Number0"
|
|
||||||
---| "Number1"
|
|
||||||
---| "Number2"
|
|
||||||
---| "Number3"
|
|
||||||
---| "Number4"
|
|
||||||
---| "Number5"
|
|
||||||
---| "Number6"
|
|
||||||
---| "Number7"
|
|
||||||
---| "Number8"
|
|
||||||
---| "Number9"
|
|
||||||
---| "ChevronUpx1"
|
|
||||||
---| "ChevronUpx2"
|
|
||||||
---| "ChevronUpx3"
|
|
||||||
---| "HorizontalCircleFat"
|
|
||||||
---| "ReplayIcon"
|
|
||||||
---| "HorizontalCircleSkinny"
|
|
||||||
---| "HorizontalCircleSkinny_Arrow"
|
|
||||||
---| "HorizontalSplitArrowCircle"
|
|
||||||
---| "DebugSphere"
|
|
||||||
---| "DollarSign"
|
|
||||||
---| "HorizontalBars"
|
|
||||||
---| "WolfHead"
|
|
||||||
---| "QuestionMark"
|
|
||||||
---| "PlaneSymbol"
|
|
||||||
---| "HelicopterSymbol"
|
|
||||||
---| "BoatSymbol"
|
|
||||||
---| "CarSymbol"
|
|
||||||
---| "MotorcycleSymbol"
|
|
||||||
---| "BikeSymbol"
|
|
||||||
---| "TruckSymbol"
|
|
||||||
---| "ParachuteSymbol"
|
|
||||||
---| "Unknown41"
|
|
||||||
---| "SawbladeSymbol"
|
|
||||||
---| "Unknown43"
|
|
||||||
|
|
||||||
---@class MarkerProps
|
---@class MarkerProps
|
||||||
---@field type MarkerType | number
|
---@field type? MarkerType | integer
|
||||||
---@field coords { x: number, y: number, z: number }
|
---@field coords { x: number, y: number, z: number }
|
||||||
---@field width? number
|
---@field width? number
|
||||||
---@field height? number
|
---@field height? number
|
||||||
---@field color? { r: number, g: number, b: number, a: number }
|
---@field color? { r: integer, g: integer, b: integer, a: integer }
|
||||||
---@field rotation? { x: number, y: number, z: number }
|
---@field rotation? { x: number, y: number, z: number }
|
||||||
---@field direction? { x: number, y: number, z: number }
|
---@field direction? { x: number, y: number, z: number }
|
||||||
---@field bobUpAndDown? boolean
|
---@field bobUpAndDown? boolean
|
||||||
@@ -122,9 +70,25 @@ local markerTypesMap = {
|
|||||||
---@field rotate? boolean
|
---@field rotate? boolean
|
||||||
---@field textureDict? string
|
---@field textureDict? string
|
||||||
---@field textureName? string
|
---@field textureName? string
|
||||||
|
---@field invert? boolean
|
||||||
|
|
||||||
---@param self MarkerProps
|
local vector3_zero = vector3(0, 0, 0)
|
||||||
local function drawMarker(self)
|
|
||||||
|
local marker_mt = {
|
||||||
|
type = 0,
|
||||||
|
width = 2.,
|
||||||
|
height = 1.,
|
||||||
|
color = {r = 255, g = 100, b = 0, a = 100},
|
||||||
|
rotation = vector3_zero,
|
||||||
|
direction = vector3_zero,
|
||||||
|
bobUpAndDown = false,
|
||||||
|
faceCamera = false,
|
||||||
|
rotate = false,
|
||||||
|
invert = false,
|
||||||
|
}
|
||||||
|
marker_mt.__index = marker_mt
|
||||||
|
|
||||||
|
function marker_mt:draw()
|
||||||
DrawMarker(
|
DrawMarker(
|
||||||
self.type,
|
self.type,
|
||||||
self.coords.x, self.coords.y, self.coords.z,
|
self.coords.x, self.coords.y, self.coords.z,
|
||||||
@@ -132,40 +96,19 @@ local function drawMarker(self)
|
|||||||
self.rotation.x, self.rotation.y, self.rotation.z,
|
self.rotation.x, self.rotation.y, self.rotation.z,
|
||||||
self.width, self.width, self.height,
|
self.width, self.width, self.height,
|
||||||
self.color.r, self.color.g, self.color.b, self.color.a,
|
self.color.r, self.color.g, self.color.b, self.color.a,
|
||||||
self.bobUpAndDown, self.faceCamera, 2, self.rotate, self.textureDict, self.textureName, false)
|
self.bobUpAndDown, self.faceCamera, 2, self.rotate, self.textureDict, self.textureName, self.invert)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param options MarkerProps
|
---@param options MarkerProps
|
||||||
function lib.marker.new(options)
|
function lib.marker.new(options)
|
||||||
local markerType
|
options.type =
|
||||||
if type(options.type) == "string" then
|
type(options.type) == 'string' and markerTypes[options.type]
|
||||||
markerType = markerTypesMap[options.type]
|
or type(options.type) == 'number' and options.type or nil
|
||||||
if markerType == nil then
|
|
||||||
error(("unknown marker type '%s'"):format(options.type))
|
|
||||||
end
|
|
||||||
elseif type(options.type) == "number" then
|
|
||||||
markerType = options.type
|
|
||||||
else
|
|
||||||
error(("expected marker type to have type 'string' or 'number' (received %s)"):format(type(options.type)))
|
|
||||||
end
|
|
||||||
|
|
||||||
local self = {}
|
local self = setmetatable(options, marker_mt)
|
||||||
self.type = markerType
|
|
||||||
self.coords = options.coords
|
|
||||||
self.color = options.color or defaultColor
|
|
||||||
self.width = options.width or defaultSize.width
|
|
||||||
self.height = options.height or defaultSize.height
|
|
||||||
self.rotation = options.rotation or defaultRotation
|
|
||||||
self.direction = options.direction or defaultDirection
|
|
||||||
self.bobUpAndDown = type(options.bobUpAndDown) == 'boolean' and options.bobUpAndDown
|
|
||||||
self.faceCamera = type(options.faceCamera) ~= 'boolean' or options.faceCamera
|
|
||||||
self.rotate = type(options.rotate) == 'boolean' and options.rotate
|
|
||||||
self.textureDict = options.textureDict or defaultTextureDict
|
|
||||||
self.textureName = options.textureName or defaultTextureName
|
|
||||||
self.draw = drawMarker
|
|
||||||
|
|
||||||
self.width += 0.0
|
self.width += .0
|
||||||
self.height += 0.0
|
self.height += .0
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -122,8 +122,15 @@ local function removeZone(zone)
|
|||||||
|
|
||||||
insideZones[zone.id] = nil
|
insideZones[zone.id] = nil
|
||||||
|
|
||||||
table.remove(exitingZones, exitingZones:indexOf(zone))
|
local exitingIndex = exitingZones:indexOf(zone)
|
||||||
table.remove(enteringZones, enteringZones:indexOf(zone))
|
if exitingIndex then
|
||||||
|
table.remove(exitingZones, exitingIndex)
|
||||||
|
end
|
||||||
|
|
||||||
|
local enteringIndex = enteringZones:indexOf(zone)
|
||||||
|
if enteringIndex then
|
||||||
|
table.remove(enteringZones, enteringIndex)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
|
|||||||
@@ -9,25 +9,25 @@
|
|||||||
"settings": {
|
"settings": {
|
||||||
"locale": "Endre språk",
|
"locale": "Endre språk",
|
||||||
"locale_description": "Nåværende språk: ${language} (%s)",
|
"locale_description": "Nåværende språk: ${language} (%s)",
|
||||||
"notification_audio": "Varslings lyd",
|
"notification_audio": "Varslingslyd",
|
||||||
"notification_position": "Varslings posisjon"
|
"notification_position": "Varslingsposisjon"
|
||||||
},
|
},
|
||||||
"position": {
|
"position": {
|
||||||
"bottom": "Bunn",
|
"bottom": "Nederst",
|
||||||
"bottom-left": "Bunn-venstre",
|
"bottom-left": "Nederst til venstre",
|
||||||
"bottom-right": "Bunn-høyre",
|
"bottom-right": "Nederst til høyre",
|
||||||
"center-left": "Senter-venstre",
|
"center-left": "Midten venstre",
|
||||||
"center-right": "Senter-høyre",
|
"center-right": "Midten høyre",
|
||||||
"top": "Top",
|
"top": "Øverst",
|
||||||
"top-left": "Top-venstre",
|
"top-left": "Øverst til venstre",
|
||||||
"top-right": "Top-høyre"
|
"top-right": "Øverst til høyre"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"open_radial_menu": "Åpne radial menyen",
|
"open_radial_menu": "Åpne radialmenyen",
|
||||||
"cancel_progress": "Avbryt den nåværende progresjonsbaren",
|
"cancel_progress": "Avbryt den nåværende progresjonsbaren",
|
||||||
"txadmin_announcement": "Server annonsering fra %s",
|
"txadmin_announcement": "Serverannonsering fra %s",
|
||||||
"txadmin_dm": "Direktemelding fra %s",
|
"txadmin_dm": "Direktemelding fra %s",
|
||||||
"txadmin_warn": "Du har fått en advarsel fra %s",
|
"txadmin_warn": "Du har fått en advarsel fra %s",
|
||||||
"txadmin_warn_content": "%s \nAction ID: %s",
|
"txadmin_warn_content": "%s \nAction ID: %s",
|
||||||
"txadmin_scheduledrestart": "Planlagt Omstart"
|
"txadmin_scheduledrestart": "Planlagt omstart"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ interface PropProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ProgressProps {
|
interface ProgressProps {
|
||||||
|
label?: string;
|
||||||
duration: number;
|
duration: number;
|
||||||
position?: 'middle' | 'bottom';
|
position?: 'middle' | 'bottom';
|
||||||
useWhileDead?: boolean;
|
useWhileDead?: boolean;
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@communityox/ox_lib",
|
"name": "@communityox/ox_lib",
|
||||||
"author": "Overextended",
|
"author": "Overextended",
|
||||||
"version": "3.30.7",
|
"version": "3.30.8",
|
||||||
"description": "JS/TS wrapper for ox_lib exports",
|
"description": "JS/TS wrapper for ox_lib exports",
|
||||||
"main": "./shared/index.js",
|
"main": "./shared/index.js",
|
||||||
"types": "./shared/index.d.ts",
|
"types": "./shared/index.d.ts",
|
||||||
"sideEffects": ["./shared/resource/locale/index.js"],
|
"sideEffects": [
|
||||||
|
"./shared/resource/locale/index.js"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "tsc",
|
"compile": "tsc",
|
||||||
"prepare": "npm run compile"
|
"prepare": "npm run compile"
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
export * from './resource';
|
export * from './resource';
|
||||||
|
|
||||||
|
export const context: 'server' | 'client' = IsDuplicityVersion() ? 'server' : 'client';
|
||||||
|
|
||||||
// https://www.raygesualdo.com/posts/flattening-object-keys-with-typescript-types/
|
// https://www.raygesualdo.com/posts/flattening-object-keys-with-typescript-types/
|
||||||
export type FlattenObjectKeys<T extends Record<string, any>, Key = keyof T> = Key extends string
|
export type FlattenObjectKeys<T extends Record<string, any>, Key = keyof T> = Key extends string
|
||||||
? T[Key] extends Record<string, unknown>
|
? T[Key] extends Record<string, unknown>
|
||||||
|
|||||||
29
package/shared/resource/getNearbyVehicles/index.ts
Normal file
29
package/shared/resource/getNearbyVehicles/index.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { cache } from '../cache/index';
|
||||||
|
import { context } from 'shared';
|
||||||
|
import { Vector3 } from "@nativewrappers/client";
|
||||||
|
|
||||||
|
interface NearbyVehicle {
|
||||||
|
vehicle: number;
|
||||||
|
coords: Vector3;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getNearbyVehicles(coords: Vector3, maxDistance: number = 2.0, includePlayerVehicle: boolean = false): NearbyVehicle[] {
|
||||||
|
const vehicles = GetGamePool('CVehicle');
|
||||||
|
const nearbyVehicles: NearbyVehicle[] = [];
|
||||||
|
|
||||||
|
for (const vehicle of vehicles) {
|
||||||
|
if (context === 'server' || !cache.vehicle || vehicle !== cache.vehicle || includePlayerVehicle) {
|
||||||
|
const vehicleCoords = Vector3.fromArray(GetEntityCoords(vehicle, true));
|
||||||
|
const distance = vehicleCoords.distance(coords);
|
||||||
|
|
||||||
|
if (distance < maxDistance && NetworkGetEntityIsNetworked(vehicle) ) {
|
||||||
|
nearbyVehicles.push({
|
||||||
|
vehicle,
|
||||||
|
coords: vehicleCoords
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nearbyVehicles;
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from './version';
|
export * from './version';
|
||||||
export * from './cache';
|
export * from './cache';
|
||||||
export * from './locale'
|
export * from './locale';
|
||||||
|
export * from './getNearbyVehicles';
|
||||||
|
|||||||
Reference in New Issue
Block a user