-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.lua
More file actions
305 lines (255 loc) · 10.4 KB
/
Copy pathapi.lua
File metadata and controls
305 lines (255 loc) · 10.4 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
-- ============================================================
-- CONFIGURATION (edit these values before running)
-- ============================================================
local ASSET_ID = 0 -- Replace with your rbxassetid number
local API_CALL_DELAY = 0.01 -- Seconds between SyncAPI calls (tune to avoid kick)
local DRY_RUN = false -- If true, counts parts and prints a preview without building
local PLACEMENT_OFFSET = CFrame.new(0, 0, 0) -- World-space offset for the entire build
-- ============================================================
local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local LocalPlayer = Players.LocalPlayer
-- Safety: wait for character
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local BuildingTools = character:WaitForChild("Building Tools", 5)
if not BuildingTools then return end
local SyncAPI = BuildingTools:WaitForChild("SyncAPI", 5)
if not SyncAPI then return end
local ServerEndpoint = SyncAPI:WaitForChild("ServerEndpoint", 5)
if not ServerEndpoint then return end
-- Tracks every created part so undoBuild() can remove them all
local createdParts = {}
-- ============================================================
-- RATE-LIMITED INVOKE
-- Wraps all SyncAPI calls with a configurable delay and pcall
-- ============================================================
local function invoke(method: string, ...): any
task.wait(API_CALL_DELAY)
local ok, result = pcall(ServerEndpoint.InvokeServer, ServerEndpoint, method, ...)
return ok and result or nil
end
-- ============================================================
-- CORE BUILDING FUNCTIONS
-- ============================================================
local function createPart(partType: string, cf: CFrame): BasePart?
local part = invoke("CreatePart", partType, cf, workspace)
if not part then return nil end
local t = 0
while not workspace:FindFirstChild(part.Name) and t < 5 do
t += task.wait(0.05)
end
table.insert(createdParts, part)
return part
end
local function determinePartType(part: BasePart): string
if part:IsA("TrussPart") then return "Truss" end
if part:IsA("WedgePart") then return "Wedge" end
if part:IsA("CornerWedgePart") then return "Corner" end
if part:IsA("Seat") then return "Seat" end
if part:IsA("VehicleSeat") then return "VehicleSeat" end
if part:IsA("SpawnLocation") then return "Spawn" end
return "Normal"
end
local function copyTextures(newPart: BasePart, sourcePart: BasePart)
for _, child in sourcePart:GetChildren() do
if child:IsA("Texture") or child:IsA("Decal") then
invoke("CreateTextures", {{ Part = newPart, Face = child.Face, TextureType = child.ClassName }})
end
end
end
local function copyLights(newPart: BasePart, sourcePart: BasePart)
for _, child in sourcePart:GetChildren() do
local lightType = child:IsA("PointLight") and "PointLight" or
child:IsA("SpotLight") and "SpotLight" or
child:IsA("SurfaceLight") and "SurfaceLight"
if lightType then
invoke("CreateLights", {{ Part = newPart, LightType = lightType }})
end
end
end
-- ============================================================
-- MAIN BUILD FUNCTION (called per BasePart)
-- ============================================================
local function buildPart(sourcePart: BasePart, targetCF: CFrame)
if not sourcePart:IsA("BasePart") then return end
local newPart = createPart(determinePartType(sourcePart), targetCF)
if not newPart then return end
invoke("SyncColor", {{ Part = newPart, UnionColoring = true, Color = sourcePart.Color }})
invoke("SyncResize", {{ Part = newPart, CFrame = targetCF, Size = sourcePart.Size }})
invoke("SyncMaterial", {{
Part = newPart,
Material = sourcePart.Material,
Transparency = sourcePart.Transparency,
Reflectance = sourcePart.Reflectance
}})
invoke("SyncCollision", {{ Part = newPart, CanCollide = sourcePart.CanCollide }})
if sourcePart.Anchored then
invoke("SyncAnchor", {{ Part = newPart, Anchored = true }})
end
if sourcePart:IsA("MeshPart") and sourcePart.MeshId ~= "" then
invoke("CreateMeshes", {{ Part = newPart }})
invoke("SyncMesh", {{
Part = newPart,
MeshType = Enum.MeshType.FileMesh,
MeshId = sourcePart.MeshId,
TextureId = sourcePart.TextureID or ""
}})
end
local specialMesh = sourcePart:FindFirstChildOfClass("SpecialMesh")
if specialMesh then
invoke("CreateMeshes", {{ Part = newPart }})
invoke("SyncMesh", {{
Part = newPart,
MeshType = specialMesh.MeshType,
MeshId = specialMesh.MeshId,
TextureId = specialMesh.TextureId,
Scale = specialMesh.Scale,
Offset = specialMesh.Offset
}})
end
copyTextures(newPart, sourcePart)
copyLights(newPart, sourcePart)
end
-- ============================================================
-- UNDO — removes every part created during this session
-- ============================================================
_G.undoBuild = function()
for _, part in createdParts do
if part and part.Parent then invoke("DeleteParts", {{ Part = part }}) end
end
table.clear(createdParts)
end
-- ============================================================
-- LOAD & BUILD
-- ============================================================
if ASSET_ID == 0 then return end
local ok, objects = pcall(game.GetObjects, game, "rbxassetid://" .. ASSET_ID)
if not ok or type(objects) ~= "table" or not objects[1] then return end
local model = objects[1]
model.Parent = workspace
local parts = {}
for _, descendant in model:GetDescendants() do
if descendant:IsA("BasePart") then table.insert(parts, descendant) end
end
local totalParts = #parts
if DRY_RUN then
model:Destroy()
return
end
local modelOriginCF = CFrame.identity
if model:IsA("Model") then
local cf = model:GetBoundingBox()
modelOriginCF = cf
elseif #parts > 0 then
modelOriginCF = parts[1].CFrame
end
-- Assemble the Ghost Hologram
local ghostModel = model:Clone()
for _, desc in ghostModel:GetDescendants() do
if desc:IsA("BasePart") then
desc.CanCollide = false
desc.Anchored = true
desc.CastShadow = false
desc.Transparency = 0.6
desc.Material = Enum.Material.SmoothPlastic
desc.Color = Color3.new(0, 1, 1)
elseif desc:IsA("Script") or desc:IsA("LocalScript") then
desc:Destroy()
end
end
ghostModel.Parent = workspace
local isLocked = false
local currentCF = modelOriginCF
local camera = workspace.CurrentCamera
local lastGhostPos = Vector3.zero
-- Zero-lag placement logic
local function updateGhost()
if isLocked then return end
local ray = camera:ViewportPointToRay(camera.ViewportSize.X / 2, camera.ViewportSize.Y / 2)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {LocalPlayer.Character, ghostModel}
local result = workspace:Raycast(ray.Origin, ray.Direction * 300, params)
local pos = result and result.Position or (ray.Origin + ray.Direction * 40)
-- Optimize rendering: only pivot if magnitude delta > 0.2 studs
if (lastGhostPos - pos).Magnitude < 0.2 then return end
lastGhostPos = pos
currentCF = CFrame.new(pos)
ghostModel:PivotTo(currentCF)
end
RunService:BindToRenderStep("BuilderGhost", Enum.RenderPriority.Camera.Value + 1, updateGhost)
local tapCount = 0
local tapStartTime = 0
local inputConnection
local function startBuildProcess()
local finalCF = currentCF
ghostModel:Destroy()
StarterGui:SetCore("SendNotification", {
Title = "Building started...",
Text = string.format("Placing %d parts.", totalParts),
Duration = 3
})
task.spawn(function()
local built = 0
local failed = 0
for i, sourcePart in ipairs(parts) do
local relativeCF = modelOriginCF:ToObjectSpace(sourcePart.CFrame)
-- Anchor onto our screen-raycasted target location + optional offsets
local targetCF = (finalCF * PLACEMENT_OFFSET) * relativeCF
local success = pcall(buildPart, sourcePart, targetCF)
if success then
built += 1
else
failed += 1
end
if i % 15 == 0 or i == totalParts then
StarterGui:SetCore("SendNotification", {
Title = "Building...",
Text = string.format("Part %d of %d", i, totalParts),
Duration = 2
})
end
end
model:Destroy()
StarterGui:SetCore("SendNotification", {
Title = "Build complete!",
Text = string.format("Built %d / %d parts. Failed: %d", built, totalParts, failed),
Icon = "rbxthumb://type=AvatarHeadShot&id=" .. LocalPlayer.UserId .. "&w=180&h=180",
Duration = 7
})
end)
end
-- Custom tap recognition engine
inputConnection = UserInputService.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then
local now = tick()
-- Prevent infinite accumulation by limiting maximum tap time window
if tapCount == 0 or (now - tapStartTime) > 0.67 then
tapCount = 1
tapStartTime = now
else
tapCount += 1
end
if tapCount == 2 then
isLocked = not isLocked
StarterGui:SetCore("SendNotification", {
Title = "Builder Mode",
Text = isLocked and "🔒 Position Locked! Triple tap to build." or "🔓 Position Unlocked!",
Duration = 2
})
elseif tapCount == 3 then
isLocked = true
RunService:UnbindFromRenderStep("BuilderGhost")
inputConnection:Disconnect()
startBuildProcess()
end
end
end)
StarterGui:SetCore("SendNotification", {
Title = "Builder Mode Activated",
Text = "Double tap to lock position.\nTriple tap to build.",
Duration = 5
})