Files
Fishing/tools/ground-decor.lua

66 lines
2.6 KiB
Lua

-- Опускает висящий в воздухе декор лобби на землю: для каждой модели декора лучи вниз из центра и углов
-- основания; модель ставится на самую высокую точку попадания под ней. Запуск в Edit (повторный безопасен:
-- то, что уже стоит, не двигается). DRY = true — только отчёт.
local DRY = false -- true — только отчёт
local map = workspace:FindFirstChild("FishingMap")
assert(map, "Нет FishingMap")
local V = Vector3.new
local FOLDERS = { "LobbyDecor", "LobbyMarketDecor", "LobbyFix3", "LobbyFix5", "LobbyFix6", "LobbyFix8", "BaitShops" }
local TOL, MAX_GAP = 0.08, 4 -- меньше — не трогаем; больше — это не «повис», а так задумано (на стене, на крыше)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.RespectCanCollide = true
local function groundUnder(obj)
local cf, size = obj:GetBoundingBox()
local bottom = cf.Position.Y - size.Y / 2
params.FilterDescendantsInstances = { obj, workspace:FindFirstChild("NpcNoWalk") }
local best
local hx, hz = size.X * 0.35, size.Z * 0.35
for _, o in ipairs({ V(0, 0, 0), V(hx, 0, hz), V(-hx, 0, hz), V(hx, 0, -hz), V(-hx, 0, -hz) }) do
local from = V(cf.Position.X + o.X, bottom + 1.5, cf.Position.Z + o.Z)
local hit = workspace:Raycast(from, V(0, -1.5 - MAX_GAP, 0), params)
if hit and (not best or hit.Position.Y > best) then
best = hit.Position.Y
end
end
return bottom, best
end
local moved, report = 0, {}
local function consider(obj)
if not (obj:IsA("Model") or obj:IsA("BasePart")) or obj:FindFirstChildOfClass("Humanoid") or obj:GetAttribute("Npc") then
return
end
local ok, bottom, ground = pcall(groundUnder, obj)
if not ok or not ground then
return
end
local gap = bottom - ground
if gap > TOL and gap < MAX_GAP then
table.insert(report, ("%s: %.2f"):format(obj:GetFullName():gsub("^Workspace%.FishingMap%.", ""), gap))
if not DRY then
if obj:IsA("Model") then
obj:PivotTo(obj:GetPivot() - V(0, gap, 0))
else
obj.CFrame = obj.CFrame - V(0, gap, 0)
end
end
moved += 1
end
end
for _, name in ipairs(FOLDERS) do
local f = map:FindFirstChild(name)
for _, c in ipairs(f and f:GetChildren() or {}) do
if c:IsA("Folder") then
for _, cc in ipairs(c:GetChildren()) do
consider(cc)
end
else
consider(c)
end
end
end
return ("%s %d:\n%s"):format(DRY and "висит (не двигал)" or "опущено", moved, table.concat(report, "\n"))