Stress and needs
Add or relieve stress and refill hunger and thirst through whichever HUD keeps them.
Stress, hunger and thirst live in the HUD script that shows them. ai-core forwards changes to the first HUD running that keeps stress: tgiann-lumihud, tgiann-hudv2, tgiann-modern-hud, qb-hud, ps-hud, then ai-hud. Never call a HUD's own events or exports (hud:server:GainStress, ai-hud's AddNeed).
GetStressSystem
The resource name of the HUD ai-core gives stress to.
Side: Server · Waits: no · Lib: stress.provider()
GetStressSystem(): string | nulllocal system = exports['ai-core']:GetStressSystem() -- string or nilParameters
None.
Returns
string | null: the HUD's resource name. null when no HUD with stress runs (stress changes are then dropped).
Example
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
Adds stress to a player, or relieves it with a negative amount.
Side: Server · Waits: no · Lib: stress.gain(source, amount) and stress.relieve(source, amount) (both take a positive amount)
AddStress(source: number, amount: number): booleanlocal ok = exports['ai-core']:AddStress(source, 5) -- more stress
local ok2 = exports['ai-core']:AddStress(source, -10) -- less stressParameters
Prop
Type
Returns
boolean: true when the change was handed to the HUD. false when source or amount is out of range, no HUD with stress runs, or the HUD failed. The HUD clamps the result to 0-100.
Example
import { resourceExport } from "@aicore-fivem/lib/server";
const core = resourceExport("ai-core");
// Robbing a store is stressful; smoking a joint relaxes.
export function robberyStarted(source: number): void {
core.AddStress(source, 8);
}
core.RegisterUsableItem("joint", (source) => {
core.AddStress(source, -15);
});Stress from shooting and fast driving is the HUD's own job. Use AddStress for events your script knows about.
RefillNeeds
Fills a player's hunger and thirst to full through the HUD that keeps them. Use it after a revive or a hospital stay.
Side: Server · Waits: no · Lib: needs.refill
RefillNeeds(source: number): booleanlocal ok = exports['ai-core']:RefillNeeds(source)Parameters
Prop
Type
Returns
boolean: true when the refill was handed to the HUD. Without a HUD that keeps needs, ai-core sets the character metadata hunger and thirst to 100 itself (and tells QB-style HUDs with hud:client:UpdateNeeds) and answers true. false when the player has no loaded character or the HUD failed.
Example
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 };
// A hospital bed: revive, full health, full stomach.
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 };
});