-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathteleport.lua
130 lines (125 loc) · 5.38 KB
/
teleport.lua
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
function HandlePlaceCommand(Split, Player)
local Teleport = function(OtherPlayer)
local LookPos = GetPlayerLookPos(Player)
if LookPos == nil then
Player:SendMessageFailure("You're not looking at a block, or it's too far away")
else
--Teleport the player
OtherPlayer:TeleportToCoords(LookPos.x, LookPos.y + 1, LookPos.z)
Player:SendMessageSuccess("Successfully teleported player \"" .. OtherPlayer:GetName() .. "\" where you are looking")
end
end
if Split[2] == nil then
Player:SendMessageInfo("Usage: " .. Split[1] .. " <player>")
else
if Split[2] == "" or not cRoot:Get():FindAndDoWithPlayer(Split[2], Teleport) then
Player:SendMessageFailure("Player \"" .. Split[2] .. "\" not found")
end
end
return true
end
function HandleTPHereCommand(Split, Player)
local Teleport = function(OtherPlayer)
local OrigWorld = OtherPlayer:GetWorld():GetName()
local DestWorld = Player:GetWorld():GetName()
if OrigWorld ~= DestWorld then
OtherPlayer:MoveToWorld(DestWorld)
end
OtherPlayer:TeleportToEntity(Player)
Player:SendMessageSuccess("Player \"" .. OtherPlayer:GetName() .. "\" teleported to you")
OtherPlayer:SendMessageSuccess("You teleported to player \"" .. Player:GetName() .. "\"")
end
if Split[2] == nil then
Player:SendMessageInfo("Usage: " .. Split[1] .. " <player>")
else
if Split[2] == "" or not cRoot:Get():FindAndDoWithPlayer(Split[2], Teleport) then
Player:SendMessageFailure("Player \"" .. Split[2] .. "\" not found")
end
end
return true
end
function HandleTPACommand(Split, Player)
local Teleport = function(OtherPlayer)
if Split[1] == "/tpa" then
OtherPlayer:SendMessageInfo("Player \"" .. Player:GetName() .. cChatColor.Plain .. "\" has requested to teleport to you")
else
OtherPlayer:SendMessageInfo("Player \"" .. Player:GetName() .. cChatColor.Plain .. "\" has requested you to teleport to them")
end
if TpRequestTimeLimit > 0 then
OtherPlayer:SendMessageInfo("This request will timeout after " .. TpRequestTimeLimit .. " seconds")
end
OtherPlayer:SendMessageInfo("To teleport, type " .. cChatColor.LightGreen .. "/tpaccept")
OtherPlayer:SendMessageInfo("To deny this request, type " .. cChatColor.Rose .. "/tpdeny")
TeleportRequests[OtherPlayer:GetUUID()] = {Type = Split[1], Requester = Player:GetName(), Time = GetTime()}
Player:SendMessageSuccess("Successfully sent teleportation request to player \"" .. OtherPlayer:GetName() .. "\"")
end
if Split[2] == nil then
Player:SendMessageInfo("Usage: " .. Split[1] .. " <player>" )
else
if Split[2] == "" or not cRoot:Get():FindAndDoWithPlayer(Split[2], Teleport) then
Player:SendMessageFailure("Player \"" .. Split[2] .. "\" not found")
end
end
return true
end
function HandleTPAcceptDenyCommand(Split, Player)
local Teleport = function(OtherPlayer)
if Split[1] == "/tpaccept" then
if OtherPlayer:GetWorld():GetName() ~= Player:GetWorld():GetName() then
if TeleportRequests[Player:GetUUID()].Type == "/tpa" then
OtherPlayer:MoveToWorld(Player:GetWorld():GetName())
elseif TeleportRequests[Player:GetUUID()].Type == "/tpahere" then
Player:MoveToWorld(OtherPlayer:GetWorld():GetName())
end
end
if TeleportRequests[Player:GetUUID()].Type == "/tpa" then
OtherPlayer:TeleportToEntity(Player)
Player:SendMessageSuccess("Player \"" .. OtherPlayer:GetName() .. "\" teleported to you")
OtherPlayer:SendMessageSuccess("You teleported to player \"" .. Player:GetName() .. "\"")
elseif TeleportRequests[Player:GetUUID()].Type == "/tpahere" then
Player:TeleportToEntity(OtherPlayer)
OtherPlayer:SendMessageSuccess("Player \"" .. Player:GetName() .. "\" teleported to you.")
Player:SendMessageSuccess("You teleported to player \"" .. OtherPlayer:GetName() .. "\"")
end
elseif Split[1] == "/tpdeny" then
OtherPlayer:SendMessageFailure("Player \"" .. Player:GetName() .. "\" has denied your teleportation request")
Player:SendMessageSuccess("Successfully denied teleportation request")
end
TeleportRequests[Player:GetUUID()] = nil
end
if TeleportRequests[Player:GetUUID()] == nil then
Player:SendMessageFailure("Nobody has sent you a teleportation request")
elseif TpRequestTimeLimit > 0 and TeleportRequests[Player:GetUUID()].Time + TpRequestTimeLimit < GetTime() then
TeleportRequests[Player:GetUUID()] = nil
Player:SendMessageFailure("Teleportation request timed out")
else
if not cRoot:Get():FindAndDoWithPlayer(TeleportRequests[Player:GetUUID()].Requester, Teleport) then
Player:SendMessageFailure("Player is no longer online")
end
end
return true
end
function HandleBackCommand(Split, Player)
local BackCoords = BackCoords[Player:GetName()]
if BackCoords == nil then
Player:SendMessageFailure("No known last position")
else
local CurWorld = Player:GetWorld()
local OldWorld = BackWorld[Player:GetName()]
if CurWorld ~= OldWorld then
Player:MoveToWorld(OldWorld, true, Vector3d(BackCoords.x, BackCoords.y, BackCoords.z))
else
Player:TeleportToCoords(BackCoords.x, BackCoords.y, BackCoords.z)
end
Player:SendMessageSuccess("Successfully teleported back to your last known position")
end
return true
end
function HandleTopCommand(Split, Player)
local World = Player:GetWorld()
local Pos = Player:GetPosition()
local Height = World:GetHeight(math.floor(Pos.x), math.floor(Pos.z))
Player:TeleportToCoords(Pos.x, Height+1, Pos.z)
Player:SendMessageSuccess("Successfully teleported to the topmost block")
return true
end