summaryrefslogtreecommitdiffstats
path: root/Core/teleport.lua
diff options
context:
space:
mode:
authorAlexander Harkness <bearbin@gmail.com>2013-07-27 17:16:04 +0200
committerAlexander Harkness <bearbin@gmail.com>2013-07-27 17:16:04 +0200
commit0623a4f9be1c21651ea212f7b4d86136a67ddffe (patch)
tree5a96f13f72fa394bf74d10839a76ec7a1eac9275 /Core/teleport.lua
parentRemoved all the pre-exising core files. (diff)
downloadcuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.tar
cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.tar.gz
cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.tar.bz2
cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.tar.lz
cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.tar.xz
cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.tar.zst
cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.zip
Diffstat (limited to 'Core/teleport.lua')
-rw-r--r--Core/teleport.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/Core/teleport.lua b/Core/teleport.lua
new file mode 100644
index 000000000..4d3d98fee
--- /dev/null
+++ b/Core/teleport.lua
@@ -0,0 +1,38 @@
+function HandleTPCommand(a_Split, a_Player)
+ if ((#a_Split == 2) or (#a_Split == 3)) then
+ -- Teleport to player specified in a_Split[2], tell them unless a_Split[3] equals "-h":
+ TeleportToPlayer(a_Player, a_Split[2], (a_Split[3] ~= "-h"));
+ return true;
+ elseif (#a_Split == 4) then
+ -- Teleport to XYZ coords specified in a_Split[2, 3, 4]:
+ SetBackCoordinates(a_Player);
+ a_Player:TeleportToCoords(a_Split[2], a_Split[3], a_Split[4]);
+ a_Player:SendMessage(cChatColor.Green .. "You teleported to {" .. a_Split[2] .. ", " .. a_Split[3] .. ", " .. a_Split[4] .. "}");
+ return true;
+ else
+ a_Player:SendMessage( cChatColor.Green .. "Usage: /tp [PlayerName] (-h) or /tp [X Y Z]" )
+ return true
+ end
+end
+
+-- Teleports a_SrcPlayer to a player named a_DstPlayerName; if a_TellDst is true, will send a notice to the destination player
+function TeleportToPlayer(a_SrcPlayer, a_DstPlayerName, a_TellDst)
+ local teleport = function(OtherPlayer)
+ if (OtherPlayer == a_SrcPlayer) then
+ -- Asked to teleport to self?
+ a_SrcPlayer:SendMessage(cChatColor.Green .. "Y' can't teleport to yerself!");
+ else
+ SetBackCoordinates(a_SrcPlayer);
+ a_SrcPlayer:TeleportToEntity(OtherPlayer);
+ a_SrcPlayer:SendMessage(cChatColor.Green .. "You teleported to " .. OtherPlayer:GetName() .. "!");
+ if (a_TellDst) then
+ OtherPlayer:SendMessage(cChatColor.Green .. Player:GetName().." teleported to you!");
+ end
+ end
+ end
+
+ local World = a_SrcPlayer:GetWorld();
+ if (not(World:DoWithPlayer(a_DstPlayerName, teleport))) then
+ a_SrcPlayer:SendMessage(cChatColor.Green .. "Can't find player " .. a_DstPlayerName);
+ end
+end \ No newline at end of file