@aifivem/lib 0.7.0 → 0.8.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aifivem/lib",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Helpers every ai-core resource uses: logging, exports, rate limits, database tables.",
5
5
  "license": "GPL-3.0-only",
6
6
  "repository": {
@@ -22,7 +22,7 @@
22
22
  "access": "public"
23
23
  },
24
24
  "dependencies": {
25
- "@aifivem/shared": "^0.6.0",
25
+ "@aifivem/shared": "^0.7.0",
26
26
  "@aifivem/mysql": "^0.2.0"
27
27
  },
28
28
  "devDependencies": {
@@ -6,6 +6,7 @@ export { ScriptCamera } from "./scriptCamera";
6
6
  export { medical } from "./medical";
7
7
  export { fuel } from "./fuel";
8
8
  export { mdt } from "./mdt";
9
+ export { phone } from "./phone";
9
10
  export {
10
11
  NuiScreen,
11
12
  type NuiPageMessage,
@@ -48,11 +49,7 @@ export {
48
49
  type ProgressOptions,
49
50
  } from "./progress";
50
51
  export { input, itemPicker, menu } from "./menu/dialogs";
51
- export {
52
- lockpick,
53
- skillCheck,
54
- type LockpickOptions,
55
- } from "./menu/minigames";
52
+ export { lockpick, skillCheck, type LockpickOptions } from "./menu/minigames";
56
53
  export type { MenuListeners } from "./menu/requests";
57
54
  export { inventory } from "./inventory";
58
55
  export { vehicleKeys } from "./vehicleKeys";
@@ -0,0 +1,14 @@
1
+ import { CORE } from "@aifivem/shared";
2
+
3
+ /** The local player's phone through ai-core's client phone layer, whatever phone runs (`docs/compat/phone.md`). */
4
+ export const phone = {
5
+ /**
6
+ * `fn(phone)` when the local player opens the phone (`phone`: the phone's resource name): once per opening, at most
7
+ * once per 10 s; nothing for a phone without an open signal.
8
+ */
9
+ onUsed(fn: (phone: string) => void): void {
10
+ on(CORE.clientPhoneUsedEvent, (phone: unknown) => {
11
+ if (typeof phone === "string") fn(phone);
12
+ });
13
+ },
14
+ };
@@ -38,6 +38,12 @@ export const characters = {
38
38
  */
39
39
  search: (text: string, cursor?: number): Promise<CharacterSearchPage> =>
40
40
  ask((done) => core.SearchCharacters(text, done, cursor)),
41
+ /**
42
+ * The character id of a citizenid, loaded or not (a loaded one from memory, a stored one with one indexed read);
43
+ * null when unknown or deleted.
44
+ */
45
+ idOf: (citizenid: string): Promise<number | null> =>
46
+ ask((done) => core.GetCharIdByCitizenId(citizenid, done)),
41
47
  /** The characters of an account id or of every account with a license (`license:abc` or `abc`). */
42
48
  ofUser: (user: number | string): Promise<StoredCharacter[]> =>
43
49
  ask((done) => core.GetCharactersOfUser(user, done)),
@@ -50,8 +56,11 @@ export const characters = {
50
56
  ask((done) => core.GetJobMembers(job, done, after, limit)),
51
57
  /** Whether anyone holds a job, loaded or not (one row is read). */
52
58
  hasJobMember: async (job: string): Promise<boolean> =>
53
- (await ask<MembersPage>((done) => core.GetJobMembers(job, done, undefined, 1)))
54
- .members.length > 0,
59
+ (
60
+ await ask<MembersPage>((done) =>
61
+ core.GetJobMembers(job, done, undefined, 1),
62
+ )
63
+ ).members.length > 0,
55
64
  gangMembers: (
56
65
  gang: string,
57
66
  after?: number,
@@ -107,7 +116,7 @@ export const characters = {
107
116
  value: unknown,
108
117
  ): Promise<CharacterResult> =>
109
118
  ask((done) => core.SetOfflineMeta(charId, key, value, done)),
110
- /** Name, birth date, nationality, sex (sex only while not loaded), each checked like the creation form. */
119
+ /** Name, birth date, nationality, sex / gender (sex only while not loaded), height (cm), each checked like the creation form. */
111
120
  setInfo: (
112
121
  charId: number,
113
122
  patch: CharacterInfoPatch,
@@ -0,0 +1,26 @@
1
+ import {
2
+ CORE,
3
+ type CharacterResult,
4
+ type CharacterTarget,
5
+ } from "@aifivem/shared";
6
+ import { resourceExport } from "../fivem/exports";
7
+
8
+ const core = resourceExport(CORE.resource);
9
+
10
+ /**
11
+ * A character's legal / illegal status through ai-core (metadata `illegal`), for scripts that gate illegal content.
12
+ * Always legal while ai-core's panel switch `illegal.enabled` is off.
13
+ */
14
+ export const illegal = {
15
+ /** Whether a loaded player's character is illegal (a memory read; false when not loaded). */
16
+ is: (source: number): boolean => core.IsIllegal(source) === true,
17
+ /** Any character by citizenid or `{ charId }`, loaded or not; null when unknown. */
18
+ of: (target: CharacterTarget): Promise<boolean | null> =>
19
+ new Promise((resolve) => {
20
+ const now = core.IsIllegal(target, resolve);
21
+ if (now !== null) resolve(now);
22
+ }),
23
+ /** Marks a character illegal or legal, loaded or not (`{ ok }` or an ai-core lang key). */
24
+ set: (target: CharacterTarget, state: boolean): Promise<CharacterResult> =>
25
+ new Promise((resolve) => core.SetIllegal(target, state, resolve)),
26
+ };
@@ -154,6 +154,7 @@ export { medical } from "./medical";
154
154
  export { billing } from "./billing";
155
155
  export { banking } from "./banking";
156
156
  export { mdt } from "./mdt";
157
+ export { warrants } from "./warrants";
157
158
  export { ems } from "./ems";
158
159
  export { appearance } from "./appearance";
159
160
  export { needs, stress } from "./stress";
@@ -161,5 +162,6 @@ export { fuel } from "./fuel";
161
162
  export { doors } from "./doors";
162
163
  export { garages } from "./garages";
163
164
  export { characters } from "./characters";
165
+ export { illegal } from "./illegal";
164
166
  export { bans } from "./bans";
165
167
  export { isPrimeTime } from "./primeTime";
package/src/server/mdt.ts CHANGED
@@ -7,6 +7,19 @@ const core = resourceExport(CORE.resource);
7
7
  export const mdt = {
8
8
  /** Writes a record; false when no MDT runs or it takes no such record. */
9
9
  record: (record: MdtRecord): boolean => core.AddMdtRecord(record),
10
+ /**
11
+ * Whether a character (a loaded player's server id or a citizenid) has an active warrant: the active MDT's and / or
12
+ * ai-core's own (`warrants`), by ai-core's panel setting `warrants` (`docs/compat/mdt.md`). False when not or when
13
+ * ai-core is stopped. ai-core keeps a stored character's answer 30 s.
14
+ */
15
+ hasWarrant: (target: number | string): Promise<boolean> =>
16
+ new Promise((resolve) => {
17
+ try {
18
+ core.HasMdtWarrant(target, (wanted) => resolve(wanted === true));
19
+ } catch {
20
+ resolve(false);
21
+ }
22
+ }),
10
23
  /** The MDT records go to, or null. */
11
24
  provider: (): string | null => core.GetMdtSystem(),
12
25
  };
@@ -1,8 +1,4 @@
1
- import {
2
- CORE,
3
- type PhoneMail,
4
- type PhoneNotification,
5
- } from "@aifivem/shared";
1
+ import { CORE, type PhoneMail, type PhoneNotification } from "@aifivem/shared";
6
2
  import { resourceExport } from "../fivem/exports";
7
3
 
8
4
  const core = resourceExport(CORE.resource);
@@ -19,4 +15,14 @@ export const phone = {
19
15
  core.SendPhoneMessage(from, to, text),
20
16
  notify: (source: number, notification: PhoneNotification): boolean =>
21
17
  core.PhoneNotify(source, notification),
18
+ /**
19
+ * `fn(source, phone)` when a player with a loaded character opens the phone (`phone`: the phone's resource name):
20
+ * once per opening, at most once per 10 s per player; nothing for a phone without an open signal.
21
+ */
22
+ onUsed(fn: (source: number, phone: string) => void): void {
23
+ on(CORE.phoneUsedEvent, (source: unknown, phone: unknown) => {
24
+ if (typeof source === "number" && typeof phone === "string")
25
+ fn(source, phone);
26
+ });
27
+ },
22
28
  };
@@ -15,11 +15,14 @@ export const stress = {
15
15
  provider: (): string | null => core.GetStressSystem(),
16
16
  };
17
17
 
18
- /** Players' hunger and thirst through the same layer (the HUD that keeps them, ai-core's metadata without one). */
18
+ /** Players' hunger and thirst, kept by ai-core (character metadata, 0-100); any HUD only draws them. */
19
19
  export const needs = {
20
20
  /** Hunger and thirst to full (admin revive, hospital); false when the player has no character. */
21
21
  refill: (source: number): boolean => core.RefillNeeds(source),
22
22
  /** Adds hunger or thirst (0-100 scale; a negative amount takes it away), a food or drink's value. */
23
23
  add: (source: number, need: "hunger" | "thirst", amount: number): boolean =>
24
24
  core.AddNeed(source, need, amount),
25
+ /** Sets hunger or thirst to a value (0-100, clamped); false when the player has no character. */
26
+ set: (source: number, need: "hunger" | "thirst", value: number): boolean =>
27
+ core.SetNeed(source, need, value),
25
28
  };
@@ -0,0 +1,37 @@
1
+ import {
2
+ CORE,
3
+ type Warrant,
4
+ type WarrantAdd,
5
+ type WarrantPage,
6
+ type WarrantResult,
7
+ type WarrantTarget,
8
+ } from "@aifivem/shared";
9
+ import { resourceExport } from "../fivem/exports";
10
+
11
+ const core = resourceExport(CORE.resource);
12
+
13
+ /** A callback export as a promise (no promise crosses a resource boundary). */
14
+ const ask = <T>(call: (done: (value: T) => void) => void): Promise<T> =>
15
+ new Promise((resolve) => call(resolve));
16
+
17
+ /**
18
+ * ai-core's own warrants (by character, loaded or not; logged on ai-core's `warrants` channel). Whether they count in
19
+ * `mdt.hasWarrant` is ai-core's panel setting `warrants` (`docs/compat/mdt.md`).
20
+ */
21
+ export const warrants = {
22
+ /** Issues a warrant (`minutes` null or left out = until cleared): `{ ok, id }` or `{ ok: false, error }` (ai-core lang key). */
23
+ add: (warrant: WarrantAdd): Promise<WarrantResult> =>
24
+ ask((done) => core.AddWarrant(warrant, done)),
25
+ /** Clears one active warrant; false when no active warrant has that id. */
26
+ clear: (id: number, by?: number | string): Promise<boolean> =>
27
+ ask((done) => core.ClearWarrant(id, by, done)),
28
+ /** Clears every active warrant of a character; resolves how many. */
29
+ clearAll: (target: WarrantTarget, by?: number | string): Promise<number> =>
30
+ ask((done) => core.ClearWarrants(target, by, done)),
31
+ /** A character's active warrants, newest first; null when the target names no character. */
32
+ of: (target: WarrantTarget): Promise<Warrant[] | null> =>
33
+ ask((done) => core.GetWarrants(target, done)),
34
+ /** Every active warrant, newest first, 25 a page (`cursor` = the last page's `next`). */
35
+ page: (cursor?: number | null): Promise<WarrantPage> =>
36
+ ask((done) => core.ListWarrants(cursor, done)),
37
+ };