AI Core

Phone

Phone numbers, mails, text messages and phone notifications through whichever phone script the server runs.

Phone calls go through ai-core, never through a phone script's own exports. ai-core forwards each call to the first phone script running (tgiann-phone, lb-phone, gksphone and the others in the compatibility list). While no phone runs, every call answers null or false.

GetPhoneNumber

A player's phone number.

Side: Server · Waits: no · Lib: phone.number

Signature
GetPhoneNumber(source: number): string | null
Lua
local number = exports['ai-core']:GetPhoneNumber(source) -- string or nil

Parameters

Prop

Type

Returns

string | null: the number as the phone script writes it. null when the player has none, no phone runs or source is not a number.

Example

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

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

// A business card item shows the owner's number.
onClientCallback("myscript:myNumber", (source) => {
  const number = core.GetPhoneNumber(source);
  return number ? { ok: true, number } : fail("NO_PHONE_NUMBER");
});

GetSourceByPhone

The online player who has a phone number.

Side: Server · Waits: no · Lib: phone.sourceOf

Signature
GetSourceByPhone(number: string): number | null
Lua
local src = exports['ai-core']:GetSourceByPhone('5551234') -- number or nil

Parameters

Prop

Type

Returns

number | null: the server id. null when that number's owner is not online, the number is unknown, no phone runs or number is not a text.

Example

import { notify, resourceExport } from "@aicore-fivem/lib/server";
import { Locale } from "common";

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

/** A taxi job tells the caller their cab is on the way, if they are online. */
export function cabOnTheWay(callerNumber: string): void {
  const caller = core.GetSourceByPhone(callerNumber);
  if (caller !== null) notify(caller, Locale("NOTIFY_CAB_COMING"), "info");
}

HasPhone

Whether a player has a phone (for phone scripts that need a phone item, whether they carry one).

Side: Server · Waits: no · Lib: phone.hasPhone

Signature
HasPhone(source: number): boolean
Lua
local has = exports['ai-core']:HasPhone(source)

Parameters

Prop

Type

Returns

boolean: true when the phone script says the player has a phone. false when not, when no phone runs or source is not a number.

Example

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

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

// A job that hands out tasks by text message needs a phone.
onClientCallback("myscript:startDeliveries", (source) =>
  core.HasPhone(source) ? { ok: true } : fail("NEED_PHONE"),
);

SendPhoneMail

Sends a mail to a player's phone.

Side: Server · Waits: no · Lib: phone.mail

Signature
SendPhoneMail(to: number | string, mail: PhoneMail): boolean
Lua
local sent = exports['ai-core']:SendPhoneMail(source, { sender = 'LS Customs', subject = 'Invoice', message = '...' })

Parameters

Prop

Type

PhoneMail

Prop

Type

Texts are shown as given: pass translated texts. See PhoneMail.

Returns

boolean: true when the phone script accepted the mail. false when the player has no number, subject or message is missing, no phone runs or it refused.

Example

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

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

/** The heist contact mails the location after the job was accepted. */
export function mailHeistLocation(source: number, street: string): void {
  core.SendPhoneMail(source, {
    sender: Locale("MAIL_CONTACT"),
    subject: Locale("MAIL_HEIST_SUBJECT"),
    message: Locale("MAIL_HEIST_BODY", street),
  });
}

SendPhoneMessage

Sends a text message from one number to a player or number.

Side: Server · Waits: no · Lib: phone.message

Signature
SendPhoneMessage(from: string, to: number | string, text: string): boolean
Lua
local sent = exports['ai-core']:SendPhoneMessage('Dispatch', source, 'Your cab is here.')

Parameters

Prop

Type

Returns

boolean: true when the phone script accepted the message. false when the receiver has no number, from or text is not a text, no phone runs or it refused.

Example

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

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

/** The next delivery address arrives by text. */
export function textNextStop(source: number, street: string): void {
  if (!core.SendPhoneMessage(Locale("SENDER_DISPATCH"), source, Locale("TEXT_NEXT_STOP", street)))
    console.log(`player ${source} could not get the text`);
}

PhoneNotify

Shows a notification on a player's phone.

Side: Server · Waits: no · Lib: phone.notify

Signature
PhoneNotify(source: number, notification: PhoneNotification): boolean
Lua
local shown = exports['ai-core']:PhoneNotify(source, { title = 'Bank', message = 'Salary paid', app = 'bank' })

Parameters

Prop

Type

PhoneNotification

Prop

Type

See PhoneNotification.

Returns

boolean: true when the phone script showed it. false when title is missing, no phone runs, source is not a number or it refused.

Example

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

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

/** Tells the owner their car was towed. */
export function towedNotice(source: number, plate: string): void {
  core.PhoneNotify(source, { title: Locale("PHONE_TOW_TITLE"), message: Locale("PHONE_TOW_TEXT", plate) });
}

On this page