AI Core
API başvurusuAI Core: server export’ları

Saat ve hava

Sunucunun çalıştırdığı hava script’i hangisiyse onun üzerinden havayı ve oyun saatini, karartmayı ve dondurulmuş zamanı oku ve ayarla.

Saat ve hava ai-core üzerinden gider, asla bir hava script’inin kendi export’ları ya da event’leri üzerinden değil. ai-core her çağrıyı çalışan ilk hava script’ine iletir: Renewed-Weathersync, av_weather, cd_easytime, sonra qb-weathersync (ai-weathersync bu adla cevap verir). Hepsi qb-weathersync sözleşmesine uyar. Hiçbiri çalışmıyorken her çağrı null ya da false cevabı verir.

Senkronu tek bir oyuncunun oyununda duraklatmak için (kendi ışığı olan bir iç mekan, bir ara sahne) client tarafını kullan (PauseWorldSync, lib world.pauseSync); bkz. Client export’ları.

GetWeather

Şu anki hava tipi.

Taraf: Server · Bekler: hayır · Lib: world.getWeather

İmza
GetWeather(): string | null
Lua
local weather = exports['ai-core']:GetWeather() -- 'EXTRASUNNY', 'RAIN'... ya da nil

Parametreler

Yok.

Dönüş değeri

string | null: büyük harfle hava tipi (EXTRASUNNY, CLEAR, RAIN, THUNDER...). Hiçbir hava script’i çalışmıyorsa null.

Örnek

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

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

/** Sokak yarışları yağmurda daha fazla öder. */
export function raceBonus(): number {
  const weather = core.GetWeather();
  return weather === "RAIN" || weather === "THUNDER" ? 1.25 : 1;
}

SetWeather

Herkes için havayı ayarlar.

Taraf: Server · Bekler: hayır · Lib: world.setWeather (tipli Weather adlarını alır)

İmza
SetWeather(type: string): boolean
Lua
local ok = exports['ai-core']:SetWeather('RAIN')

Parametreler

Prop

Type

Dönüş değeri

boolean: hava script’i kabul ettiğinde true. type metin değilse, script reddettiyse (bilinmeyen bir tip) ya da hiçbir hava script’i çalışmıyorsa false.

Örnek

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

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

addCommand("weather", { help: "Sets the weather", params: [{ name: "type", type: "string" }], restricted: true }, (_source, args) => {
  const type = args.type.toUpperCase();
  if (!isWeather(type)) return console.log("unknown weather type");
  core.SetWeather(type);
});

GetTime

Oyun saati (oyun içi saat).

Taraf: Server · Bekler: hayır · Lib: world.getTime

İmza
GetTime(): { hour: number; minute: number } | null
Lua
local time = exports['ai-core']:GetTime() -- { hour, minute } ya da nil

Parametreler

Yok.

Dönüş değeri

{ hour, minute } | null: saat 0-23 ve dakika 0-59. Hiçbir hava script’i çalışmıyorsa null.

Örnek

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

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

// Uyuşturucu satıcısı yalnızca gece satar (oyun saatiyle 22:00 - 05:59).
onClientCallback("myscript:dealer", (source) => {
  const time = core.GetTime();
  const night = time !== null && (time.hour >= 22 || time.hour < 6);
  return night ? { ok: true } : fail("COME_BACK_AT_NIGHT");
});

SetTime

Herkes için oyun saatini ayarlar.

Taraf: Server · Bekler: hayır · Lib: world.setTime

İmza
SetTime(hour: number, minute?: number): boolean
Lua
local ok = exports['ai-core']:SetTime(12, 0)

Parametreler

Prop

Type

Dönüş değeri

boolean: hava script’i kabul ettiğinde true. hour bir sayı değilse, script reddettiyse ya da hiçbir hava script’i çalışmıyorsa false.

Örnek

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

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

addCommand("noon", { help: "Sets the time to 12:00", restricted: true }, () => {
  core.SetTime(12, 0);
});

SetBlackout

Şehrin karartmasını (tüm yapay ışıklar kapalı) açar ya da kapatır.

Taraf: Server · Bekler: hayır · Lib: world.setBlackout

İmza
SetBlackout(on: boolean): boolean
Lua
local ok = exports['ai-core']:SetBlackout(true)

Parametreler

Prop

Type

Dönüş değeri

boolean: hava script’i kabul ettiğinde true. Script’te karartma yoksa, reddettiyse ya da hiçbir hava script’i çalışmıyorsa false.

Örnek

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

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

/** Elektrik santrali sabote edildi: 5 dakika karanlık. */
export function sabotagePowerPlant(): void {
  if (!core.SetBlackout(true)) return;
  setTimeout(() => core.SetBlackout(false), 5 * 60_000);
}

FreezeTime

Oyun saatini durdurur ya da yeniden başlatır.

Taraf: Server · Bekler: hayır · Lib: world.freezeTime

İmza
FreezeTime(on: boolean): boolean
Lua
local ok = exports['ai-core']:FreezeTime(true)

Parametreler

Prop

Type

Dönüş değeri

boolean: hava script’i kabul ettiğinde true. Script zamanı donduramıyorsa, reddettiyse ya da hiçbir hava script’i çalışmıyorsa false.

Örnek

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

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

// Bir etkinlik gecesi: her zaman 21:00.
addCommand("eventnight", { help: "Freezes the clock at 21:00", restricted: true }, () => {
  core.SetTime(21, 0);
  core.FreezeTime(true);
});

Bu sayfada