World
Time and weather through whatever weather script runs, routing buckets from ai-core's allocator, door locks, and stored characters' spawn points.
import { world, buckets, doors, characters } from "@aicore-fivem/lib/server";world
Time and weather through ai-core, whatever weather script runs (Renewed-Weathersync, av_weather, cd_easytime, qb-weathersync). While none runs, reads answer null and changes answer false.
world.getWeather
Side: Server · Waits: no
world.getWeather(): string | nulllocal weather = aiLib.world.getWeather()Returns the current weather type as the weather script reports it (CLEAR, RAIN...), or null while none runs.
const raining = ["RAIN", "THUNDER"].includes(world.getWeather() ?? "");world.setWeather
Sets the weather.
Side: Server · Waits: no
world.setWeather(type: Weather): booleanlocal ok = aiLib.world.setWeather(weather)Prop
Type
Returns true when set, false while no weather script runs or the value is not a string.
import { addCommand, world } from "@aicore-fivem/lib/server";
import { isWeather } from "@aicore-fivem/shared";
addCommand("weather", { restricted: true, params: [{ name: "type", type: "string" }] }, (_source, { type }) => {
const upper = type.toUpperCase();
if (isWeather(upper)) world.setWeather(upper);
});world.getTime
Side: Server · Waits: no
world.getTime(): { hour: number; minute: number } | nulllocal time = aiLib.world.getTime() -- { hour, minute } or nilReturns the in-game time, or null while no weather script runs.
const time = world.getTime();
const night = time !== null && (time.hour >= 22 || time.hour < 6);world.setTime
Sets the in-game time.
Side: Server · Waits: no
world.setTime(hour: number, minute?: number): booleanlocal ok = aiLib.world.setTime(hour, minute)Prop
Type
Returns true when set, false while no weather script runs.
world.setTime(12, 30);world.setBlackout
Turns the city blackout on or off.
Side: Server · Waits: no
world.setBlackout(on: boolean): booleanlocal ok = aiLib.world.setBlackout(on)Returns true when applied, false while no weather script runs or it has no blackout.
world.setBlackout(true); // the power plant was sabotagedworld.freezeTime
Stops or restarts the in-game clock.
Side: Server · Waits: no
world.freezeTime(on: boolean): booleanlocal ok = aiLib.world.freezeTime(on)Returns true when applied, false while no weather script runs or it cannot freeze time.
world.setTime(20, 0);
world.freezeTime(true);buckets
Routing buckets (separate worlds: an apartment interior, an instance) from ai-core's allocator, so no two scripts ever share one. Never pick bucket numbers yourself (1000 + n). No Lua twin: call ai-core's exports AcquireBucket(tag) / ReleaseBucket(id).
buckets.acquire
Takes a free bucket for this resource. It has no population (no ambient peds and cars) and strict entity lockdown.
Side: Server · Waits: no
buckets.acquire(tag: string): numberProp
Type
Returns the bucket id.
import { buckets } from "@aicore-fivem/lib/server";
const bucket = buckets.acquire(`property:${propertyId}`);
SetPlayerRoutingBucket(String(source), bucket);buckets.release
Gives a bucket back once its players are out.
Side: Server · Waits: no
buckets.release(id: number): booleanReturns true when released. Every bucket of a stopped resource goes back by itself.
SetPlayerRoutingBucket(String(source), 0);
buckets.release(bucket);doors
Door locks through ai-core's door lock layer, by the door lock script's own door id. No Lua twin: call ai-core's exports SetDoorLocked, IsDoorLocked.
doors.setLocked
Locks or unlocks a door.
Side: Server · Waits: no
doors.setLocked(id: string, locked: boolean, by?: number): booleanProp
Type
Returns true when a door script took it, false otherwise.
if (outcome === "won") doors.setLocked("bank_vault", false, source);doors.isLocked
Side: Server · Waits: no
doors.isLocked(id: string): boolean | nullReturns true or false, or null when unknown (no door lock, no such door, or the script cannot tell on the server).
if (doors.isLocked("bank_vault") === false) return fail("ALREADY_OPEN");doors.provider
Side: Server · Waits: no
doors.provider(): string | nullReturns the door lock script that answers, or null when none runs.
console.log(`doors through ${doors.provider() ?? "nothing"}`);characters
Stored characters through ai-core. Loaded characters go through online and ai-core's player exports.
characters.setOfflinePosition
Moves a stored (not loaded) character's spawn point, for example a sleeping body that was carried away. ai-core writes it once no load or unload save holds the character.
Side: Server · Waits: no
characters.setOfflinePosition(charId: number, position: { x: number; y: number; z: number; heading?: number }): booleanNo Lua twin: call ai-core's export SetOfflinePosition(charId, position).
Prop
Type
Returns true when accepted. false when the character is loaded or the values are wrong.
characters.setOfflinePosition(sleeperCharId, { x: 340.2, y: -1396.7, z: 32.5, heading: 50 });