· 6 years ago · Dec 19, 2019, 07:16 AM
1local Players = require(game.ServerScriptService.LeaderBoardModule)
2
3game.Lighting.TimeOfDay = 0
4
5local Template = workspace.Template
6
7local SubLevel = 1
8local HeightOffset = Template:GetExtentsSize().Y - 4
9local MinSPCShowAtLVLFromPlr = 5
10local MaxSPCShowAtLVLFromPlr = 10
11local SCP_Brain = script["SCP-087 Brain"]:Clone()
12local SummonedSCP = false
13local TemplateTble = {Total = 0}
14local Pad1 = {}
15local Pad2 = {}
16
17function TemplateTble:init(mdl)
18 local keyObj = (function() local num = 8 local Key = Instance.new("StringValue") local Keys = {"1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"} Key.Name = "" for i=1,num do Key.Name = Key.Name..Keys[math.random(1,#Keys)] end return Key end)
19
20 if(mdl:IsA("BasePart") == true) then
21 local key = keyObj()
22 key.Parent = mdl
23 self[key.Name] = {Ref = mdl}
24 self.Total = self.Total+1
25 elseif(mdl:IsA("Model") == true)then
26 local Bits = mdl:GetChildren()
27 for n,Obj in next,Bits do
28 local BInside = Obj:GetChildren()
29 if(Obj:IsA("BasePart") == true) then
30 local key = keyObj()
31 key.Parent = Obj
32 self[key.Name] = {Ref = Obj}
33 self.Total = self.Total+1
34 elseif(Obj:IsA("Model") == true)then
35 self:init(Obj)
36 end
37 end
38 end
39end
40TemplateTble:init(Template)
41--[[ Clear our function out from the table so it's not included in the for loops below and break things ]]
42TemplateTble["init"] = nil
43
44
45
46local TemplateMiddlePart = (function()
47 local Part = nil
48 local TemplateBits = TemplateTble
49 local SX = 0
50 local SY = 0
51 local SZ = 0
52 local CenterPoint = Vector3.new()
53 for key,Obj in next, TemplateBits do
54 if(key ~= "Total") then
55 --print(key,Obj)
56 if(Obj.Ref:IsA("BasePart") == true) then
57 local X = Obj.Ref.Position.X
58 local Y = Obj.Ref.Position.Y
59 local Z = Obj.Ref.Position.Z
60 SX = SX + X
61 SY = SY + Y
62 SZ = SZ + Z
63 end
64 end
65 end
66 SX = SX/TemplateBits.Total
67 SY = SY/TemplateBits.Total
68 SZ = SZ/TemplateBits.Total
69 CenterPoint = Vector3.new(SX,SY,SZ)
70 local Dist = math.huge
71 for key,Obj in next, TemplateBits do
72 if(key ~= "Total") then
73 if(Obj.Ref:IsA("BasePart") == true) then
74 local D = (CenterPoint - Obj.Ref.Position).magnitude
75 if(D < Dist) then
76 Part = Obj.Ref
77 Dist = D
78 end
79 end
80 end
81 end
82 return Part
83end)()
84
85if(TemplateMiddlePart == nil) then
86 error("Cannot run game due to not finding the center of your template!\n Stopping main script, due to errors!...")
87 return
88end
89
90--[[
91 ========================
92 Debugging
93 ========================
94]]
95
96function tprint (tbl, indent)
97 if not indent then indent = 0 end
98 for k, v in next,tbl do
99 local formatting = string.rep(" ", indent) .. tostring(k) .. ": "
100 if type(v) == "table" then
101 print(formatting)
102 tprint(v, indent+1)
103 else
104 print(formatting .. tostring(v))
105 end
106 end
107end
108-- Enable this to print out our master template table
109-- tprint(TemplateBits)
110--[[
111
112 ==========================
113 End of debugging
114 ==========================
115]]
116--[[ Add the offset from the center part to our master table ]]
117for key,Obj in next, TemplateTble do
118 if(key ~= "Total") then
119 local Pos_OFfset = Obj.Ref.Position - TemplateMiddlePart.Position
120 TemplateTble[key].Pos_OFfset = Pos_OFfset
121 end
122end
123
124
125
126
127
128function CreateNextLevel(newLevel)
129 local YOffset = Template:GetExtentsSize().Y
130 local Exists = workspace:FindFirstChild("Level_"..newLevel) ~= nil
131 if(Exists == false) then
132 -- Right if the level doesn't exist then lets create it!...
133 local Clone = Template:Clone()
134 for key,Tble in next, TemplateTble do
135 if(key ~= "Total") then
136 local Obj = Tble.Ref
137 local CCopy_Part = Clone:FindFirstChild(key,true)
138 if(CCopy_Part ~= nil) then
139 CCopy_Part.Parent.Position = Obj.Position -Vector3.new(0,SubLevel*(YOffset-4.5),0)
140 if(CCopy_Part.Parent.Name == "Landing2") then
141 CCopy_Part.Parent.Touched:connect(function(otr) ConnectNewLevel(otr,CCopy_Part.Parent) end)
142 end
143 if(CCopy_Part.Parent.Name == "Landing1") then
144 CCopy_Part.Parent.Touched:connect(function(otr) AddLevelToPlayer(otr,CCopy_Part.Parent.Parent) end)
145 end
146 end
147 end
148
149 end
150 Clone.MyLevel.Value = SubLevel
151 Clone.Name = "Level_"..SubLevel
152 Clone.Parent = workspace
153 SubLevel = SubLevel +1
154 end
155end
156
157function AddLevelToPlayer(plr,LvlMdl)
158 local isHumanoid = (function() local isValid = false local Hum = plr.Parent:FindFirstChildOfClass("Humanoid") if(Hum ~= nil) then isValid = Hum.Health > 0 end return isValid end)()
159 local TouchedLevel = LvlMdl.MyLevel.Value
160 if(isHumanoid == true) then
161 local IsPlayer = (game.Players:GetPlayerFromCharacter(plr.Parent) ~= nil)
162 if(IsPlayer == true) then
163
164 local Player = game.Players:GetPlayerFromCharacter(plr.Parent)
165 local Stats = Player:FindFirstChild("leaderstats")
166
167 if(Stats ~= nil) then
168 local Levels = Stats:FindFirstChild("Sub-Level")
169 local MaxLevel = Stats:findFirstChild("Lowest Level")
170 if(Levels ~= nil) then
171 Levels.Value = TouchedLevel
172 Players:UpdateStats(Player,"Sub-Level",Levels.Name,TouchedLevel)
173 end
174 if(MaxLevel ~= nil) then
175 if(Levels.Value > MaxLevel.Value) then
176 MaxLevel.Value = Levels.Value
177 Players:UpdateStats(Player,"MaxLevel",MaxLevel.Name,Levels.Value)
178 end
179 end
180 end
181 end
182 end
183end
184
185function SummonSCP(hrp,CurLevel)
186 local SCP = (function() local CLvl = workspace:FindFirstChild("Level_"..CurLevel) if(CLvl ~= nil) then return CLvl:FindFirstChild("SCP-087") end return nil end)()
187 local NoBrain = (function() local IsIt = true if(SCP ~= nil) then IsIt = SCP:FindFirstChild(SCP_Brain.Name) == nil end return IsIt end)()
188 local Player = game.Players:GetPlayerFromCharacter(hrp.Parent)
189
190 if(SummonedSCP == false) then
191 if(Player ~= nil) then
192 local Settings = Player:FindFirstChild("Settings")
193 if(Settings ~= nil) then
194 local Show_SCP_AT = Settings:FindFirstChild("Spawn SCP at Level")
195 print("Gordon Ramsay Sleeping... till ",Player," gets to ",Show_SCP_AT.Value,",",Player," is currently at floor number ",CurLevel)
196
197 Players:UpdateStats(Player,"Spawn SCP at Level",Show_SCP_AT.Name,Show_SCP_AT.Value)
198 local Settings = Player:FindFirstChild("Settings")
199 if((CurLevel > Show_SCP_AT.Value and SummonedSCP == false) or (CurLevel < Show_SCP_AT.Value-MaxSPCShowAtLVLFromPlr)) then
200 local Min = CurLevel-MaxSPCShowAtLVLFromPlr >1 and CurLevel-MaxSPCShowAtLVLFromPlr or math.random(MinSPCShowAtLVLFromPlr,MaxSPCShowAtLVLFromPlr)
201 local Max = CurLevel > Min and CurLevel or Min + math.random(MinSPCShowAtLVLFromPlr,MaxSPCShowAtLVLFromPlr)
202 Show_SCP_AT.Value = math.random(Min,Max)
203 end
204 if(CurLevel == Show_SCP_AT.Value and SCP ~= nil) then
205 print("Waking SCP OnFloorNumber[",CurLevel,"]")
206 SummonedSCP = true
207 if(hrp ~= nil) then
208 SCP.GotoPlayer.Value = hrp
209 end
210
211 local SCPB = SCP_Brain:Clone()
212 SCPB.Parent = SCP
213 SCPB.Disabled = false
214 NoBrain = false
215 end
216 end
217 end
218 else
219 print("Gordon Ramsay Active ... waiting for it to disappear...")
220 if(SCP ~= nil) then
221 local NoBrain = (function() local IsIt = true if(SCP ~= nil) then IsIt = SCP:FindFirstChild(SCP_Brain.Name) == nil end return IsIt end)()
222 local SCPActive = SCP:FindFirstChild("Active")
223 if(SCPActive ~= nil) then
224 if(SCPActive.Value == false and NoBrain == true) then
225 print("Resetting Gordon Ramsay...")
226 SummonedSCP = false
227 local Settings = Player:FindFirstChild("Settings")
228 if(Settings ~= nil) then
229 local Show_SCP_AT = Settings:FindFirstChild("Spawn SCP at Level")
230 local NewValue = math.random(CurLevel+MinSPCShowAtLVLFromPlr,CurLevel+MaxSPCShowAtLVLFromPlr)
231 Show_SCP_AT.Value = NewValue
232 Players:UpdateStats(Player,"Spawn SCP at Level",Show_SCP_AT.Name,NewValue)
233
234 end
235 end
236 end
237 end
238 end
239end
240
241function ConnectNewLevel(Thing,Touchy)
242
243 local isHumanoid = (function() local isValid = false local Hum = Thing.Parent:FindFirstChildOfClass("Humanoid") if(Hum ~= nil) then isValid = Hum.Health > 0 end return isValid end)()
244 if(isHumanoid == true) then
245 local IsPlayer = (game.Players:GetPlayerFromCharacter(Thing.Parent) ~= nil)
246 if(IsPlayer == true) then
247 local Player = game.Players:GetPlayerFromCharacter(Thing.Parent)
248
249 if(Player ~= nil) then
250 local PlrFloorLevel = Player.leaderstats["Sub-Level"].Value
251 local PlrSettings = Player:FindFirstChild("Settings")
252 local justDied = false
253 local SpawnSCPForPlayerAT_obj = nil
254
255
256 if(PlrSettings ~= nil) then
257 SpawnSCPForPlayerAT_obj = PlrSettings:FindFirstChild("Spawn SCP at Level")
258 justDied = PlrSettings:FindFirstChild("Got-Ya!") ~= nil
259 end
260 if(SpawnSCPForPlayerAT_obj ~= nil) then
261 if(SpawnSCPForPlayerAT_obj.Value == 0) then
262 SpawnSCPForPlayerAT_obj.Value = math.random(PlrFloorLevel+MinSPCShowAtLVLFromPlr,PlrFloorLevel+MaxSPCShowAtLVLFromPlr)
263 end
264 end
265 if(justDied == true) then
266 SpawnSCPForPlayerAT_obj.Value = math.random(PlrFloorLevel+MinSPCShowAtLVLFromPlr,PlrFloorLevel+MaxSPCShowAtLVLFromPlr)
267 PlrSettings["Got-Ya!"]:Destroy()
268 end
269 CreateNextLevel(Touchy.Parent.MyLevel.Value+1)
270 SummonSCP(Thing.Parent.Head,PlrFloorLevel+1)
271 end
272 end
273 end
274end
275
276
277workspace.Template.Landing1.Touched:connect(function(otr)
278 local Player = otr.Parent
279 AddLevelToPlayer(otr,workspace.Template)
280end)
281
282workspace.Template.Landing2.Touched:connect(function(otr)
283 local Player = otr.Parent
284 ConnectNewLevel(otr,workspace.Template.Landing2)
285end)