The online racing simulator
Teleport Menu
Hello everyone!
We present to you a fully working, simple, and easy-to-understand teleportation menu for players.

đź”§ Features:
After leaving the garage, type the command !teleport to open the teleportation window.

In the window, you'll see a list of available locations to choose from.

When a player clicks on a location name:

They will be instantly teleported to that location.

The teleport menu will automatically close.

Created by: Bass_Driver


CatchEvent OnLapperStart()
GlobalVar $SpawnLocation;

# X , Y , Z, Flag(do not change), Heading of vehicle
$SpawnLocation[1] = "286.25,-984.5,11.89,128,55";
$SpawnLocation[2] = "126.56,-1087.62,14.62,128,-101";
$SpawnLocation[3] = "283.81,-988.25,11.92,128,55";
$SpawnLocation[4] = "190.56,-80.74,7.64,128,20";
$SpawnLocation[5] = "-284.5,-295.81,21.77,128,-101";

EndCatchEvent


CatchEvent OnMSO( $userName, $text ) # Player event

$idxOfFirtsSpace = indexOf( $text, " ");

IF( $idxOfFirtsSpace == -1 ) THEN
$command = $text;
$argv = "";
ELSE
$command = subStr( $text,0,$idxOfFirtsSpace );
$argv = trim( subStr( $text,$idxOfFirtsSpace ) );
ENDIF

SWITCH( $command )
CASE "!teleport":
OpenTeleportWindow($userName);
BREAK;

ENDSWITCH
EndCatchEvent

Sub OpenTeleportWindow($userName)

#Background
OpenPrivButton("Teleportwindow_bgd",70,65,60,32,5,-1,32, "");

#Buttons of locations.

OpenPrivButton("Teleportwindow_Loc_1",71,66,58,6,5,-1,16, "^0Location 1",TeleportPlayer);
OpenPrivButton("Teleportwindow_Loc_2",71,72,58,6,5,-1,16, "^0Location 2",TeleportPlayer);
OpenPrivButton("Teleportwindow_Loc_3",71,78,58,6,5,-1,16, "^0Location 3",TeleportPlayer);
OpenPrivButton("Teleportwindow_Loc_4",71,84,58,6,5,-1,16, "^0Location 4",TeleportPlayer);
OpenPrivButton("Teleportwindow_Loc_5",71,90,58,6,5,-1,16, "^0Location 5",TeleportPlayer);

EndSub

Sub TeleportPlayer($keyflags,$id)

$userName = Getcurrentplayervar("UserName");

#trim the first 19 characters of the buttonID ("Teleportwindow_Loc_")
$SelectedLocation = trim( subStr( $id,19 ));
$SplittedValues = SplitToArray($SpawnLocation[ToNum($SelectedLocation)],",");

#Give values of the array a readable name.
$X = $SplittedValues[0];
$Y = $SplittedValues[1];
$Z = $SplittedValues[2];
$Flag = $SplittedValues[3];
$Heading = $SplittedValues[4];

#JRR Spawn request.
joinrequest(ToNum($X),ToNum($Y),ToNum($Z),ToNum($Flag),ToNum($Heading),GetPlayerVar($userName,"UCID"),GetPlayerVar($userName,"PLID"),4); #Spawn Player to the selected location with vehiclereset

# Close window after teleport
closePrivButton("Teleportwindow_bgd&Teleportwindow_Loc_1&Teleportwindow_Loc_2&Teleportwindow_Loc_3&Teleportwindow_Loc_4&Teleportwindow_Loc_5");
EndSub

Attached images
Untitled.jpg
Hello developers,

I have a problem (because I’m a bad programmer Big grin). I’m using a !teleport function on my server, but it’s not working correctly.

The main issue is this: all players get teleported to the exact same coordinate at the same time. They appear there simultaneously, and as soon as they start moving, they all “fly off” in different directions.

I believe there must be a coding solution that would teleport players next to each other instead — kind of like when you join a track and everyone is placed into different pit boxes in order.

Can someone help me with this? I haven’t been able to solve it myself, and I’d really appreciate your assistance.



