AI Core

Metadata and settings

Read and write a character's metadata bag, read the server's branding and the list of outdated scripts.

GetMeta

One value from a character's metadata: a free bag of named values saved with the character. ESX and QB scripts keep their extra character data there through the bridge (hunger, thirst, armor, isdead...), and your script can keep small values of its own.

Side: Server · Waits: no · Lib: none

Signature
GetMeta(src: number, key: string): unknown
Lua
local value = exports['ai-core']:GetMeta(source, 'myscript_xp') -- any value or nil

Parameters

Prop

Type

Returns

unknown: the stored value (number, text, boolean, list or table), as it was set. null when the key is not set or the player has no loaded character. Check the type before using it: the value may have been written by another script or an older version of yours.

Example

import { resourceExport } from "@aicore-fivem/lib/server";

const core = resourceExport("ai-core");

/** The character's fishing level, 1 when none was stored yet. */
export function fishingLevel(source: number): number {
  const value = core.GetMeta(source, "myscript_level");
  return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : 1;
}

SetMeta

Stores one value in a character's metadata. The value is saved with the character's next periodic save (panel setting, every 5 minutes by default), on logout and when the server stops.

Side: Server · Waits: no · Lib: none

Signature
SetMeta(src: number, key: string, value: unknown): boolean
Lua
local ok = exports['ai-core']:SetMeta(source, 'myscript_level', 3)

Parameters

Prop

Type

Returns

boolean: true when the value was stored (or removed). false when the player has no loaded character or key is not a text.

The change reaches the player's own game at once and fires the server event ai-core:metaChanged (src, key, value).

Example

import { resourceExport } from "@aicore-fivem/lib/server";

const core = resourceExport("ai-core");

/** One level up after enough catches. */
export function levelUp(source: number): void {
  const level = core.GetMeta(source, "myscript_level");
  const next = (typeof level === "number" ? level : 1) + 1;
  core.SetMeta(source, "myscript_level", next);
}

Metadata is for small values that belong to one character (a level, a flag, a few numbers). Lists that grow (a history, every catch) and anything you search or count across characters belong in your own database table. Values in metadata are not saved at once: money and items never go there.

GetBranding

The server's name, subtitle, taglines and background picture from the panel's General settings. Use it to show the same name on your own full-screen menus.

Side: Server · Waits: no · Lib: none

Signature
GetBranding(): Branding
Lua
local brand = exports['ai-core']:GetBranding() -- table

Parameters

None.

Returns

Branding: a copy with name, subtitle, tagline, taglineSub and background ("skyline" or "wet-drive", a picture in ai-core). See Branding.

Example

import { onClientCallback, resourceExport } from "@aicore-fivem/lib/server";

const core = resourceExport("ai-core");

// The welcome screen shows the server name.
onClientCallback("myscript:welcome", () => {
  const { name, tagline } = core.GetBranding();
  return { ok: true, name, tagline };
});

GetUpdates

The scripts with a newer GitHub release than the version running, from ai-core's update check. ai-core asks GitHub at most once every 6 hours per script (and when a script starts) for every started script with a repository line in its fxmanifest.lua, unless the panel's Check for updates is off.

Side: Server · Waits: no · Lib: none

Signature
GetUpdates(): UpdateInfo[]
Lua
local outdated = exports['ai-core']:GetUpdates() -- list of tables

Parameters

None.

Returns

UpdateInfo[]: one entry per outdated script with resource, label (the name people know it by), current (running version), latest (newest release) and url (the release page). An empty list when everything is current or nothing was checked yet (the first check runs 15 seconds after start). See UpdateInfo.

Example

import { addCommand, resourceExport } from "@aicore-fivem/lib/server";

const core = resourceExport("ai-core");

addCommand("outdated", { help: "Lists outdated scripts", restricted: true }, () => {
  for (const u of core.GetUpdates()) console.log(`${u.label}: ${u.current} -> ${u.latest} (${u.url})`);
});

On this page