Skip to content

Virtual worlds

Twenty houses can share one interior, a race can run through traffic nobody else sees, and a duel can happen in the middle of a busy street. A virtual world is a number, as in SA-MP and open.mp. Players in different virtual worlds are on the same map and do not exist for each other. Everyone starts in virtual world 0, and any number from 0 to 2,147,483,647 is a virtual world.

gamemodes/my-mode.ts
import { commands, players, vehicles } from "nativemp";
const raceWorld = 7;
commands.register("practice", async (player) => {
await players.setVirtualWorld(player, raceWorld);
await vehicles.create({ model: 411, position: [1756, -2496, 13.5], virtualWorld: raceWorld });
});
Thing Its virtual world
Players players.setVirtualWorld; 0 to start with.
Your vehicles virtualWorld on vehicles.create, or vehicles.setVirtualWorld.
Traffic, pedestrians, police The virtual world of the player whose game made them. Each virtual world has its own.
Objects, pickups, text labels, map icons, checkpoints, areas virtualWorld when you create them, 0 by default. virtualWorlds.every (-1) shows one in every virtual world.
Broken lamp posts, open gates, panicking bars, fires The virtual world they happened in.
Vending machines, gym machines, food carts and their vendors One in each virtual world. One of your interactive objects, or a hotdog van, is one thing, in its own virtual world.
The story’s parked vehicles, the map’s own pickups Virtual world 0 only.

Every PlayerSnapshot and Entity has a virtualWorld to read. It goes with interior: an interior in virtual world 7 shows to players in that interior in virtual world 7.

The clock, the weather and the world rules are the same in every virtual world, and so are the player list, name colors and skills. Chat goes to everyone by default: for a chat per virtual world, filter it in chat.onPlayerMessage by player.virtualWorld, and give chat.sendServerMessageNearby its virtualWorld. A player’s wanted level goes with them; the police chasing them stay behind, and new ones come in the new virtual world. Money, inventory and the rest are your gamemode’s.

A player in a vehicle moves only with their vehicle, and a vehicle takes what it tows. Pass withVehicle to players.setVirtualWorld, or use vehicles.setVirtualWorld: everyone in it goes.

The virtual world a player leaves is gone from their screen at once, and they from its players’. Whatever they were doing there ends: a seat they were getting into is refused, a parachute closes, a machine they used is let go. They go out of every checkpoint and area of the old virtual world at once, with the usual leave event, and into the new one’s, unless they are dead, busted or held. Their race checkpoint is their own and goes with them. A kill in the next seconds names no killer from the other virtual world.

virtualWorldChangeRequest asks you before every move and can send the player elsewhere. playerVirtualWorldChanged tells you it happened.

A player who joins is in virtual world 0. Move them in playerConnected or in playerSpawnRequest, before they show. A player who comes back within two minutes, with the same name and address, goes back to their virtual world: the reason is "reconnect", and your answer comes before they spawn. After that, your gamemode knows who they are and moves them itself.

A reload of your gamemode keeps every player’s and vehicle’s virtual world. Objects, pickups, text labels, map icons, checkpoints and areas go with your gamemode: make them again at the top of your gamemode.

The limits on world markers are the server’s, not each virtual world’s: 4,096 in all, 1,024 of them checkpoints and areas. Each virtual world costs what any other players there would: its own traffic, on its own players’ games.