lenix 1.7.0 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client/blip.ts CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  import type { Vec4 } from '../shared/types.ts'
4
4
 
5
-
6
5
  export interface Blip {
7
6
  /**
8
7
  * Blip world coordinates and heading.
@@ -0,0 +1,137 @@
1
+ import type { Vec3, Vec4 } from '../shared/types.ts'
2
+
3
+
4
+ export const client: {
5
+ entity: {
6
+ handle: (entityNetId?: number) => number
7
+ netId: (entity?: number) => number
8
+ coords: {
9
+ (excludeH: true, entity?: number, isAlive?: boolean): Vec3;
10
+ (excludeH?: false, entity?: number, isAlive?: boolean): Vec4
11
+ }
12
+ teleport: (
13
+ x: number,
14
+ y: number,
15
+ z: number,
16
+ h?: number,
17
+ entity?: number,
18
+ clearArea?: boolean,
19
+ alive?: boolean,
20
+ deadDisable?: boolean,
21
+ ragdol?: boolean
22
+ ) => void
23
+ }
24
+ player: {
25
+ serverId: (playerId?: number) => number
26
+ id: (serverId?: number) => number
27
+ storage: {
28
+ set: <T extends string>(key: T, value: string) => void
29
+ get: <T extends string>(key: T) => string
30
+ delete: <T extends string>(key: T) => void
31
+ }
32
+ }
33
+ } = {
34
+ entity: {
35
+ /**
36
+ * Gets the local entity handle from a network ID.
37
+ *
38
+ * Network IDs are shared, but entity handles are local.
39
+ * The returned handle is only valid on the current machine.
40
+ *
41
+ * If no network ID is provided, this resolves your own player ped
42
+ * by first getting its network ID.
43
+ *
44
+ * Examples:
45
+ * - entity(vehicleNetId) -> local vehicle handle
46
+ * - entity(pedNetId) -> local ped handle
47
+ * - entity() -> your own player ped handle
48
+ */
49
+ handle: (entityNetId = client.entity.netId()) => NetworkGetEntityFromNetworkId(entityNetId),
50
+
51
+ /**
52
+ * Gets the network ID for an entity.
53
+ *
54
+ * Entity handles are local to the current machine.
55
+ * Network IDs are shared references for networked entities.
56
+ *
57
+ * If no entity is provided, this uses your own player ped.
58
+ *
59
+ * Examples:
60
+ * - netId(vehicle) -> network ID of that vehicle
61
+ * - netId(targetPed) -> network ID of that ped
62
+ * - netId() -> network ID of your own player ped
63
+ */
64
+ netId: (entity = PlayerPedId()) => NetworkGetNetworkIdFromEntity(entity),
65
+
66
+ /**
67
+ * Gets entity coordinates and heading.
68
+ */
69
+ coords: (() => {
70
+ function coords(excludeH: true, entity?: number, isAlive?: boolean): Vec3
71
+ function coords(excludeH?: false, entity?: number, isAlive?: boolean): Vec4
72
+ function coords(excludeH = false, entity = client.entity.handle(), isAlive = true) {
73
+ const entityCoords = GetEntityCoords(entity, isAlive) as Vec3
74
+
75
+ if (excludeH) return entityCoords
76
+
77
+ return [
78
+ ...entityCoords,
79
+ GetEntityHeading(entity)
80
+ ]
81
+ }
82
+
83
+ return coords
84
+ })(),
85
+
86
+ teleport: (
87
+ x: number,
88
+ y: number,
89
+ z: number,
90
+ h?: number,
91
+ entity = client.entity.handle(),
92
+ clearArea = false,
93
+ alive = true,
94
+ deadDisable = false,
95
+ ragdol = false
96
+ ) => {
97
+ SetEntityCoords(entity, x, y, z, alive, deadDisable, ragdol, clearArea)
98
+ SetEntityHeading(entity, h ?? client.entity.coords()[3])
99
+ }
100
+ },
101
+ player: {
102
+ /**
103
+ * Gets a client player ID.
104
+ *
105
+ * If a server ID is provided, this converts that server ID into a client
106
+ * player ID on the current client.
107
+ *
108
+ * If no server ID is provided, this returns your own client player ID.
109
+ *
110
+ * Examples:
111
+ * - id(targetServerId) -> target player's client player ID
112
+ * - id() -> your own client player ID
113
+ */
114
+ id: (serverId?: number) => serverId ? GetPlayerFromServerId(serverId) : PlayerId(),
115
+
116
+ /**
117
+ * Gets a player's server ID from their client player ID.
118
+ *
119
+ * Client player IDs are local to each client.
120
+ * Server IDs, also called source IDs, identify connected players on the server.
121
+ *
122
+ * If no client player ID is provided, this uses your own client player ID.
123
+ *
124
+ * Examples:
125
+ * - serverId(targetPlayerId) -> target player's server ID
126
+ * - serverId() -> your own server ID
127
+ */
128
+ serverId: (playerId = client.player.id()) => GetPlayerServerId(playerId),
129
+
130
+ storage: {
131
+ set: <T extends string>(key: T, value: string) => SetResourceKvp(key, value),
132
+ get: <T extends string>(key: T) => GetResourceKvpString(key),
133
+ delete: <T extends string>(key: T) => DeleteResourceKvp(key)
134
+ }
135
+ }
136
+ }
137
+
package/client/index.ts CHANGED
@@ -11,5 +11,5 @@ export * from './blip.ts'
11
11
  export * from './cam.ts'