Thanks in advance!
They all going to the exact same location is because the same location is used. A solution could be to add a globalvar $pos_offset and set it to 0.
Then after every teleport, add to that globalvar, while adding the global it self to the X or Y variable.
Thanks you for fast answer Smile If I created coordinates for one track, everything works fine on that track. But the problem is that when I change the track, the teleport function still uses the coordinates from the first track. Is it possible to make the teleport function work differently for each track?"
Sure put the coordinates in an array, as well as the track names.
Then read the current loaded track, find the number in de track array and load the coordinates using the same number from the coordinates array.
Quote from Yisc[NL :;2127126"]They all going to the exact same location is because the same location is used...

I just can’t figure out the coordinate issue. I’m not a programmer, I’m doing everything with your and ChatGPT’s help, but I can’t understand how the offset function works. The problem is that my solutions don’t work correctly (the cars sometimes appear side by side, sometimes they overlap). I want to ask the community if you could insert this into the code posted in this thread?

I want the cars to teleport along the Y-axis every 2-3 meters apart from each other, and after 5 teleports, to start again from the initial point. I would be very grateful to anyone who could help solve this code.
An offset with each successive teleport may or may not work, as it all depends on whether a car has moved after teleporting: if you allow 5 offset locations, 5 people teleport but don't move, you have the same issue for the 6th teleport (but less likely, of course); a better solution for this would be to check whether a vehicle is within a safe distance of the teleport target, and prevent teleport until the area is clear, which should be doable with an InSim circle and the IS_UCO packet.
(but of course, if you expect multiple people to teleport to the same location in a short time, you may still need multiple target locations close to one another)

Also, instead of storing locations in code, you should consider reading a text file containing those locations instead, so you don't have to modify the code every time you want to add, remove, or change a target.

As for AI coding, do keep in mind that you should not just trust the code AI gives you: you should be able to understand it, so you can find issues that will inevitably arise (code not actually following your prompt, or using the wanted API in a wrong way or based on outdated "knowledge"); therefore you should probably learn the Lapper API, or at least the features the code uses.

But to try and answer your question: create an array of variables tracking the current count of teleports to each location, increment the variable each time a vehicle is teleported to the corresponding target, and reset when it goes over 5; then use that variable for the teleport itself, and add the offset multiplied by the 2-3 meters you want to the coordinate you want to offset. You may also want to use the teleport target's heading to automatically offset both X and Y with cos/sin, so that cars spawn next to each other.
Here is the code with 8 offsets. Maybe someone will find it useful.
Now the cars don’t spawn on top of each other but teleport next to each other.



CatchEvent OnLapperStart()
GlobalVar $SpawnLocation;
GlobalVar $TeleportCounter;

# X , Y , Z, Flag (do not change), Heading of vehicle
$SpawnLocation[1] = "390.24,-463.08,11.89,128,140";
$SpawnLocation[2] = "-240.15,-46.25,14.62,128,180";
$SpawnLocation[3] = "-110.43,202.46,11.92,128,-90";
$SpawnLocation[4] = "-914.38,322.13,7.64,128,90";
$SpawnLocation[5] = "-712.62,392.18,21.77,128,180";

# Initialize teleport counters
$TeleportCounter[1] = 0;
$TeleportCounter[2] = 0;
$TeleportCounter[3] = 0;
$TeleportCounter[4] = 0;
$TeleportCounter[5] = 0;
EndCatchEvent


CatchEvent OnMSO( $userName, $text )

$idxOfFirtsSpace = indexOf( $text, " ");

IF( $idxOfFirtsSpace == -1 ) THEN
$command = $text;
$argv = "";
ELSE
$command = subStr( $text,0,$idxOfFirtsSpace );
$argv = trim( subStr( $text,$idxOfFirtsSpace ) );
ENDIF

SWITCH( $command )
CASE "!teleport":
OpenTeleportWindow($userName);
BREAK;
ENDSWITCH
EndCatchEvent


Sub OpenTeleportWindow($userName)

# Background window
OpenPrivButton("Teleportwindow_bgd",70,65,60,32,5,-1,32, "");

# Location buttons
OpenPrivButton("Teleportwindow_Loc_1",71,66,58,6,5,-1,16, "^0TwinDrift Zone",TeleportPlayer);
OpenPrivButton("Teleportwindow_Loc_2",71,72,58,6,5,-1,16, "^0Training Park",TeleportPlayer);
OpenPrivButton("Teleportwindow_Loc_3",71,78,58,6,5,-1,16, "^0Small LYT",TeleportPlayer);
OpenPrivButton("Teleportwindow_Loc_4",71,84,58,6,5,-1,16, "^0Big LYT",TeleportPlayer);
OpenPrivButton("Teleportwindow_Loc_5",71,90,58,6,5,-1,16, "^0Garages Zone",TeleportPlayer);

EndSub


Sub TeleportPlayer($keyflags,$id)

$userName = GetCurrentPlayerVar("UserName");

# Extract location index from button ID
$SelectedLocation = trim( subStr( $id,19 ));
$locIndex = ToNum($SelectedLocation);
$SplittedValues = SplitToArray($SpawnLocation[$locIndex],",");

# Base coordinates
$X = ToNum($SplittedValues[0]);
$Y = ToNum($SplittedValues[1]);
$Z = ToNum($SplittedValues[2]);
$Flag = ToNum($SplittedValues[3]);
$Heading = ToNum($SplittedValues[4]);

# Y axis offset
$offsetCount = $TeleportCounter[$locIndex];
$offsetMeters = 4;

# Apply offset only on Y axis
$Y = $Y + ($offsetCount * $offsetMeters);

# Teleport the player
joinrequest($X,$Y,$Z,$Flag,$Heading,GetPlayerVar($userName,"UCID"),GetPlayerVar($userName,"PLID"),4);

# Update counter (0–7)
$TeleportCounter[$locIndex] = $offsetCount + 1;
IF($TeleportCounter[$locIndex] > 7) THEN
$TeleportCounter[$locIndex] = 0;
ENDIF

# Close teleport window
closePrivButton("Teleportwindow_bgd&Teleportwindow_Loc_1&Teleportwindow_Loc_2&Teleportwindow_Loc_3&Teleportwindow_Loc_4&Teleportwindow_Loc_5");

EndSub



FGED GREDG RDFGDR GSFDG