-
Notifications
You must be signed in to change notification settings - Fork 42
/
regen.lua
79 lines (58 loc) · 1.89 KB
/
regen.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
-- regen.lua
-- Implements the in-game and console commands for chunk regeneration
function HandleRegenCommand(a_Split, a_Player)
-- Check the params:
local numParams = #a_Split
if (numParams == 2) or (numParams > 3) then
SendMessage(a_Player, "Usage: '" .. a_Split[1] .. "' or '" .. a_Split[1] .. " <chunk x> <chunk z>'" )
return true
end
-- Get the coords of the chunk to regen:
local chunkX = a_Player:GetChunkX()
local chunkZ = a_Player:GetChunkZ()
if (numParams == 3) then
chunkX = tonumber(a_Split[2])
chunkZ = tonumber(a_Split[3])
if (chunkX == nil) then
SendMessageFailure(a_Player, "Not a number: '" .. a_Split[2] .. "'")
return true
end
if (chunkZ == nil) then
SendMessageFailure(a_Player, "Not a number: '" .. a_Split[3] .. "'")
return true
end
end
-- Regenerate the chunk:
SendMessageSuccess(a_Player, "Regenerating chunk [" .. chunkX .. ", " .. chunkZ .. "]...")
a_Player:GetWorld():RegenerateChunk(chunkX, chunkZ)
return true
end
function HandleConsoleRegen(a_Split)
-- Check the params:
local numParams = #a_Split
if ((numParams ~= 3) and (numParams ~= 4)) then
return true, "Usage: " .. a_Split[1] .. " <chunk x> <chunk z> [world]"
end
-- Get the coords of the chunk to regen:
local chunkX = tonumber(a_Split[2])
if (chunkX == nil) then
return true, "Not a number: '" .. a_Split[2] .. "'"
end
local chunkZ = tonumber(a_Split[3])
if (chunkZ == nil) then
return true, "Not a number: '" .. a_Split[3] .. "'"
end
-- Get the world to regen:
local world
if (a_Split[4] == nil) then
world = cRoot:Get():GetDefaultWorld()
else
world = cRoot:Get():GetWorld(a_Split[4])
if (world == nil) then
return true, "There's no world named '" .. a_Split[4] .. "'."
end
end
-- Regenerate the chunk:
world:RegenerateChunk(chunkX, chunkZ)
return true, "Regenerating chunk [" .. chunkX .. ", " .. chunkZ .. "] in world " .. world:GetName()
end