Skip to content

players.setVirtualWorld

Puts a player in another virtual world. From then on they see only what is in that virtual world, and the one they left no longer sees them. Every player starts in virtual world 0. A virtual world needs no creating: it is any number from 0 to 2,147,483,647.

Their wanted level goes with them. Whatever they were doing in the old virtual world ends: a parachute closes, a vending machine or gym machine is let go, and a pending players.putInVehicle fails.

Renamed in 0.28 from players.setWorld; see renamed names.

players.setVirtualWorld(player: PlayerTarget, virtualWorld: number, withVehicle?: boolean): Promise<ActionResult>
Name Type Description
player PlayerTarget The player.
virtualWorld number The virtual world, 0 to 2147483647.
withVehicle boolean Optional. For a player in a vehicle: the vehicle goes too, with everyone in it. Defaults to false.

A promise of an ActionResult: applied with createdId the virtual world the player is in, or rejected with:

Code Meaning
invalid-world Not a virtual world number.
in-vehicle The player is in a vehicle and withVehicle was not set.
vetoed virtualWorldChangeRequest kept the player where they are.
vehicle-changed With withVehicle: the player got out or into another vehicle while your gamemode decided.
player-not-found No such player, or they left meanwhile.

Twenty houses share one interior; each owner sees only their own.

gamemodes/my-mode.ts
import { commands, players } from "nativemp";
const houseWorld = (houseId: number) => 1000 + houseId;
commands.register("enterhouse", async (player, args) => {
const result = await players.setVirtualWorld(player, houseWorld(Number(args)));
if (result.status === "applied") await players.setPosition(player, [244, 305, 999.5], 0, 1);
});