To achieve the functionality you described in a Minecraft plugin using the Skript language, you need to implement a way to track players' previous locations and handle the command to teleport them to those locations. Here's a script that you can use:
# This script requires Skript and a compatible version of Minecraft server.
# It saves the player's last location in the world "world" when they leave the world or disconnect.
# Creates a variable to store the player's last known location in the world "world"
variables:
{lastLocation::%player%} = location
# Tracks when a player changes worlds and saves their location if they are leaving "world"
on world change:
if world of event-player is "world":
set {lastLocation::%player%} to location of event-player
# Tracks when a player disconnects and saves their location if they are in "world"
on quit:
if world of event-player is "world":
set {lastLocation::%player%} to location of event-player
# Command to teleport the player back to their last location in "world"
command /overworld:
trigger:
if {lastLocation::%player%} is set:
teleport player to {lastLocation::%player%}
send "&aYou have been teleported to your last known location in the overworld."
else:
# If no stored location, teleport to the spawnpoint of the world "world"
if world "world" exists:
teleport player to spawn point of world "world"
send "&aYou have been teleported to the spawn point of the overworld."
else:
send "&cThe world 'world' does not exist or cannot be found."
Explanation:
-
Variables Storage: A variable {lastLocation::%player%} is used to store each player's last location in the world named "world". Variables are stored persistently, meaning they retain their values even when the server restarts.
-
World Change Event: When a player changes the world, the script checks if they are leaving "world". If so, it saves their location.
-
Player Quit Event: When a player disconnects, it saves their current location if they are in "world".
-
Command /overworld:
- If a player's last location in "world" is saved, they are teleported there.
- If no location is saved, they are teleported to the spawn point of "world".
- If the "world" does not exist, it sends an error message (this check is more a safety or debug measure).
Before using this script, ensure you have Skript installed on your server and any dependencies it requires. Save your script to a .sk file in your server's Skript scripts directory and reload Skript to apply changes.