diff options
author | bearbin <bearbin@gmail.com> | 2013-07-27 18:19:22 +0200 |
---|---|---|
committer | bearbin <bearbin@gmail.com> | 2013-07-27 18:19:22 +0200 |
commit | 1d0b57d8abf2297614659e1115b81d569612a402 (patch) | |
tree | df7d0acb85b3ef5c4783f721a83908ddc5130ef7 /MCServer/Plugins/Core/teleport.lua | |
parent | Merge pull request #7 from tigerw/master (diff) | |
parent | Merge pull request #8 from mc-server/master (diff) | |
download | cuberite-1d0b57d8abf2297614659e1115b81d569612a402.tar cuberite-1d0b57d8abf2297614659e1115b81d569612a402.tar.gz cuberite-1d0b57d8abf2297614659e1115b81d569612a402.tar.bz2 cuberite-1d0b57d8abf2297614659e1115b81d569612a402.tar.lz cuberite-1d0b57d8abf2297614659e1115b81d569612a402.tar.xz cuberite-1d0b57d8abf2297614659e1115b81d569612a402.tar.zst cuberite-1d0b57d8abf2297614659e1115b81d569612a402.zip |
Diffstat (limited to 'MCServer/Plugins/Core/teleport.lua')
-rw-r--r-- | MCServer/Plugins/Core/teleport.lua | 126 |
1 files changed, 80 insertions, 46 deletions
diff --git a/MCServer/Plugins/Core/teleport.lua b/MCServer/Plugins/Core/teleport.lua index ad9e7be69..89352408a 100644 --- a/MCServer/Plugins/Core/teleport.lua +++ b/MCServer/Plugins/Core/teleport.lua @@ -1,46 +1,80 @@ -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
- Player:SendMessage( cChatColor.Green .. "Usage: /tp [PlayerName] (-h)" )
- 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 .. "Already there :)");
- 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 = Player:GetWorld();
- if (not(World:DoWithPlayer(s_DstPlayerName, teleport))) then
- a_SrcPlayer:SendMessage(cChatColor.Green .. "Can't find player " .. a_DstPlayerName);
- end
-end
-
-
-
-
+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 + +function HandleTPACommand( Split, Player ) + if Split[2] == nil then + Player:SendMessage( cChatColor.Green .. "Usage: /tpa [Player]" ) + return true + end + local loopPlayer = function( OtherPlayer ) + if OtherPlayer:GetName() == Split[2] then + OtherPlayer:SendMessage( cChatColor.Green .. Player:GetName() .. " send a teleport request" ) + Player:SendMessage( cChatColor.Green .. "You send a teleport request to " .. OtherPlayer:GetName() ) + Destination[OtherPlayer:GetName()] = Player:GetName() + end + end + local loopWorlds = function( World ) + World:ForEachPlayer( loopPlayer ) + end + cRoot:Get():ForEachWorld( loopWorlds ) + return true +end + +function HandleTPAcceptCommand( Split, Player ) + if Destination[Player:GetName()] == nil then + Player:SendMessage( cChatColor.Green .. "Nobody has send you a teleport request" ) + return true + end + local loopPlayer = function( OtherPlayer ) + if Destination[Player:GetName()] == OtherPlayer:GetName() then + if OtherPlayer:GetWorld():GetName() ~= Player:GetWorld():GetName() then + OtherPlayer:MoveToWorld( Player:GetWorld():GetName() ) + end + OtherPlayer:TeleportToEntity( Player ) + Player:SendMessage( cChatColor.Green .. OtherPlayer:GetName() .. " teleported to you" ) + OtherPlayer:SendMessage( cChatColor.Green .. "You teleported to " .. Player:GetName() ) + Destination[Player:GetName()] = nil + end + end + local loopWorlds = function( World ) + World:ForEachPlayer( loopPlayer ) + end + cRoot:Get():ForEachWorld( loopWorlds ) + return true +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 |