forked from cuberite/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteleport.lua
More file actions
93 lines (73 loc) · 2.51 KB
/
teleport.lua
File metadata and controls
93 lines (73 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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)
-- For relative coordinates
local Function;
local X = a_Split[2];
Function = loadstring(a_Split[2]:gsub("~", "return " .. a_Player:GetPosX() .. "+0"));
if Function then
X = Function();
end
local Y = a_Split[3];
Function = loadstring(a_Split[3]:gsub("~", "return " .. a_Player:GetPosY() .. "+0"));
if Function then
Y = Function();
end
local Z = a_Split[4];
Function = loadstring(a_Split[4]:gsub("~", "return " .. a_Player:GetPosZ() .. "+0"));
if Function then
Z = Function();
end
a_Player:TeleportToCoords( X, Y, Z )
SendMessageSuccess( a_Player, "You teleported to [X:" .. X .. " Y:" .. Y .. " Z:" .. Z .. "]" )
return true
else
SendMessage( a_Player, "Usage: /tp [PlayerName] (-h) or /tp [X Y Z]" )
return true
end
end
function HandleTPACommand( Split, Player )
if Split[2] == nil then
SendMessage( Player, "Usage: /tpa [Player]" )
return true
end
local loopPlayer = function( OtherPlayer )
if OtherPlayer:GetName() == Split[2] then
SendMessage( OtherPlayer, Player:GetName() .. " send a teleport request" )
SendMessageSuccess( Player, "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
SendMessageFailure( Player, "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 )
SendMessage( Player, OtherPlayer:GetName() .. " teleported to you" )
SendMessageSuccess( OtherPlayer, "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