chore: refractor
This commit is contained in:
79
ServerScriptService/CmdrCommands/ChunkCullWorld.lua
Normal file
79
ServerScriptService/CmdrCommands/ChunkCullWorld.lua
Normal file
@@ -0,0 +1,79 @@
|
||||
return {
|
||||
Name = "chunkcull",
|
||||
Aliases = {"cullchunks", "resetchunks"},
|
||||
Description = "Unload all server chunk cache instantly, then preload only chunks near players (and force clients to unload/resync).",
|
||||
Group = "Admin",
|
||||
Args = {
|
||||
{
|
||||
Type = "integer",
|
||||
Name = "radius",
|
||||
Description = "Horizontal chunk radius around each player to preload",
|
||||
Optional = true,
|
||||
Default = 5,
|
||||
},
|
||||
{
|
||||
Type = "integer",
|
||||
Name = "yRadius",
|
||||
Description = "Vertical chunk radius around each player to preload",
|
||||
Optional = true,
|
||||
Default = 1,
|
||||
},
|
||||
},
|
||||
Run = function(context, radius, yRadius)
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Players = game:GetService("Players")
|
||||
|
||||
local terrainGen = require(
|
||||
game:GetService("ServerScriptService")
|
||||
:WaitForChild("Actor")
|
||||
:WaitForChild("ServerChunkManager")
|
||||
:WaitForChild("TerrainGen")
|
||||
)
|
||||
|
||||
local tickRemote = ReplicatedStorage:WaitForChild("Tick")
|
||||
|
||||
local r = radius or 5
|
||||
local ry = yRadius or 1
|
||||
|
||||
local unloaded = 0
|
||||
pcall(function()
|
||||
unloaded = terrainGen:UnloadAllChunks()
|
||||
end)
|
||||
|
||||
-- Tell all clients to immediately drop their local chunk instances
|
||||
pcall(function()
|
||||
tickRemote:FireAllClients("U_ALL", 0, 0, 0, 0, 0, 0, 0)
|
||||
end)
|
||||
|
||||
-- Preload server chunks around players (reduces initial lag spikes after cull)
|
||||
local preloaded = 0
|
||||
pcall(function()
|
||||
preloaded = terrainGen:PreloadNearPlayers(r, ry)
|
||||
end)
|
||||
|
||||
-- Force clients to resync around themselves
|
||||
local resyncCount = 0
|
||||
for _, player in ipairs(Players:GetPlayers()) do
|
||||
local character = player.Character
|
||||
local root = character and character:FindFirstChild("HumanoidRootPart")
|
||||
if root then
|
||||
local pos = root.Position
|
||||
local cx = math.floor((pos.X + 16) / 32)
|
||||
local cy = math.floor((pos.Y + 16) / 32)
|
||||
local cz = math.floor((pos.Z + 16) / 32)
|
||||
for y = -ry, ry do
|
||||
for x = -r, r do
|
||||
for z = -r, r do
|
||||
tickRemote:FireClient(player, "C_R", cx + x, cy + y, cz + z, 0, 0, 0, 0)
|
||||
resyncCount += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return (
|
||||
"chunkcull done | unloaded=%d | preloaded=%d | resyncPackets=%d | radius=%d yRadius=%d"
|
||||
):format(unloaded, preloaded, resyncCount, r, ry)
|
||||
end,
|
||||
}
|
||||
23
ServerScriptService/CmdrCommands/ChunkDump.lua
Normal file
23
ServerScriptService/CmdrCommands/ChunkDump.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
return {
|
||||
Name = "chunkdump",
|
||||
Aliases = {"dumpchunk"},
|
||||
Description = "Show server-side block count for a chunk.",
|
||||
Group = "Debug",
|
||||
Args = {
|
||||
{
|
||||
Type = "integer",
|
||||
Name = "cx",
|
||||
Description = "Chunk X"
|
||||
},
|
||||
{
|
||||
Type = "integer",
|
||||
Name = "cy",
|
||||
Description = "Chunk Y"
|
||||
},
|
||||
{
|
||||
Type = "integer",
|
||||
Name = "cz",
|
||||
Description = "Chunk Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
15
ServerScriptService/CmdrCommands/ChunkDumpServer.lua
Normal file
15
ServerScriptService/CmdrCommands/ChunkDumpServer.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
return function(context, cx, cy, cz)
|
||||
local terrainGen = require(
|
||||
game:GetService("ServerScriptService")
|
||||
:WaitForChild("Actor")
|
||||
:WaitForChild("ServerChunkManager")
|
||||
:WaitForChild("TerrainGen")
|
||||
)
|
||||
|
||||
local chunk = terrainGen:GetChunk(cx, cy, cz)
|
||||
local count = 0
|
||||
for _ in pairs(chunk.data) do
|
||||
count += 1
|
||||
end
|
||||
return ("Chunk %d,%d,%d has %d blocks"):format(cx, cy, cz, count)
|
||||
end
|
||||
49
ServerScriptService/CmdrCommands/ResyncChunk.lua
Normal file
49
ServerScriptService/CmdrCommands/ResyncChunk.lua
Normal file
@@ -0,0 +1,49 @@
|
||||
return {
|
||||
Name = "resyncchunk",
|
||||
Aliases = {"resyncc"},
|
||||
Description = "Resync a chunk (and optional radius) for a player.",
|
||||
Group = "Debug",
|
||||
Args = {
|
||||
{
|
||||
Type = "player",
|
||||
Name = "player",
|
||||
Description = "Player to resync"
|
||||
},
|
||||
{
|
||||
Type = "integer",
|
||||
Name = "cx",
|
||||
Description = "Chunk X"
|
||||
},
|
||||
{
|
||||
Type = "integer",
|
||||
Name = "cy",
|
||||
Description = "Chunk Y"
|
||||
},
|
||||
{
|
||||
Type = "integer",
|
||||
Name = "cz",
|
||||
Description = "Chunk Z"
|
||||
},
|
||||
{
|
||||
Type = "integer",
|
||||
Name = "radius",
|
||||
Description = "Radius around the chunk",
|
||||
Optional = true,
|
||||
Default = 0
|
||||
}
|
||||
},
|
||||
Run = function(context, player, cx, cy, cz, radius)
|
||||
local tickRemote = game:GetService("ReplicatedStorage"):WaitForChild("Tick")
|
||||
local r = radius or 0
|
||||
local count = 0
|
||||
for y = -r, r do
|
||||
for x = -r, r do
|
||||
for z = -r, r do
|
||||
tickRemote:FireClient(player, "C_R", cx + x, cy + y, cz + z, 0, 0, 0, 0)
|
||||
count += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
return ("Resync sent to %s (%d chunks)"):format(player.Name, count)
|
||||
end
|
||||
}
|
||||
48
ServerScriptService/CmdrCommands/ResyncNear.lua
Normal file
48
ServerScriptService/CmdrCommands/ResyncNear.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
return {
|
||||
Name = "resyncnear",
|
||||
Aliases = {"resyncnearby"},
|
||||
Description = "Resync chunks around a player's current chunk.",
|
||||
Group = "Debug",
|
||||
Args = {
|
||||
{
|
||||
Type = "player",
|
||||
Name = "player",
|
||||
Description = "Player to resync"
|
||||
},
|
||||
{
|
||||
Type = "integer",
|
||||
Name = "radius",
|
||||
Description = "Radius around the player chunk",
|
||||
Optional = true,
|
||||
Default = 1
|
||||
}
|
||||
},
|
||||
Run = function(context, player, radius)
|
||||
local character = player.Character
|
||||
if not character then
|
||||
return "Player has no character"
|
||||
end
|
||||
local root = character:FindFirstChild("HumanoidRootPart")
|
||||
if not root then
|
||||
return "Player has no HumanoidRootPart"
|
||||
end
|
||||
|
||||
local pos = root.Position
|
||||
local cx = math.round(pos.X / 32)
|
||||
local cy = math.round(pos.Y / 32)
|
||||
local cz = math.round(pos.Z / 32)
|
||||
|
||||
local tickRemote = game:GetService("ReplicatedStorage"):WaitForChild("Tick")
|
||||
local r = radius or 1
|
||||
local count = 0
|
||||
for y = -r, r do
|
||||
for x = -r, r do
|
||||
for z = -r, r do
|
||||
tickRemote:FireClient(player, "C_R", cx + x, cy + y, cz + z, 0, 0, 0, 0)
|
||||
count += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
return ("Resync sent to %s (%d chunks around %d,%d,%d)"):format(player.Name, count, cx, cy, cz)
|
||||
end
|
||||
}
|
||||
Reference in New Issue
Block a user