leet.world
A script can teleport the player to coordinates, to the waypoint on the map, or to one of their saved points. Saved points are the user's list in the menu under World > Coordinates.
Teleports use the client's own safe teleport: it loads the destination area and puts the player on the ground, or on the water surface over water. If the player is in a vehicle, the vehicle is teleported together with the player.
Teleport results
All teleport functions take an optional callback. You may omit it or pass undefined.
- One teleport at a time. A new teleport (from a script, from the menu, or a friend's teleport) cancels the one in
progress, and the cancelled teleport's callback receives
"cancelled". - Called once, later. A teleport takes a moment, so the callback never fires during the
teleport...call itself. It fires exactly once, when the teleport finishes, with one string argument,result. - Errors are swallowed. An exception thrown by the callback has no effect.
- Reconnect. On reconnect, callbacks of teleports still in progress are dropped and never fire.
result | Meaning |
|---|---|
"done" | The player was teleported. |
"cancelled" | The teleport was replaced by another teleport or switched off, or the player or vehicle changed during it. |
"load_failed" | The destination area did not load in time. |
"no_waypoint" | teleportToWaypoint was called without a waypoint on the map. |
"not_in_game" | The player is not in the game (for example, loading or disconnected). |
leet.world.teleport
leet.world.teleport(x: number, y: number, z: number, callback?: (result: string) => void): undefinedTeleports the player (and their vehicle, if any) to the given coordinates. Returns nothing.
const RESULT_TEXT = {
load_failed: 'the area did not load in time',
cancelled: 'cancelled by another teleport',
not_in_game: 'you are not in the game',
};
leet.world.teleport(-75.0, -818.5, 326.2, (result) => {
if (result === 'done') {
leet.ui.notify('Welcome to the Maze Bank Tower roof', 'success');
} else {
leet.ui.notify(`Teleport failed: ${RESULT_TEXT[result] ?? result}`, 'error');
}
});Parameters
x(number): X coordinate. Finite, from -100000 to 100000.y(number): Y coordinate. Finite, from -100000 to 100000.z(number): height hint. Finite, from -100000 to 100000. The player lands on the ground or floor at (x,y), found from slightly abovez. With the rightzyou can land inside interiors or on bridges instead of on the terrain below them.callback(function, optional): receives the result.
| Error | When |
|---|---|
leet: invalid coordinates | x, y or z is not a number, is NaN / Infinity, or is outside -100000 to 100000. |
leet: callback must be a function | callback is given and is not a function. |
leet.world.teleportToWaypoint
leet.world.teleportToWaypoint(callback?: (result: string) => void): undefinedTeleports the player (and their vehicle, if any) to the waypoint set on the map. Without a waypoint, nothing happens and the
callback receives "no_waypoint". Returns nothing.
leet.world.teleportToWaypoint((result) => {
if (result === 'no_waypoint') leet.ui.notify('Set a waypoint on the map first', 'warning');
});Parameters
callback(function, optional): receives the result.
Errors: leet: callback must be a function (callback is given and is not a function).
For an F7 key binding, see the recipe Waypoint teleport on a key.
leet.world.points
leet.world.points(): Array<{ name: string, x: number, y: number, z: number }>Returns the user's saved points (World > Coordinates in the menu), in the same order as in the menu: an array of
{ name, x, y, z } objects, empty if there are no saved points. Never throws.
const points = leet.world.points();
if (points.length === 0) {
mp.console.logInfo('No saved points. Add some in World > Coordinates.');
} else {
points.forEach((p, i) => {
mp.console.logInfo(`${i + 1}. ${p.name} (${p.x.toFixed(1)}, ${p.y.toFixed(1)}, ${p.z.toFixed(1)})`);
});
}Keep in mind
- The array and its objects are a copy: changing them does not change the saved points.
leet.world.teleportToPoint
leet.world.teleportToPoint(name: string, callback?: (result: string) => void): undefinedTeleports the player (and their vehicle, if any) to a saved point. Returns nothing.
leet.world.teleportToPoint('Home', (result) => {
if (result !== 'done') leet.ui.notify(`Teleport failed: ${result}`, 'error');
});Parameters
name(string): the saved point's name, exactly as in the menu.callback(function, optional): receives the result.
Keep in mind
- The name must match exactly, case-sensitive. If several points share the name, the first one is used.
Errors: leet: unknown point (no saved point has this name, or name is not a string), leet: callback must be a function
(callback is given and is not a function).
Recipes
Route through several places
The script visits each point in turn, waits 5 seconds at each, and stops on the first result other than "done" or when the
user presses Stop.
const route = [
{ name: 'Legion Square', x: 195.2, y: -933.8, z: 30.7 },
{ name: 'LS Airport', x: -1037.0, y: -2737.7, z: 20.2 },
{ name: 'Sandy Shores', x: 1961.5, y: 3740.4, z: 32.3 },
{ name: 'Paleto Bay', x: -275.5, y: 6233.0, z: 31.5 },
];
let stopped = false;
let pause = null;
function visit(i) {
if (stopped) return;
if (i >= route.length) {
leet.ui.notify('Route finished', 'success');
return;
}
const p = route[i];
leet.world.teleport(p.x, p.y, p.z, (result) => {
if (stopped) return;
if (result !== 'done') {
leet.ui.notify(`Route stopped at ${p.name}: ${result}`, 'error');
return;
}
mp.console.logInfo(`[route] ${i + 1}/${route.length} ${p.name}`);
pause = setTimeout(() => visit(i + 1), 5000);
});
}
visit(0);
leet.events.onUnload(() => {
stopped = true;
clearTimeout(pause);
});Each teleport starts only from the previous one's callback, so they never cancel each other. The stopped flag is there
because a callback can still arrive after Stop.
Waypoint teleport on a key
const KEY_F7 = 0x76;
const onKey = () => {
if (mp.gui.cursor.visible) return; // chat or a menu is open
leet.world.teleportToWaypoint((result) => {
if (result === 'done') leet.ui.notify('Teleported to the waypoint', 'success');
else if (result === 'no_waypoint') leet.ui.notify('Set a waypoint on the map first', 'warning');
else leet.ui.notify(`Teleport failed: ${result}`, 'error');
});
};
mp.keys.bind(KEY_F7, true, onKey);
leet.events.onUnload(() => {
mp.keys.unbind(KEY_F7, true, onKey);
});The cursor check keeps the key from teleporting while the player types in chat. The key is unbound in onUnload.
Go home, with a fallback
Teleports to the saved point Home. If there is no such point, it falls back to the first saved point, and if there are none
at all, it tells the user what to do.
const onResult = (result) => {
if (result === 'done') leet.ui.notify('Teleported', 'success');
else leet.ui.notify(`Teleport failed: ${result}`, 'error');
};
try {
leet.world.teleportToPoint('Home', onResult);
} catch (e) {
if (e.message !== 'leet: unknown point') throw e;
const [first] = leet.world.points();
if (first) {
leet.ui.notify(`No "Home" point, going to "${first.name}"`, 'warning');
leet.world.teleportToPoint(first.name, onResult);
} else {
leet.ui.notify('Save a point named "Home" in World > Coordinates', 'warning');
}
}A missing point throws right away, so the fallback is caught with try instead of in the callback.