AI Core

Logs

Send your resource's logs through ai-core to Discord, Fivemanage, FiveM Stats and the console, and describe your log channels.

Every resource logs through ai-core. Your resource names a channel (purchases, robberies) and writes a message; ai-core decides where it goes. The server owner turns providers on in the admin panel (console, Discord, Fivemanage, FiveM Stats), sets the minimum level, and pastes Discord webhook urls per resource and channel. A resource never posts to a webhook or a log service itself, and never holds a webhook url.

Pass the players involved as source and target instead of writing their names into the message: ai-core adds each player's name, character, citizen id and identifiers (the IP only when the panel allows it).

Log

Sends one log entry of your resource.

Side: Server · Waits: no · Lib: aiLog(channel, message, options?) (Lua: aiLib.aiLog; both print to the console instead while ai-core is not running)

Signature
Log(channel: string, message: string, options?: LogOptions): void
Lua
exports['ai-core']:Log('purchases', 'Bought a car', { source = source, metadata = { price = 25000 } })

Parameters

Prop

Type

LogOptions

Prop

Type

See LogOptions and LogLevel.

Returns

Nothing. The entry is dropped without a word when its level is below the panel's minimum or its channel is switched off with LogChannels.

Example

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

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

onClientCallback("myscript:buyCar", { lock: true }, (source) => {
  const price = 25_000;
  if (!core.RemoveMoney(source, "bank", price, "car_purchase")) return fail("NOT_ENOUGH_MONEY");
  // ... create and store the car
  core.Log("purchases", "Bought a car", { source, metadata: { model: "sultan", price } });
  return { ok: true };
});

Logs are for the server owner, so the message stays English and is not translated. Keep the message short and put values into metadata, where log services can filter them.

LogChannels

Describes your resource's channels: their dataset name for Fivemanage and FiveM Stats, and whether each is on. Call it once when your resource starts. Channels you never describe still work with the defaults.

Side: Server · Waits: no · Lib: aiLogChannels(channels)

Signature
LogChannels(channels: Record<string, LogChannel>): void
Lua
exports['ai-core']:LogChannels({ purchases = { dataset = 'myscript-sales' }, debug = { active = false } })

Parameters

Prop

Type

LogChannel

Prop

Type

See LogChannel.

Returns

Nothing. A second call replaces the whole description of your resource. It is dropped when your resource stops. A value that is not a table does nothing.

Example

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

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

// Once at start.
core.LogChannels({
  purchases: { dataset: "myscript-sales" },
  robberies: { dataset: "myscript-crime" },
  debug: { active: false },
});

Webhook urls never go here or anywhere in your resource: the server owner sets them in ai-core's panel, which keeps them in a file that is not shared.

On this page