AI Core

Weather and time sync

Pause the server's weather and time sync on one player's game while your script sets its own (an interior, a scene), resume it, and read whether it is paused.

The weather script (ai-weathersync, or a third-party one) keeps every player on the server's weather and clock. When your script needs its own weather or time on one player's screen (a dark interior, a character creator, a cut scene), pause the sync first, otherwise the weather script overwrites your values a moment later.

Pausing works with reasons, like the HUD: the sync stays paused while at least one reason is set and runs again when the last one is cleared. Reasons belong to the resource that set them and are removed when it stops. ai-core tells the weather script through its own client event ai-core:client:worldSync and through the common pause events third-party weather scripts listen to (qb-weathersync, cd_easytime, vSync, av_weather). The other way round, when a script sends one of those events itself, ai-core counts it as a reason too, so one script's resume never ends another script's pause.

PauseWorldSync

Pauses the weather and time sync on this player's game under a reason of your resource.

Side: Client · Waits: no

Signature
PauseWorldSync(reason: string): void
Lua
exports['ai-core']:PauseWorldSync(reason) -- or aiLib.world.pauseSync(reason)

Parameters

Prop

Type

Returns

Nothing. A reason that is not a string is ignored.

Example

resource/client/interior.ts
import { world } from "@aicore-fivem/lib/client";

// A dark, clear night inside a custom interior, back to the server's weather on leaving.
export function enterInterior(): void {
  world.pauseSync("interior"); // same as resourceExport("ai-core").PauseWorldSync("interior")
  NetworkOverrideClockTime(23, 0, 0);
  SetWeatherTypeNowPersist("CLEAR");
}

export function leaveInterior(): void {
  NetworkClearClockTimeOverride();
  world.resumeSync("interior");
}

The pause only stops the sync. Setting your own weather and time, and clearing them when you are done, is your script's job.

ResumeWorldSync

Clears one pause reason of your resource. The sync runs again, and the weather script puts the server's weather and clock back, when no reason is left.

Side: Client · Waits: no

Signature
ResumeWorldSync(reason: string): void
Lua
exports['ai-core']:ResumeWorldSync(reason) -- or aiLib.world.resumeSync(reason)

Parameters

Prop

Type

Returns

Nothing.

Example

See the example of PauseWorldSync.

IsWorldSyncPaused

Tells whether the sync is paused right now by any resource or third-party pause event. A weather script that starts later reads it once; afterwards it follows the client event ai-core:client:worldSync.

Side: Client · Waits: no

Signature
IsWorldSyncPaused(): boolean
Lua
local paused = exports['ai-core']:IsWorldSyncPaused() -- boolean

Parameters

None.

Returns

boolean: true while at least one reason is set, false when the sync runs.

Example

resource/client/weather.ts
import { resourceExport } from "@aicore-fivem/lib/client";
import { CORE } from "@aicore-fivem/shared";

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

// A weather script of your own: stop applying the server's weather while paused.
let paused = core.IsWorldSyncPaused();
on(CORE.clientWorldSyncEvent, (value: boolean) => {
  paused = value;
});

export const shouldApplyWeather = (): boolean => !paused;

On this page