forked from Catsuq/Doors-Entity-Replicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskellyKeyRoomRep.lua
230 lines (176 loc) · 7.18 KB
/
skellyKeyRoomRep.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
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
-- Services
local Players = game:GetService("Players")
local TS = game:GetService("TweenService")
local ReSt = game:GetService("ReplicatedStorage")
-- Variables
local Plr = Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Hum = Char:WaitForChild("Humanoid")
local Root = Char:WaitForChild("HumanoidRootPart")
local SelfModules = {
Functions = loadstring(game:HttpGet("https://raw.githubusercontent.com/RegularVynixu/Utilities/main/Functions.lua"))(),
}
local Assets = {
Door = LoadCustomInstance("https://github.com/RegularVynixu/Utilities/blob/main/Doors/Door%20Replication/Door.rbxm?raw=true"),
}
local DoorReplication = {}
-- Misc Functions
local function openDoor(doorTable)
doorTable.Debug.OnDoorPreOpened()
doorTable.Model:SetAttribute("Opened", true)
if doorTable.Model:FindFirstChild("Lock") then
-- Unlock visual
doorTable.Model.Lock.UnlockPrompt.Enabled = false
doorTable.Model.Lock.M_Thing.C0 = doorTable.Model.Lock.M_Thing.C0 * CFrame.Angles(0, math.rad(-45), 0)
doorTable.Model.Hinge.Lock:Destroy()
doorTable.Model.Lock.UnlockPrompt:Destroy()
end
-- Door opening visual
if doorTable.Model:FindFirstChild("Light") then
doorTable.Model.Light.Light.Color = Color3.fromRGB(197, 113, 88)
doorTable.Model.Light.Light.Attachment.PointLight.Enabled = true
doorTable.Model.Light.Light.Hit:Play()
end
doorTable.Model.Door.CanCollide = false
doorTable.Model.Door.Open:Play()
doorTable.Model.Hidden:Destroy()
task.spawn(function()
local knobC1 = doorTable.Model.Hinge.Knob.C1
TS:Create(doorTable.Model.Hinge.Knob, TweenInfo.new(0.15, Enum.EasingStyle.Quad), {C1 = knobC1 * CFrame.Angles(0, 0, math.rad(-35))}):Play()
task.wait(0.15)
TS:Create(doorTable.Model.Hinge.Knob, TweenInfo.new(0.15, Enum.EasingStyle.Quad), {C1 = knobC1}):Play()
end)
TS:Create(doorTable.Model.Hinge, TweenInfo.new(doorTable.Config.FastOpen and 0.15 or 0.75, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {CFrame = doorTable.Model.Hinge.CFrame * CFrame.Angles(0, math.rad(-90), 0)}):Play()
-- Next room preparations
local nextRoom = workspace.CurrentRooms:FindFirstChild(tonumber(doorTable.Model.Parent.Name) + 1)
if nextRoom then
for _, v in next, {"Assets", "Light_Fixtures"} do
if nextRoom:FindFirstChild(v) then
for _, v2 in next, nextRoom[v]:GetDescendants() do
if string.find(v2.ClassName, "Light") and not v2.Enabled then
v2.Enabled = true
end
end
end
end
end
doorTable.Debug.OnDoorOpened()
end
-- Functions
DoorReplication.CreateDoor = function(config)
-- Configs setup
for _, v in next, {"Key", "Lockpick"} do
if not table.find(config.CustomKeyNames, v) then
table.insert(config.CustomKeyNames, v)
end
end
-- Model
local model = Assets.Door:Clone()
model.Door.MaterialVariant = "PlywoodALT"
model.Sign.MaterialVariant = "Plywood"
if not config.Barricaded then
model.Boards:Destroy()
if not config.Locked then
model.Lock:Destroy()
end
if config.Sign == false then
model.Sign:Destroy()
model.Gui:Destroy()
else
task.spawn(function()
repeat task.wait() until model.Parent and tonumber(model.Parent.Name)
local signText = ""
for i = #tostring(model.Parent.Name + 1), 3 do
signText = signText.. "0"
end
signText = signText.. model.Parent.Name + 1
for _, v in next, model.Gui:GetDescendants() do
if v.ClassName == "TextLabel" then
v.Text = signText
end
end
end)
end
if config.Light == false then
model.Light:Destroy()
end
else
model.Lock:Destroy()
model.Sign:Destroy()
model.Gui:Destroy()
end
return {
Model = model,
Config = config,
Debug = {
OnDoorPreOpened = function() end,
OnDoorOpened = function() end,
},
}
end
DoorReplication.ReplicateDoor = function(doorTable)
-- Pre-check
if not doorTable.Model.Parent then
warn("Failure - Parent the door before replicating it")
return
elseif doorTable.Config.Barricaded then
warn("Failure - Attempt to replicate a barricaded door")
return
end
-- Guiding light
if doorTable.Config.GuidingLight ~= false and doorTable.Model.Parent:GetAttribute("IsDark") then
task.spawn(function()
if not doorTable.Model.Door.LightAttach.HelpLight.Enabled then
task.wait(15)
end
if doorTable.Model.Parent and not doorTable.Model:GetAttribute("Opened") then
doorTable.Model.Door.LightAttach.HelpLight.Enabled = true
doorTable.Model.Door.LightAttach.HelpParticle.Enabled = true
TS:Create(doorTable.Model.Door.LightAttach.HelpLight, TweenInfo.new(2), {Brightness = 0.5}):Play()
end
end)
end
-- Connections
local connections = {}
if doorTable.Model:FindFirstChild("Lock") then
connections.unlockBegan = doorTable.Model.Lock.UnlockPrompt.PromptButtonHoldBegan:Connect(function()
for _, v in next, doorTable.Config.CustomKeyNames do
local key = Char:FindFirstChild(v)
if key and key:FindFirstChild("Animations") and key.Animations:FindFirstChild("use") then
Hum:LoadAnimation(key.Animations.use):Play()
return
end
end
firesignal(ReSt.Bricks.Caption.OnClientEvent, "You need a key!", true)
end)
connections.unlockTriggered = doorTable.Model.Lock.UnlockPrompt.Triggered:Connect(function()
for _, v in next, doorTable.Config.CustomKeyNames do
local key = Char:FindFirstChild(v)
if key then
for _, v in next, connections do
v:Disconnect()
end
if key:GetAttribute("uses") then key:SetAttribute("uses", key:GetAttribute("uses")-1) end
if not key:GetAttribute("uses") and doorTable.Config.DestroyKey ~= false or key:GetAttribute("uses")==0 then
key:Destroy()
if key:FindFirstChild("Handle"):FindFIrstChild("Curse") then key.Handle.Curse:Play() end
end
openDoor(doorTable)
break
end
end
end)
else
task.spawn(function()
while doorTable.Model.Parent and Root do
if (Root.Position - doorTable.Model.PrimaryPart.Position).Magnitude <= 15 then
openDoor(doorTable)
break
end
task.wait()
end
end)
end
end
-- Scripts
return DoorReplication