AI Core
API başvurusuLib: server

Komutlar

addCommand: ayrıştırılmış argümanlar, ACE yetkileri, sohbet önerileri ve ai-core’un admin panelinde bir satırla sohbet komutları.

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

addCommand

Bir sohbet komutu (ve konsol komutu) kaydeder. Argümanlar handler’ın çalışmadan önce ayrıştırılır ve kontrol edilir, yetki ACE ile kontrol edilir, sohbet önerileri yalnızca komutu kullanabilen oyunculara gider ve ai-core’un admin paneli onu Commands sekmesinde listeler. Her server komutu için çıplak bir RegisterCommand yerine bunu kullan.

Taraf: Server · Bekler: hayır

Signature
addCommand<P extends readonly CommandParam[]>(
  name: string | string[],
  options: CommandOptions<P>,
  handler: (source: number, args: CommandArgs<P>, raw: string) => unknown,
): void
Lua
aiLib.addCommand(name, options, handler) -- handler(source, args, raw)

Parametreler

Prop

Type

CommandOptions

Prop

Type

CommandParam

Prop

Type

Yanlış girdide oyuncunun gördüğü

Handler çalışmadan önce lib, ai-core’un metinleriyle bir ai-core bildirimiyle (source 0 için bir konsol satırıyla) cevap verir:

DurumMetin (İngilizce)
Yetki yokYou are not allowed to use this command.
Zorunlu bir argüman eksik<name> is missing.
number / playerId bir sayı değil<name> must be a number.
playerId çevrimiçi bir oyuncu değilNo player is online with id <value>.
Herhangi bir argüman hatasından sonraUsage: /name <required> [optional]

Dönüş değeri

void. TypeScript’te name boş bir liste ise hata fırlatır.

Örnek

import { addCommand, medical, notify, createLocale } from "@aicore-fivem/lib/server";

const Locale = createLocale();

addCommand(
  ["heal", "h"],
  {
    help: Locale("CMD_HEAL"),
    params: [{ name: "id", type: "playerId", help: Locale("CMD_P_ID"), optional: true }],
    restricted: true,
  },
  (source, args) => {
    const target = args.id ?? source; // args.id, number | undefined tipindedir
    if (target === 0) return; // konsol bir oyuncu belirtmek zorunda
    if (medical.heal(target) && source > 0) notify(source, Locale("HEALED"), "success");
  },
);

addCommand(
  "announce",
  {
    help: "Sends a message to everyone",
    params: [{ name: "text", type: "longString" }],
    restricted: ["group.admin", "ai.admin"],
  },
  (_source, { text }) => {
    for (const player of getPlayers()) notify(Number(player), text, "info", 8000);
  },
);

Yetkileri asla handler içinde elle kontrol etme: bunu restricted yapar ve sohbet önerileri ona uyar. Bir principal listesi için ai-core her birine command.<name> verir; bunun için permission.cfg içinde add_ace resource.ai-core command.add_ace allow ve add_ace resource.ai-core command.remove_ace allow gerekir. Meslek ve çete rütbeleri principal’dır (ai.job.police); bu yüzden bir oyuncunun mesleği ya da çetesi değiştiğinde öneriler güncellenir.

TypeScript’te args tipini params’tan alır: args.id number’dır, isteğe bağlıysa number | undefined. Birkaç komutun paylaştığı bir param listesi as const ile tanımlanmalıdır; yoksa adlar ve tipler genişler ve args onları kaybeder.

Bu sayfada