Skip to content
M2O Scripting APIScripting reference
Global objectServer APIGenerated

World

const World: object

Defined in: server/api.d.ts:921

Controls replicated world state and exposes collections of connected players and spawned vehicles.

readonly players: EntityCollection<Player>

Connected players visible to scripts; walk it with forEach, or filter and map for an array.

readonly vehicles: EntityCollection<Vehicle>

Spawned vehicles visible to scripts; walk it with forEach, or filter and map for an array.

createExplosion(x, y, z, weaponId?, owner?): void

Detonates an explosion at a world-space position on every client.

number

World-space X coordinate of the blast.

number

World-space Y coordinate of the blast.

number

World-space Z coordinate of the blast.

number

Optional explosive weapon whose blast to reproduce: 20 Grenade MkII (default), 21 Molotov, 19 Bazooka, 7 Sicily grenade, 16 Stielhandgranate.

number | Player

Optional player credited with any kill the blast causes.

void

cycleTrafficLights(): number

Advances the replicated traffic-light cycle by one epoch.

number

The new monotonically increasing traffic epoch.

getDrivingCoeff(): number

Returns the replicated arcade driving coefficient.

number

A value from 0 for simulation handling to 1 for arcade handling.

getDrivingMode(): "arcade" | "simulation" | "custom"

Returns the named driving-mode category for the current coefficient.

"arcade" | "simulation" | "custom"

Arcade at coefficient 1, simulation at 0, or custom for an intermediate value.

getLightGroup(group): number

Returns the level this server drives for a light group.

string | number

Light group name or index.

number

The level from 0 to 1, or -1 when the group is left to the game’s own day/night lighting.

getOutdoorAmbient(): OutdoorAmbientColor | null

Returns the replicated outdoor ambient colour override.

OutdoorAmbientColor | null

The overriding colour, or null when the outdoor ambient is left to the weather template.

getPlayersWithinRange(x, y, z, range, virtualWorld?): Player[]

Lists the players whose replicated position is within range of a point. This is a distance test, not a trigger volume – for containment and enter/exit events use Volume, which runs on the game’s own physics sensors.

number

World-space X coordinate of the query centre.

number

World-space Y coordinate of the query centre.

number

World-space Z coordinate of the query centre.

number

Radius in world units.

number

Restrict the answer to one virtual world; every world by default.

Player[]

The players in range.

getRainIntensity(): number

Returns the replicated rain-intensity override.

number

A value from 0 to 100, or -1 when no override is active.

getSeason(): "summer" | "winter"

Returns the season this server declares in its mod.season configuration.

"summer" | "winter"

The active season; the world’s ground, city and vehicle models are fixed to it, so weather templates should match.

getTime(): WorldTime

Returns the current replicated game time as clock components.

WorldTime

The current hour and minute.

getTimeNormalized(): number

Returns the current game time in the engine’s normalized representation.

number

A value from 0 inclusive to 1 exclusive, where 0 is midnight and 0.5 is noon.

getTimeScale(): number

Returns the current game-clock speed multiplier.

number

The non-negative replicated time scale.

getTrafficEpoch(): number

Returns the current replicated traffic-light epoch.

number

The current traffic cycle counter.

getWeather(): string

Returns the active replicated weather template.

string

The configured template name, or an empty string when world state is unavailable.

policeDispatch(event, x?, y?, z?, range?): void

Broadcasts a police radio event globally or around a world-space position.

string | number

Police radio event name or numeric event identifier.

number

Optional world-space X coordinate; all four location arguments must be supplied together.

number

Optional world-space Y coordinate.

number

Optional world-space Z coordinate.

number

Optional dispatch radius around the supplied position.

void

resetLightGroup(group): void

Hands one light group back to the game’s day/night lighting. The group keeps its current appearance until the next in-game weather or time change.

string | number

Light group name or index.

void

resetLighting(): void

Drops every light-group and outdoor-ambient override, handing the whole city back to the game’s day/night lighting.

void

setBlackout(enabled?): void

Switches every fixed city light group at once: lampsOther, signalLights, advertLights, shopLights, lamps and trafficLights. Vehicle headlights and the outdoor ambient colour are left alone.

boolean

True to black the city out, false to switch it back on; defaults to true.

void

setDrivingMode(mode): void

Sets the replicated vehicle driving model.

number | "arcade" | "simulation"

Arcade, simulation (or sim), or a custom arcade coefficient from 0 to 1; numeric values are clamped.

void

setLightGroup(group, level): void

Drives one city light group. The group stays under server control, surviving the game’s own weather updates, until it is released with resetLightGroup or resetLighting.

string | number

Light group to drive, as a name or its index: lampsOther (0), signalLights (1), advertLights (2), shopLights (3), lamps (4), headlights (5), trafficLights (6), group7 (7), outdoorAmbient (8).

number | boolean

True or false to switch the whole group, or a number from 0 to 1 to light that fraction of it at random; the fraction also applies to lights that stream in later.

void

setOutdoorAmbient(r, g, b): void

Overrides the global outdoor ambient colour, including outdoor lights that stream in afterwards.

number

Red channel from 0 to 1; values outside the range are clamped.

number

Green channel from 0 to 1.

number

Blue channel from 0 to 1.

void

setRainIntensity(value): void

Sets or disables the replicated rain-intensity override.

number

Rain override from 0 to 100; a negative value disables the override.

void

setTime(hour, minute?): void

Sets the replicated game time.

number

Hour of day; the combined time is clamped to the valid 24-hour range.

number

Minute of the hour; defaults to zero.

void

setTimeScale(scale): void

Sets how quickly replicated game time advances.

number

Game-clock speed multiplier; negative values are clamped to zero.

void

setWeather(templateName): void

Sets the active replicated weather template.

string

Mafia II weather template name to replicate to clients.

void