AI Core

Phone and appearance

The player's phone through ai-core (numbers, mails, texts, notifications) and characters' stored looks through whatever clothing script runs.

TypeScript
import { phone, appearance } from "@aicore-fivem/lib/server";

phone

The player's phone through ai-core: the first phone script that runs (tgiann-phone, lb-phone...) answers. Without a phone script every call answers null or false. The Lua twins on aiLib.phone have the same names and argument order.

phone.number

Side: Server · Waits: no

Signature
phone.number(source: number): string | null
Lua
local number = aiLib.phone.number(source)

Returns the player's phone number, or null (Lua nil) when they have none or no phone script runs.

const number = phone.number(source);
if (!number) return fail("NO_PHONE_NUMBER");

phone.sourceOf

The online player who owns a phone number.

Side: Server · Waits: no

Signature
phone.sourceOf(number: string): number | null
Lua
local source = aiLib.phone.sourceOf(number)

Returns the server id, or null (Lua nil) when nobody online has that number.

const owner = phone.sourceOf("555-0101");
if (owner !== null) notify(owner, "Your phone is ringing");

phone.hasPhone

Whether the player carries a phone.

Side: Server · Waits: no

Signature
phone.hasPhone(source: number): boolean
Lua
local has = aiLib.phone.hasPhone(source)

Returns true when they have one; false without, or without a phone script.

if (!phone.hasPhone(source)) return fail("NEED_PHONE");

phone.mail

Sends a mail to a player's phone.

Side: Server · Waits: no

Signature
phone.mail(to: number | string, mail: PhoneMail): boolean
Lua
local ok = aiLib.phone.mail(to, mail)

Prop

Type

The type is PhoneMail.

Returns true when sent, false otherwise.

phone.mail(source, {
  sender: "Downtown Cab Co.",
  subject: "Your shift",
  message: "Pick up the taxi at the depot.",
});

phone.message

Sends a text message.

Side: Server · Waits: no

Signature
phone.message(from: string, to: number | string, text: string): boolean
Lua
local ok = aiLib.phone.message(from, to, text)

Prop

Type

Returns true when sent, false otherwise.

phone.message("Dealer", source, "Meet me behind the gas station.");

phone.notify

Shows a notification inside the phone.

Side: Server · Waits: no

Signature
phone.notify(source: number, notification: PhoneNotification): boolean
Lua
local ok = aiLib.phone.notify(source, notification)

Prop

Type

The type is PhoneNotification.

Returns true when shown, false otherwise.

phone.notify(source, { title: "Bank", message: "Salary paid: $250", app: "bank" });

appearance

Characters' stored looks through ai-core's appearance layer, whatever clothing script runs (ai-appearance, tgiann-clothing).

appearance.get

A character's stored look, loaded or not. Use it to dress a ped that stands in for a character (a sleeping body, a mannequin): hand the result unchanged to the client's appearance.apply (Lib: client).

Side: Server · Waits: yes (Promise in TypeScript, yields the thread in Lua)

Signature
appearance.get(charId: number): Promise<CharacterAppearance | null>
Lua
local look = aiLib.appearance.get(charId) -- { model, data } or nil, call inside a thread

Prop

Type

Returns

Promise<CharacterAppearance | null>: CharacterAppearance is { model, data } (the ped model hash and the clothing script's own look data). null when the character has none, no clothing script runs, or ai-core is stopped.

Example

import { appearance, online, playersNear } from "@aicore-fivem/lib/server";

async function sendLook(source: number) {
  const charId = online.charId(source);
  if (charId === undefined) return;
  const look = await appearance.get(charId);
  if (!look) return;
  // Only the players near this character need the look.
  for (const other of playersNear(source, 100)) emitNet("my-sleepers:look", other, source, look);
}

appearance.provider

Side: Server · Waits: no

Signature
appearance.provider(): string | null
Lua
local name = aiLib.appearance.provider()

Returns the clothing script that answers, or null (Lua nil) when none runs.

console.log(`looks through ${appearance.provider() ?? "nothing"}`);

On this page