@warpfx/client 0.3.3 → 0.3.4

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/dist/index.d.ts CHANGED
@@ -35,6 +35,43 @@ interface SyncRef<T = any> {
35
35
  /** React to state changes. Returns an unsubscribe function. */
36
36
  watch(handler: (newState: T, oldState: T) => void): () => void;
37
37
  }
38
+ /** Entity type for proximity queries. */
39
+ type NearbyEntityType = "player" | "vehicle" | "ped" | "object";
40
+ /** An entity within proximity range. */
41
+ interface NearbyEntity {
42
+ /** FiveM entity handle. */
43
+ id: number;
44
+ /** Entity type. */
45
+ type: NearbyEntityType;
46
+ /** World coordinates. */
47
+ coords: {
48
+ x: number;
49
+ y: number;
50
+ z: number;
51
+ };
52
+ /** Distance from the local player. */
53
+ distance: number;
54
+ /** FiveM server ID — only present for `player` type. */
55
+ serverId?: number;
56
+ }
57
+ /** Options for the `nearby()` proximity query. */
58
+ interface NearbyOptions {
59
+ /** Maximum distance to include entities. */
60
+ range: number;
61
+ /** Entity types to track. Defaults to all types. */
62
+ types?: NearbyEntityType[];
63
+ /** Milliseconds between proximity checks. Defaults to 500. */
64
+ interval?: number;
65
+ }
66
+ /** Reactive handle to nearby entities. SyncRef-compatible (works with `watch()`). */
67
+ interface NearbyRef {
68
+ /** Current nearby entities (latest check result). */
69
+ readonly value: NearbyEntity[];
70
+ /** React to changes in the nearby set. Returns an unsubscribe function. */
71
+ watch(handler: (current: NearbyEntity[], previous: NearbyEntity[]) => void): () => void;
72
+ /** Stop tracking and clean up this consumer. */
73
+ destroy(): void;
74
+ }
38
75
  /** Action error received from the server. */
39
76
  interface ActionError {
40
77
  action: string;
@@ -100,6 +137,27 @@ declare function watch<T extends readonly SyncRef[]>(refs: readonly [...T], hand
100
137
  }, oldValues: {
101
138
  [K in keyof T]: T[K] extends SyncRef<infer V> ? V : never;
102
139
  }) => void): () => void;
140
+ /**
141
+ * Track nearby entities with a shared, optimized proximity tick.
142
+ *
143
+ * All `nearby()` consumers share a single game-thread loop — instead of
144
+ * N modules each running their own `GetEntityCoords` tick. Watchers fire
145
+ * when entities enter or leave the range.
146
+ *
147
+ * The returned ref is SyncRef-compatible and works with `watch()`.
148
+ *
149
+ * @example
150
+ * const entities = nearby({ range: 50, types: ['player', 'vehicle'] });
151
+ *
152
+ * entities.watch((current, previous) => {
153
+ * console.log(`${current.length} entities nearby`);
154
+ * });
155
+ *
156
+ * const closest = entities.value
157
+ * .filter(e => e.type === 'player')
158
+ * .sort((a, b) => a.distance - b.distance)[0];
159
+ */
160
+ declare function nearby(options: NearbyOptions): NearbyRef;
103
161
  /**
104
162
  * Register a global error handler for all action errors.
105
163
  * Returns an unsubscribe function.
@@ -145,4 +203,4 @@ declare function onNUI<T = any>(name: string, handler: (data: T) => any): void;
145
203
  */
146
204
  declare function registerKeybind(name: string, options: KeybindOptions): void;
147
205
 
148
- export { type ActionError, type ClientEventBus, type KeybindOptions, type ShowNUIOptions, type SyncRef, action, call, getEvents, hideNUI, isReady, onError, onNUI, onReady, registerKeybind, sendNUI, setNUIFocus, showNUI, sync, watch };
206
+ export { type ActionError, type ClientEventBus, type KeybindOptions, type NearbyEntity, type NearbyEntityType, type NearbyOptions, type NearbyRef, type ShowNUIOptions, type SyncRef, action, call, getEvents, hideNUI, isReady, nearby, onError, onNUI, onReady, registerKeybind, sendNUI, setNUIFocus, showNUI, sync, watch };
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ __export(index_exports, {
25
25
  getEvents: () => getEvents,
26
26
  hideNUI: () => hideNUI,
27
27
  isReady: () => isReady,
28
+ nearby: () => nearby,
28
29
  onError: () => onError,
29
30
  onNUI: () => onNUI,
30
31
  onReady: () => onReady,
@@ -66,6 +67,9 @@ function watch(refs, handler) {
66
67
  );
67
68
  return () => unsubs.forEach((fn) => fn());
68
69
  }
70
+ function nearby(options) {
71
+ return warp().nearby(options);
72
+ }
69
73
  function onError(handler) {
70
74
  return warp().onError(handler);
71
75
  }
@@ -103,6 +107,7 @@ function registerKeybind(name, options) {
103
107
  getEvents,
104
108
  hideNUI,
105
109
  isReady,
110
+ nearby,
106
111
  onError,
107
112
  onNUI,
108
113
  onReady,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warpfx/client",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Warp Framework SDK for client-side FiveM module development",
5
5
  "keywords": [
6
6
  "client",