12
12
  export * from './nearest.ts'
13
13
  export * from './pool.ts'
14
- export * from './entity.ts'
15
14
  export * from './timer.ts'
15
+ export * from './client.ts'
package/client/nearest.ts CHANGED
@@ -51,9 +51,9 @@ const player = (
51
51
  const playerPed = GetPlayerPed(playerId)
52
52
  // deno-lint-ignore no-boolean-literal-for-arguments
53
53
  const vehicle = GetVehiclePedIsIn(playerPed, false)
54
- const playerCoords: Vec3 = (
55
- vehicle === 0 ? getEntity.coords(true, playerPed) : GetWorldPositionOfEntityBone(playerPed, 0) as Vec3
56
- )
54
+ const playerCoords: Vec3 = vehicle === 0
55
+ ? getEntity.coords(true, playerPed)
56
+ : GetWorldPositionOfEntityBone(playerPed, 0) as Vec3
57
57
 
58
58
  const distance = Vdist(
59
59
  coords[0],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lenix",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Typed FiveM utilities for client, server, shared, and NUI scripts",
5
5
  "author": "Lenix",
6
6
  "license": "MIT",
package/server/index.ts CHANGED
@@ -3,3 +3,5 @@
3
3
  *
4
4
  * FiveM server-side helpers.
5
5
  */
6
+
7
+ export * from './server'
@@ -0,0 +1,11 @@
1
+ export const server: {
2
+ entity: {
3
+ handle: (netId: number) => number;
4
+ handleFromSource: (source: number) => number;
5
+ };
6
+ } = {
7
+ entity: {
8
+ handle: (netId: number) => NetworkGetEntityFromNetworkId(netId),
9
+ handleFromSource: (source: number) => GetPlayerPed(source.toString())
10
+ }
11
+ }
package/shared/types.ts CHANGED
@@ -23,7 +23,6 @@ export type Request<
23
23
  > = Params extends readonly unknown[] ? never
24
24
  : [Response, Id, Params]
25
25
 
26
-
27
26
  /**
28
27
  * Internal NUI requests used by Lenix helpers. DO NOT USE
29
28
  */
@@ -33,4 +32,3 @@ export interface _InternalRequests {
33
32
  cursor: boolean
34
33
  }>
35
34
  }
36
-
package/client/entity.ts DELETED
@@ -1,22 +0,0 @@
1
- // deno-lint-ignore-file no-undef
2
- import type { Vec3, Vec4 } from '../shared/types.ts'
3
-
4
- /**
5
- * Gets entity coordinates and heading.
6
- */
7
- function coords(excludeH: true, entity?: number, isAlive?: boolean): Vec3
8
- function coords(excludeH?: false, entity?: number, isAlive?: boolean): Vec4
9
- function coords(excludeH = false, entity = PlayerPedId(), isAlive = true): Vec3 | Vec4 {
10
- const entityCoords = GetEntityCoords(entity, isAlive) as Vec3
11
-
12
- if (excludeH) return entityCoords
13
-
14
- return [
15
- ...entityCoords,
16
- GetEntityHeading(entity)
17
- ]
18
- }
19
-
20
- export const getEntity = {
21
- coords
22
- }