-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworldlimiter.lua
More file actions
60 lines (50 loc) · 1.69 KB
/
worldlimiter.lua
File metadata and controls
60 lines (50 loc) · 1.69 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
-- worldlimiter.lua
-- Handles world border limitation.
local WorldLimiter_Flag = false -- True when teleportation is about to occur, false otherwise.
local WorldLimiter_LastMessage = -100 -- The last time the player was sent a message about reaching the border.
function OnPlayerMoving(Player)
if (WorldLimiter_Flag == true) then
return
end
local LimitChunks = WorldsWorldLimit[Player:GetWorld():GetName()]
-- The world probably was created by an external plugin. Let's load the settings.
if not LimitChunks then
LoadWorldSettings(Player:GetWorld())
LimitChunks = WorldsWorldLimit[Player:GetWorld():GetName()]
end
if (LimitChunks > 0) then
local World = Player:GetWorld()
local Limit = LimitChunks * 16 - 1
local SpawnX = math.floor(World:GetSpawnX())
local SpawnZ = math.floor(World:GetSpawnZ())
local X = math.floor(Player:GetPosX())
local Z = math.floor(Player:GetPosZ())
local NewX = X
local NewZ = Z
if (X > SpawnX + Limit) then
NewX = SpawnX + Limit
elseif (X < SpawnX - Limit) then
NewX = SpawnX - Limit
end
if (Z > SpawnZ + Limit) then
NewZ = SpawnZ + Limit
elseif (Z < SpawnZ - Limit) then
NewZ = SpawnZ - Limit
end
if (X ~= NewX) or (Z ~= NewZ) then
WorldLimiter_Flag = true
local UpTime = cRoot:Get():GetServerUpTime()
if UpTime - WorldLimiter_LastMessage > 30 then
WorldLimiter_LastMessage = UpTime
Player:SendMessageInfo(cChatColor.LightGray .. "You're at the world border.")
end
local UUID = Player:GetUUID()
World:ScheduleTask(3, function(World)
World:DoWithPlayerByUUID(UUID, function(Player)
Player:TeleportToCoords(NewX, Player:GetPosY(), NewZ)
WorldLimiter_Flag = false
end)
end)
end
end
end