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

Stres ve ihtiyaçlar

Bunları tutan HUD hangisiyse onun üzerinden stres ekle ya da azalt ve açlık ile susuzluğu doldur.

Stres, açlık ve susuzluk onları gösteren HUD script’inde yaşar. ai-core değişiklikleri stres tutan çalışan ilk HUD’a iletir: tgiann-lumihud, tgiann-hudv2, tgiann-modern-hud, qb-hud, ps-hud, sonra ai-hud. Asla bir HUD’ın kendi event’lerini ya da export’larını çağırma (hud:server:GainStress, ai-hud’ın AddNeed’i).

GetStressSystem

ai-core’un stres verdiği HUD’ın resource adı.

Taraf: Server · Bekler: hayır · Lib: stress.provider()

İmza
GetStressSystem(): string | null
Lua
local system = exports['ai-core']:GetStressSystem() -- string ya da nil

Parametreler

Yok.

Dönüş değeri

string | null: HUD’ın resource adı. Stresli bir HUD çalışmıyorsa null (stres değişiklikleri o zaman atılır).

Örnek

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

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

addCommand("stresssystem", { help: "Shows the HUD that keeps stress", restricted: true }, () => {
  console.log(core.GetStressSystem() ?? "none: stress is dropped");
});

AddStress

Bir oyuncuya stres ekler ya da negatif bir miktarla azaltır.

Taraf: Server · Bekler: hayır · Lib: stress.gain(source, amount) ve stress.relieve(source, amount) (ikisi de pozitif bir miktar alır)

İmza
AddStress(source: number, amount: number): boolean
Lua
local ok = exports['ai-core']:AddStress(source, 5)    -- daha fazla stres
local ok2 = exports['ai-core']:AddStress(source, -10) -- daha az stres

Parametreler

Prop

Type

Dönüş değeri

boolean: değişiklik HUD’a verildiğinde true. source ya da amount aralık dışındaysa, stresli bir HUD çalışmıyorsa ya da HUD başarısız olduysa false. HUD sonucu 0-100 arasına sıkıştırır.

Örnek

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

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

// Bir dükkanı soymak stresli; bir joint içmek rahatlatır.
export function robberyStarted(source: number): void {
  core.AddStress(source, 8);
}

core.RegisterUsableItem("joint", (source) => {
  core.AddStress(source, -15);
});

Ateş etmekten ve hızlı sürmekten gelen stres HUD’ın kendi işidir. AddStress’i script’inin bildiği olaylar için kullan.

RefillNeeds

Bir oyuncunun açlık ve susuzluğunu onları tutan HUD üzerinden tamamen doldurur. Bir canlandırmadan ya da hastanede kaldıktan sonra kullan.

Taraf: Server · Bekler: hayır · Lib: needs.refill

İmza
RefillNeeds(source: number): boolean
Lua
local ok = exports['ai-core']:RefillNeeds(source)

Parametreler

Prop

Type

Dönüş değeri

boolean: doldurma HUD’a verildiğinde true. İhtiyaçları tutan bir HUD yokken ai-core karakter metadata’sındaki hunger ve thirst’ü kendisi 100’e ayarlar (ve QB tarzı HUD’lara hud:client:UpdateNeeds ile bildirir) ve true cevabı verir. Oyuncunun yüklü karakteri yoksa ya da HUD başarısız olduysa false.

Örnek

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

const core = resourceExport("ai-core");
const BED = { x: 317.8, y: -585.2, z: 43.3 };

// Bir hastane yatağı: canlandırma, tam can, tok karın.
onClientCallback("myscript:hospitalBed", { guards: [near(BED, 2)], lock: true }, (source) => {
  if (!core.RemoveMoney(source, "bank", 500, "hospital_bed")) return fail("NOT_ENOUGH_MONEY");
  if (!core.RevivePlayer(source)) core.HealPlayer(source);
  core.RefillNeeds(source);
  return { ok: true };
});

Bu sayfada