Advertisement
N0ePlox

spooky npc

Nov 25th, 2018
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 62.25 KB | None | 0 0
  1.  
  2. --Converted with ttyyuu12345's model to script plugin v4
  3. function sandbox(var,func)
  4. local env = getfenv(func)
  5. local newenv = setmetatable({},{
  6. __index = function(self,k)
  7. if k=="script" then
  8. return var
  9. else
  10. return env[k]
  11. end
  12. end,
  13. })
  14. setfenv(func,newenv)
  15. return func
  16. end
  17. cors = {}
  18. mas = Instance.new("Model",game:GetService("Lighting"))
  19. Model0 = Instance.new("Model")
  20. Part1 = Instance.new("Part")
  21. Motor6D2 = Instance.new("Motor6D")
  22. Part3 = Instance.new("Part")
  23. Motor6D4 = Instance.new("Motor6D")
  24. Motor6D5 = Instance.new("Motor6D")
  25. Motor6D6 = Instance.new("Motor6D")
  26. Motor6D7 = Instance.new("Motor6D")
  27. BodyForce8 = Instance.new("BodyForce")
  28. Motor6D9 = Instance.new("Motor6D")
  29. Part10 = Instance.new("Part")
  30. Part11 = Instance.new("Part")
  31. Part12 = Instance.new("Part")
  32. Part13 = Instance.new("Part")
  33. Part14 = Instance.new("Part")
  34. SpecialMesh15 = Instance.new("SpecialMesh")
  35. Humanoid16 = Instance.new("Humanoid")
  36. Script17 = Instance.new("Script")
  37. StringValue18 = Instance.new("StringValue")
  38. Animation19 = Instance.new("Animation")
  39. StringValue20 = Instance.new("StringValue")
  40. Animation21 = Instance.new("Animation")
  41. StringValue22 = Instance.new("StringValue")
  42. Animation23 = Instance.new("Animation")
  43. NumberValue24 = Instance.new("NumberValue")
  44. Animation25 = Instance.new("Animation")
  45. NumberValue26 = Instance.new("NumberValue")
  46. StringValue27 = Instance.new("StringValue")
  47. Animation28 = Instance.new("Animation")
  48. StringValue29 = Instance.new("StringValue")
  49. Animation30 = Instance.new("Animation")
  50. StringValue31 = Instance.new("StringValue")
  51. Animation32 = Instance.new("Animation")
  52. StringValue33 = Instance.new("StringValue")
  53. Animation34 = Instance.new("Animation")
  54. Script35 = Instance.new("Script")
  55. BillboardGui36 = Instance.new("BillboardGui")
  56. TextLabel37 = Instance.new("TextLabel")
  57. Configuration38 = Instance.new("Configuration")
  58. ModuleScript39 = Instance.new("ModuleScript")
  59. ModuleScript40 = Instance.new("ModuleScript")
  60. ModuleScript41 = Instance.new("ModuleScript")
  61. ModuleScript42 = Instance.new("ModuleScript")
  62. ModuleScript43 = Instance.new("ModuleScript")
  63. ModuleScript44 = Instance.new("ModuleScript")
  64. Configuration45 = Instance.new("Configuration")
  65. IntValue46 = Instance.new("IntValue")
  66. BoolValue47 = Instance.new("BoolValue")
  67. IntValue48 = Instance.new("IntValue")
  68. IntValue49 = Instance.new("IntValue")
  69. Configuration50 = Instance.new("Configuration")
  70. Animation51 = Instance.new("Animation")
  71. Animation52 = Instance.new("Animation")
  72. CharacterMesh53 = Instance.new("CharacterMesh")
  73. CharacterMesh54 = Instance.new("CharacterMesh")
  74. CharacterMesh55 = Instance.new("CharacterMesh")
  75. CharacterMesh56 = Instance.new("CharacterMesh")
  76. CharacterMesh57 = Instance.new("CharacterMesh")
  77. Sound58 = Instance.new("Sound")
  78. BodyColors59 = Instance.new("BodyColors")
  79. Script60 = Instance.new("Script")
  80. MeshPart61 = Instance.new("MeshPart")
  81. Model0.Name = "Drooling Zombie"
  82. Model0.Parent = mas
  83. Part1.Name = "HumanoidRootPart"
  84. Part1.Parent = Model0
  85. Part1.CFrame = CFrame.new(-734.89978, 3.99996591, 313.700012, 4.49431016e-21, -6.80004916e-22, -1, 4.72213198e-22, 1, -6.80004916e-22, 1, -4.72213198e-22, 4.49431016e-21)
  86. Part1.Orientation = Vector3.new(0, -90, 0)
  87. Part1.Position = Vector3.new(-734.89978, 3.99996591, 313.700012)
  88. Part1.Rotation = Vector3.new(0, -90, 0)
  89. Part1.Color = Color3.new(0.152941, 0.27451, 0.176471)
  90. Part1.Transparency = 1
  91. Part1.Size = Vector3.new(2, 2, 1)
  92. Part1.BottomSurface = Enum.SurfaceType.Smooth
  93. Part1.BrickColor = BrickColor.new("Earth green")
  94. Part1.Material = Enum.Material.WoodPlanks
  95. Part1.TopSurface = Enum.SurfaceType.Smooth
  96. Part1.brickColor = BrickColor.new("Earth green")
  97. Part1.FormFactor = Enum.FormFactor.Symmetric
  98. Part1.formFactor = Enum.FormFactor.Symmetric
  99. Motor6D2.Name = "Root Hip"
  100. Motor6D2.Parent = Part1
  101. Motor6D2.MaxVelocity = 0.10000000149012
  102. Motor6D2.C0 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  103. Motor6D2.C1 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  104. Motor6D2.Part0 = Part1
  105. Motor6D2.Part1 = Part3
  106. Motor6D2.part1 = Part3
  107. Part3.Name = "Torso"
  108. Part3.Parent = Model0
  109. Part3.CFrame = CFrame.new(-734.89978, 3.99996591, 313.700012, 4.49431016e-21, -6.80004916e-22, -1, 4.72213198e-22, 1, -6.80004916e-22, 1, -4.72213198e-22, 4.49431016e-21)
  110. Part3.Orientation = Vector3.new(0, -90, 0)
  111. Part3.Position = Vector3.new(-734.89978, 3.99996591, 313.700012)
  112. Part3.Rotation = Vector3.new(0, -90, 0)
  113. Part3.Color = Color3.new(0.152941, 0.27451, 0.176471)
  114. Part3.Transparency = 1
  115. Part3.Size = Vector3.new(2, 2, 1)
  116. Part3.BottomSurface = Enum.SurfaceType.Smooth
  117. Part3.BrickColor = BrickColor.new("Earth green")
  118. Part3.Material = Enum.Material.WoodPlanks
  119. Part3.TopSurface = Enum.SurfaceType.Smooth
  120. Part3.brickColor = BrickColor.new("Earth green")
  121. Part3.FormFactor = Enum.FormFactor.Symmetric
  122. Part3.formFactor = Enum.FormFactor.Symmetric
  123. Motor6D4.Name = "Left Hip"
  124. Motor6D4.Parent = Part3
  125. Motor6D4.MaxVelocity = 0.10000000149012
  126. Motor6D4.C0 = CFrame.new(-1, -1, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
  127. Motor6D4.C1 = CFrame.new(-0.5, 1, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
  128. Motor6D4.Part0 = Part3
  129. Motor6D4.Part1 = Part10
  130. Motor6D4.part1 = Part10
  131. Motor6D5.Name = "Left Shoulder"
  132. Motor6D5.Parent = Part3
  133. Motor6D5.MaxVelocity = 0.10000000149012
  134. Motor6D5.C0 = CFrame.new(-1, 0.5, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
  135. Motor6D5.C1 = CFrame.new(0.5, 0.5, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
  136. Motor6D5.Part0 = Part3
  137. Motor6D5.Part1 = Part12
  138. Motor6D5.part1 = Part12
  139. Motor6D6.Name = "Right Shoulder"
  140. Motor6D6.Parent = Part3
  141. Motor6D6.MaxVelocity = 0.10000000149012
  142. Motor6D6.C0 = CFrame.new(1, 0.5, 0, -4.37113883e-08, 0, 1, -0, 0.99999994, 0, -1, 0, -4.37113883e-08)
  143. Motor6D6.C1 = CFrame.new(-0.5, 0.5, 0, -4.37113883e-08, 0, 1, 0, 0.99999994, 0, -1, 0, -4.37113883e-08)
  144. Motor6D6.Part0 = Part3
  145. Motor6D6.Part1 = Part13
  146. Motor6D6.part1 = Part13
  147. Motor6D7.Name = "Neck"
  148. Motor6D7.Parent = Part3
  149. Motor6D7.MaxVelocity = 0.10000000149012
  150. Motor6D7.C0 = CFrame.new(0, 1, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  151. Motor6D7.C1 = CFrame.new(0, -0.5, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  152. Motor6D7.Part0 = Part3
  153. Motor6D7.Part1 = Part14
  154. Motor6D7.part1 = Part14
  155. BodyForce8.Name = "RepulsionForce"
  156. BodyForce8.Parent = Part3
  157. BodyForce8.Force = Vector3.new(0, 0, 0)
  158. BodyForce8.force = Vector3.new(0, 0, 0)
  159. Motor6D9.Name = "Right Hip"
  160. Motor6D9.Parent = Part3
  161. Motor6D9.MaxVelocity = 0.10000000149012
  162. Motor6D9.C0 = CFrame.new(1, -1, 0, -4.37113883e-08, 0, 1, -0, 0.99999994, 0, -1, 0, -4.37113883e-08)
  163. Motor6D9.C1 = CFrame.new(0.5, 1, 0, -4.37113883e-08, 0, 1, 0, 0.99999994, 0, -1, 0, -4.37113883e-08)
  164. Motor6D9.Part0 = Part3
  165. Motor6D9.Part1 = Part11
  166. Motor6D9.part1 = Part11
  167. Part10.Name = "Left Leg"
  168. Part10.Parent = Model0
  169. Part10.CFrame = CFrame.new(-734.89978, 1.99996603, 313.200012, 4.49431016e-21, -6.80004815e-22, -1, 4.72213198e-22, 0.999999881, -6.80004916e-22, 1, -4.72213148e-22, 4.49431016e-21)
  170. Part10.Orientation = Vector3.new(0, -90, 0)
  171. Part10.Position = Vector3.new(-734.89978, 1.99996603, 313.200012)
  172. Part10.Rotation = Vector3.new(0, -90, 0)
  173. Part10.Color = Color3.new(0.152941, 0.27451, 0.176471)
  174. Part10.Transparency = 1
  175. Part10.Size = Vector3.new(1, 2, 1)
  176. Part10.BottomSurface = Enum.SurfaceType.Smooth
  177. Part10.BrickColor = BrickColor.new("Earth green")
  178. Part10.CanCollide = false
  179. Part10.Material = Enum.Material.WoodPlanks
  180. Part10.TopSurface = Enum.SurfaceType.Smooth
  181. Part10.brickColor = BrickColor.new("Earth green")
  182. Part10.FormFactor = Enum.FormFactor.Symmetric
  183. Part10.formFactor = Enum.FormFactor.Symmetric
  184. Part11.Name = "Right Leg"
  185. Part11.Parent = Model0
  186. Part11.CFrame = CFrame.new(-734.89978, 1.99996603, 314.200012, 4.49431016e-21, -6.80004815e-22, -1, 4.72213198e-22, 0.999999881, -6.80004916e-22, 1, -4.72213148e-22, 4.49431016e-21)
  187. Part11.Orientation = Vector3.new(0, -90, 0)
  188. Part11.Position = Vector3.new(-734.89978, 1.99996603, 314.200012)
  189. Part11.Rotation = Vector3.new(0, -90, 0)
  190. Part11.Color = Color3.new(0.152941, 0.27451, 0.176471)
  191. Part11.Transparency = 1
  192. Part11.Size = Vector3.new(1, 2, 1)
  193. Part11.BottomSurface = Enum.SurfaceType.Smooth
  194. Part11.BrickColor = BrickColor.new("Earth green")
  195. Part11.CanCollide = false
  196. Part11.Material = Enum.Material.WoodPlanks
  197. Part11.TopSurface = Enum.SurfaceType.Smooth
  198. Part11.brickColor = BrickColor.new("Earth green")
  199. Part11.FormFactor = Enum.FormFactor.Symmetric
  200. Part11.formFactor = Enum.FormFactor.Symmetric
  201. Part12.Name = "Left Arm"
  202. Part12.Parent = Model0
  203. Part12.CFrame = CFrame.new(-734.89978, 3.99996591, 312.200012, 4.49431016e-21, -6.80004815e-22, -1, 4.72213198e-22, 0.999999881, -6.80004916e-22, 1, -4.72213148e-22, 4.49431016e-21)
  204. Part12.Orientation = Vector3.new(0, -90, 0)
  205. Part12.Position = Vector3.new(-734.89978, 3.99996591, 312.200012)
  206. Part12.Rotation = Vector3.new(0, -90, 0)
  207. Part12.Color = Color3.new(0.152941, 0.27451, 0.176471)
  208. Part12.Transparency = 1
  209. Part12.Size = Vector3.new(1, 2, 1)
  210. Part12.BottomSurface = Enum.SurfaceType.Smooth
  211. Part12.BrickColor = BrickColor.new("Earth green")
  212. Part12.CanCollide = false
  213. Part12.Material = Enum.Material.WoodPlanks
  214. Part12.TopSurface = Enum.SurfaceType.Smooth
  215. Part12.brickColor = BrickColor.new("Earth green")
  216. Part12.FormFactor = Enum.FormFactor.Symmetric
  217. Part12.formFactor = Enum.FormFactor.Symmetric
  218. Part13.Name = "Right Arm"
  219. Part13.Parent = Model0
  220. Part13.CFrame = CFrame.new(-734.89978, 3.99996591, 315.200012, 4.49431016e-21, -6.80004815e-22, -1, 4.72213198e-22, 0.999999881, -6.80004916e-22, 1, -4.72213148e-22, 4.49431016e-21)
  221. Part13.Orientation = Vector3.new(0, -90, 0)
  222. Part13.Position = Vector3.new(-734.89978, 3.99996591, 315.200012)
  223. Part13.Rotation = Vector3.new(0, -90, 0)
  224. Part13.Color = Color3.new(0.152941, 0.27451, 0.176471)
  225. Part13.Transparency = 1
  226. Part13.Size = Vector3.new(1, 2, 1)
  227. Part13.BottomSurface = Enum.SurfaceType.Smooth
  228. Part13.BrickColor = BrickColor.new("Earth green")
  229. Part13.CanCollide = false
  230. Part13.Material = Enum.Material.WoodPlanks
  231. Part13.TopSurface = Enum.SurfaceType.Smooth
  232. Part13.brickColor = BrickColor.new("Earth green")
  233. Part13.FormFactor = Enum.FormFactor.Symmetric
  234. Part13.formFactor = Enum.FormFactor.Symmetric
  235. Part14.Name = "Head"
  236. Part14.Parent = Model0
  237. Part14.CFrame = CFrame.new(-734.89978, 5.49996567, 313.700012, 4.49431016e-21, -6.80004916e-22, -1, 4.72213198e-22, 1, -6.80004916e-22, 1, -4.72213198e-22, 4.49431016e-21)
  238. Part14.Orientation = Vector3.new(0, -90, 0)
  239. Part14.Position = Vector3.new(-734.89978, 5.49996567, 313.700012)
  240. Part14.Rotation = Vector3.new(0, -90, 0)
  241. Part14.Color = Color3.new(0.227451, 0.490196, 0.0823529)
  242. Part14.Transparency = 1
  243. Part14.Size = Vector3.new(2, 1, 1)
  244. Part14.BottomSurface = Enum.SurfaceType.Smooth
  245. Part14.BrickColor = BrickColor.new("Camo")
  246. Part14.Material = Enum.Material.WoodPlanks
  247. Part14.TopSurface = Enum.SurfaceType.Smooth
  248. Part14.brickColor = BrickColor.new("Camo")
  249. Part14.FormFactor = Enum.FormFactor.Symmetric
  250. Part14.formFactor = Enum.FormFactor.Symmetric
  251. SpecialMesh15.Parent = Part14
  252. SpecialMesh15.Scale = Vector3.new(1.25, 1.25, 1.25)
  253. Humanoid16.Parent = Model0
  254. Humanoid16.LeftLeg = Part10
  255. Humanoid16.RightLeg = Part11
  256. Humanoid16.Torso = Part1
  257. Humanoid16.WalkSpeed = 2
  258. Script17.Name = "Animate"
  259. Script17.Parent = Model0
  260. table.insert(cors,sandbox(Script17,function()
  261. function waitForChild(parent, childName)
  262. local child = parent:findFirstChild(childName)
  263. if child then return child end
  264. while true do
  265. child = parent.ChildAdded:wait()
  266. if child.Name==childName then return child end
  267. end
  268. end
  269.  
  270. local Figure = script.Parent
  271. local Torso = waitForChild(Figure, "Torso")
  272. local RightShoulder = waitForChild(Torso, "Right Shoulder")
  273. local LeftShoulder = waitForChild(Torso, "Left Shoulder")
  274. local RightHip = waitForChild(Torso, "Right Hip")
  275. local LeftHip = waitForChild(Torso, "Left Hip")
  276. local Neck = waitForChild(Torso, "Neck")
  277. local Humanoid = waitForChild(Figure, "Humanoid")
  278. local pose = "Standing"
  279.  
  280. local currentAnim = ""
  281. local currentAnimTrack = nil
  282. local currentAnimKeyframeHandler = nil
  283. local currentAnimSpeed = 1.0
  284. local animTable = {}
  285. local animNames = {
  286. idle = {
  287. { id = "http://www.roblox.com/asset/?id=125750544", weight = 9 },
  288. { id = "http://www.roblox.com/asset/?id=125750618", weight = 1 }
  289. },
  290. walk = {
  291. { id = "http://www.roblox.com/asset/?id=125749145", weight = 10 }
  292. },
  293. run = {
  294. { id = "run.xml", weight = 10 }
  295. },
  296. jump = {
  297. { id = "http://www.roblox.com/asset/?id=125750702", weight = 10 }
  298. },
  299. fall = {
  300. { id = "http://www.roblox.com/asset/?id=125750759", weight = 10 }
  301. },
  302. climb = {
  303. { id = "http://www.roblox.com/asset/?id=125750800", weight = 10 }
  304. },
  305. toolnone = {
  306. { id = "http://www.roblox.com/asset/?id=125750867", weight = 10 }
  307. },
  308. toolslash = {
  309. { id = "http://www.roblox.com/asset/?id=129967390", weight = 10 }
  310. -- { id = "slash.xml", weight = 10 }
  311. },
  312. toollunge = {
  313. { id = "http://www.roblox.com/asset/?id=129967478", weight = 10 }
  314. },
  315. wave = {
  316. { id = "http://www.roblox.com/asset/?id=128777973", weight = 10 }
  317. },
  318. point = {
  319. { id = "http://www.roblox.com/asset/?id=128853357", weight = 10 }
  320. },
  321. dance = {
  322. { id = "http://www.roblox.com/asset/?id=130018893", weight = 10 },
  323. { id = "http://www.roblox.com/asset/?id=132546839", weight = 10 },
  324. { id = "http://www.roblox.com/asset/?id=132546884", weight = 10 }
  325. },
  326. dance2 = {
  327. { id = "http://www.roblox.com/asset/?id=160934142", weight = 10 },
  328. { id = "http://www.roblox.com/asset/?id=160934298", weight = 10 },
  329. { id = "http://www.roblox.com/asset/?id=160934376", weight = 10 }
  330. },
  331. dance3 = {
  332. { id = "http://www.roblox.com/asset/?id=160934458", weight = 10 },
  333. { id = "http://www.roblox.com/asset/?id=160934530", weight = 10 },
  334. { id = "http://www.roblox.com/asset/?id=160934593", weight = 10 }
  335. },
  336. laugh = {
  337. { id = "http://www.roblox.com/asset/?id=129423131", weight = 10 }
  338. },
  339. cheer = {
  340. { id = "http://www.roblox.com/asset/?id=129423030", weight = 10 }
  341. },
  342. }
  343.  
  344. -- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
  345. local emoteNames = { wave = false, point = false, dance = true, dance2 = true, dance3 = true, laugh = false, cheer = false}
  346.  
  347. math.randomseed(tick())
  348.  
  349. function configureAnimationSet(name, fileList)
  350. if (animTable[name] ~= nil) then
  351. for _, connection in pairs(animTable[name].connections) do
  352. connection:disconnect()
  353. end
  354. end
  355. animTable[name] = {}
  356. animTable[name].count = 0
  357. animTable[name].totalWeight = 0
  358. animTable[name].connections = {}
  359.  
  360. -- check for config values
  361. local config = script:FindFirstChild(name)
  362. if (config ~= nil) then
  363. -- print("Loading anims " .. name)
  364. table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
  365. table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
  366. local idx = 1
  367. for _, childPart in pairs(config:GetChildren()) do
  368. if (childPart:IsA("Animation")) then
  369. table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
  370. animTable[name][idx] = {}
  371. animTable[name][idx].anim = childPart
  372. local weightObject = childPart:FindFirstChild("Weight")
  373. if (weightObject == nil) then
  374. animTable[name][idx].weight = 1
  375. else
  376. animTable[name][idx].weight = weightObject.Value
  377. end
  378. animTable[name].count = animTable[name].count + 1
  379. animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  380. -- print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
  381. idx = idx + 1
  382. end
  383. end
  384. end
  385.  
  386. -- fallback to defaults
  387. if (animTable[name].count <= 0) then
  388. for idx, anim in pairs(fileList) do
  389. animTable[name][idx] = {}
  390. animTable[name][idx].anim = Instance.new("Animation")
  391. animTable[name][idx].anim.Name = name
  392. animTable[name][idx].anim.AnimationId = anim.id
  393. animTable[name][idx].weight = anim.weight
  394. animTable[name].count = animTable[name].count + 1
  395. animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  396. -- print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
  397. end
  398. end
  399. end
  400.  
  401. -- Setup animation objects
  402. function scriptChildModified(child)
  403. local fileList = animNames[child.Name]
  404. if (fileList ~= nil) then
  405. configureAnimationSet(child.Name, fileList)
  406. end
  407. end
  408.  
  409. script.ChildAdded:connect(scriptChildModified)
  410. script.ChildRemoved:connect(scriptChildModified)
  411.  
  412.  
  413. for name, fileList in pairs(animNames) do
  414. configureAnimationSet(name, fileList)
  415. end
  416.  
  417. -- ANIMATION
  418.  
  419. -- declarations
  420. local toolAnim = "None"
  421. local toolAnimTime = 0
  422.  
  423. local jumpAnimTime = 0
  424. local jumpAnimDuration = 0.3
  425.  
  426. local toolTransitionTime = 0.1
  427. local fallTransitionTime = 0.3
  428. local jumpMaxLimbVelocity = 0.75
  429.  
  430. -- functions
  431.  
  432. function stopAllAnimations()
  433. local oldAnim = currentAnim
  434.  
  435. -- return to idle if finishing an emote
  436. if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
  437. oldAnim = "idle"
  438. end
  439.  
  440. currentAnim = ""
  441. if (currentAnimKeyframeHandler ~= nil) then
  442. currentAnimKeyframeHandler:disconnect()
  443. end
  444.  
  445. if (currentAnimTrack ~= nil) then
  446. currentAnimTrack:Stop()
  447. currentAnimTrack:Destroy()
  448. currentAnimTrack = nil
  449. end
  450. return oldAnim
  451. end
  452.  
  453. function setAnimationSpeed(speed)
  454. if speed ~= currentAnimSpeed then
  455. currentAnimSpeed = speed
  456. currentAnimTrack:AdjustSpeed(currentAnimSpeed)
  457. end
  458. end
  459.  
  460. function keyFrameReachedFunc(frameName)
  461. if (frameName == "End") then
  462. -- print("Keyframe : ".. frameName)
  463. local repeatAnim = stopAllAnimations()
  464. local animSpeed = currentAnimSpeed
  465. playAnimation(repeatAnim, 0.0, Humanoid)
  466. setAnimationSpeed(animSpeed)
  467. end
  468. end
  469.  
  470. -- Preload animations
  471. function playAnimation(animName, transitionTime, humanoid)
  472. local idleFromEmote = (animName == "idle" and emoteNames[currentAnim] ~= nil)
  473. if (animName ~= currentAnim and not idleFromEmote) then
  474.  
  475. if (currentAnimTrack ~= nil) then
  476. currentAnimTrack:Stop(transitionTime)
  477. currentAnimTrack:Destroy()
  478. end
  479.  
  480. currentAnimSpeed = 1.0
  481. local roll = math.random(1, animTable[animName].totalWeight)
  482. local origRoll = roll
  483. local idx = 1
  484. while (roll > animTable[animName][idx].weight) do
  485. roll = roll - animTable[animName][idx].weight
  486. idx = idx + 1
  487. end
  488. -- print(animName .. " " .. idx .. " [" .. origRoll .. "]")
  489. local anim = animTable[animName][idx].anim
  490.  
  491. -- load it to the humanoid; get AnimationTrack
  492. currentAnimTrack = humanoid:LoadAnimation(anim)
  493.  
  494. -- play the animation
  495. currentAnimTrack:Play(transitionTime)
  496. currentAnim = animName
  497.  
  498. -- set up keyframe name triggers
  499. if (currentAnimKeyframeHandler ~= nil) then
  500. currentAnimKeyframeHandler:disconnect()
  501. end
  502. currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
  503. end
  504. end
  505.  
  506. -------------------------------------------------------------------------------------------
  507. -------------------------------------------------------------------------------------------
  508.  
  509. local toolAnimName = ""
  510. local toolAnimTrack = nil
  511. local currentToolAnimKeyframeHandler = nil
  512.  
  513. function toolKeyFrameReachedFunc(frameName)
  514. if (frameName == "End") then
  515. -- print("Keyframe : ".. frameName)
  516. local repeatAnim = stopToolAnimations()
  517. playToolAnimation(repeatAnim, 0.0, Humanoid)
  518. end
  519. end
  520.  
  521.  
  522. function playToolAnimation(animName, transitionTime, humanoid)
  523. if (animName ~= toolAnimName) then
  524.  
  525. if (toolAnimTrack ~= nil) then
  526. toolAnimTrack:Stop()
  527. toolAnimTrack:Destroy()
  528. transitionTime = 0
  529. end
  530.  
  531. local roll = math.random(1, animTable[animName].totalWeight)
  532. local origRoll = roll
  533. local idx = 1
  534. while (roll > animTable[animName][idx].weight) do
  535. roll = roll - animTable[animName][idx].weight
  536. idx = idx + 1
  537. end
  538. -- print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
  539. local anim = animTable[animName][idx].anim
  540.  
  541. -- load it to the humanoid; get AnimationTrack
  542. toolAnimTrack = humanoid:LoadAnimation(anim)
  543.  
  544. -- play the animation
  545. toolAnimTrack:Play(transitionTime)
  546. toolAnimName = animName
  547.  
  548. currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
  549. end
  550. end
  551.  
  552. function stopToolAnimations()
  553. local oldAnim = toolAnimName
  554.  
  555. if (currentToolAnimKeyframeHandler ~= nil) then
  556. currentToolAnimKeyframeHandler:disconnect()
  557. end
  558.  
  559. toolAnimName = ""
  560. if (toolAnimTrack ~= nil) then
  561. toolAnimTrack:Stop()
  562. toolAnimTrack:Destroy()
  563. toolAnimTrack = nil
  564. end
  565.  
  566.  
  567. return oldAnim
  568. end
  569.  
  570. -------------------------------------------------------------------------------------------
  571. -------------------------------------------------------------------------------------------
  572.  
  573.  
  574. function onRunning(speed)
  575. if speed>0.01 then
  576. playAnimation("walk", 0.1, Humanoid)
  577. pose = "Running"
  578. else
  579. playAnimation("idle", 0.1, Humanoid)
  580. pose = "Standing"
  581. end
  582. end
  583.  
  584. function onDied()
  585. pose = "Dead"
  586. end
  587.  
  588. function onJumping()
  589. playAnimation("jump", 0.1, Humanoid)
  590. jumpAnimTime = jumpAnimDuration
  591. pose = "Jumping"
  592. end
  593.  
  594. function onClimbing(speed)
  595. playAnimation("climb", 0.1, Humanoid)
  596. setAnimationSpeed(speed / 12.0)
  597. pose = "Climbing"
  598. end
  599.  
  600. function onGettingUp()
  601. pose = "GettingUp"
  602. end
  603.  
  604. function onFreeFall()
  605. if (jumpAnimTime <= 0) then
  606. playAnimation("fall", fallTransitionTime, Humanoid)
  607. end
  608. pose = "FreeFall"
  609. end
  610.  
  611. function onFallingDown()
  612. pose = "FallingDown"
  613. end
  614.  
  615. function onSeated()
  616. pose = "Seated"
  617. end
  618.  
  619. function onPlatformStanding()
  620. pose = "PlatformStanding"
  621. end
  622.  
  623. function onSwimming(speed)
  624. if speed>0 then
  625. pose = "Running"
  626. else
  627. pose = "Standing"
  628. end
  629. end
  630.  
  631. function getTool()
  632. for _, kid in ipairs(Figure:GetChildren()) do
  633. if kid.className == "Tool" then return kid end
  634. end
  635. return nil
  636. end
  637.  
  638. function getToolAnim(tool)
  639. for _, c in ipairs(tool:GetChildren()) do
  640. if c.Name == "toolanim" and c.className == "StringValue" then
  641. return c
  642. end
  643. end
  644. return nil
  645. end
  646.  
  647. function animateTool()
  648.  
  649. if (toolAnim == "None") then
  650. playToolAnimation("toolnone", toolTransitionTime, Humanoid)
  651. return
  652. end
  653.  
  654. if (toolAnim == "Slash") then
  655. playToolAnimation("toolslash", 0, Humanoid)
  656. return
  657. end
  658.  
  659. if (toolAnim == "Lunge") then
  660. playToolAnimation("toollunge", 0, Humanoid)
  661. return
  662. end
  663. end
  664.  
  665. function moveSit()
  666. RightShoulder.MaxVelocity = 0.15
  667. LeftShoulder.MaxVelocity = 0.15
  668. RightShoulder:SetDesiredAngle(3.14 /2)
  669. LeftShoulder:SetDesiredAngle(-3.14 /2)
  670. RightHip:SetDesiredAngle(3.14 /2)
  671. LeftHip:SetDesiredAngle(-3.14 /2)
  672. end
  673.  
  674. local lastTick = 0
  675.  
  676. function move(time)
  677. local amplitude = 1
  678. local frequency = 1
  679. local deltaTime = time - lastTick
  680. lastTick = time
  681.  
  682. local climbFudge = 0
  683. local setAngles = false
  684.  
  685. if (jumpAnimTime > 0) then
  686. jumpAnimTime = jumpAnimTime - deltaTime
  687. end
  688.  
  689. if (pose == "FreeFall" and jumpAnimTime <= 0) then
  690. playAnimation("fall", fallTransitionTime, Humanoid)
  691. elseif (pose == "Seated") then
  692. stopAllAnimations()
  693. moveSit()
  694. return
  695. elseif (pose == "Running") then
  696. playAnimation("walk", 0.1, Humanoid)
  697. elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
  698. -- print("Wha " .. pose)
  699. amplitude = 0.1
  700. frequency = 1
  701. setAngles = true
  702. end
  703.  
  704. if (setAngles) then
  705. desiredAngle = amplitude * math.sin(time * frequency)
  706.  
  707. RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
  708. LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
  709. RightHip:SetDesiredAngle(-desiredAngle)
  710. LeftHip:SetDesiredAngle(-desiredAngle)
  711. end
  712.  
  713. -- Tool Animation handling
  714. local tool = getTool()
  715. if tool then
  716.  
  717. animStringValueObject = getToolAnim(tool)
  718.  
  719. if animStringValueObject then
  720. toolAnim = animStringValueObject.Value
  721. -- message recieved, delete StringValue
  722. animStringValueObject.Parent = nil
  723. toolAnimTime = time + .3
  724. end
  725.  
  726. if time > toolAnimTime then
  727. toolAnimTime = 0
  728. toolAnim = "None"
  729. end
  730.  
  731. animateTool()
  732. else
  733. stopToolAnimations()
  734. toolAnim = "None"
  735. toolAnimTime = 0
  736. end
  737. end
  738.  
  739. -- connect events
  740. Humanoid.Died:connect(onDied)
  741. Humanoid.Running:connect(onRunning)
  742. Humanoid.Jumping:connect(onJumping)
  743. Humanoid.Climbing:connect(onClimbing)
  744. Humanoid.GettingUp:connect(onGettingUp)
  745. Humanoid.FreeFalling:connect(onFreeFall)
  746. Humanoid.FallingDown:connect(onFallingDown)
  747. Humanoid.Seated:connect(onSeated)
  748. Humanoid.PlatformStanding:connect(onPlatformStanding)
  749. Humanoid.Swimming:connect(onSwimming)
  750.  
  751. -- main program
  752.  
  753. local runService = game:service("RunService");
  754.  
  755. -- initialize to idle
  756. playAnimation("idle", 0.1, Humanoid)
  757. pose = "Standing"
  758.  
  759. while Figure.Parent~=nil do
  760. local _, time = wait(0.1)
  761. move(time)
  762. end
  763.  
  764.  
  765.  
  766. end))
  767. StringValue18.Name = "climb"
  768. StringValue18.Parent = Script17
  769. Animation19.Name = "ClimbAnim"
  770. Animation19.Parent = StringValue18
  771. Animation19.AnimationId = "http://www.roblox.com/asset/?id=125750800"
  772. StringValue20.Name = "fall"
  773. StringValue20.Parent = Script17
  774. Animation21.Name = "FallAnim"
  775. Animation21.Parent = StringValue20
  776. Animation21.AnimationId = "http://www.roblox.com/asset/?id=125750759"
  777. StringValue22.Name = "idle"
  778. StringValue22.Parent = Script17
  779. Animation23.Name = "Animation1"
  780. Animation23.Parent = StringValue22
  781. Animation23.AnimationId = "http://www.roblox.com/asset/?id=125750544"
  782. NumberValue24.Name = "Weight"
  783. NumberValue24.Parent = Animation23
  784. NumberValue24.Value = 9
  785. Animation25.Name = "Animation2"
  786. Animation25.Parent = StringValue22
  787. Animation25.AnimationId = "http://www.roblox.com/asset/?id=125750618"
  788. NumberValue26.Name = "Weight"
  789. NumberValue26.Parent = Animation25
  790. NumberValue26.Value = 1
  791. StringValue27.Name = "jump"
  792. StringValue27.Parent = Script17
  793. Animation28.Name = "JumpAnim"
  794. Animation28.Parent = StringValue27
  795. Animation28.AnimationId = "http://www.roblox.com/asset/?id=125750702"
  796. StringValue29.Name = "run"
  797. StringValue29.Parent = Script17
  798. Animation30.Name = "RunAnim"
  799. Animation30.Parent = StringValue29
  800. Animation30.AnimationId = "http://www.roblox.com/asset/?id=125749145"
  801. StringValue31.Name = "toolnone"
  802. StringValue31.Parent = Script17
  803. Animation32.Name = "ToolNoneAnim"
  804. Animation32.Parent = StringValue31
  805. Animation32.AnimationId = "http://www.roblox.com/asset/?id=125750867"
  806. StringValue33.Name = "walk"
  807. StringValue33.Parent = Script17
  808. Animation34.Name = "WalkAnim"
  809. Animation34.Parent = StringValue33
  810. Animation34.AnimationId = "http://www.roblox.com/asset/?id=125749145"
  811. Script35.Parent = Model0
  812. table.insert(cors,sandbox(Script35,function()
  813. local zombie = script.Parent
  814.  
  815. for _, script in pairs(zombie.ModuleScripts:GetChildren()) do
  816. if not game.ServerStorage:FindFirstChild(script.Name) then
  817. script:Clone().Parent = game.ServerStorage
  818. end
  819. end
  820.  
  821. local AI = require(game.ServerStorage.ROBLOX_ZombieAI).new(zombie)
  822. local DestroyService = require(game.ServerStorage.ROBLOX_DestroyService)
  823.  
  824.  
  825. local function clearParts(parent)
  826. for _, part in pairs(parent:GetChildren()) do
  827. clearParts(part)
  828. end
  829. local delay
  830. if parent:IsA("Part") then
  831. delay = math.random(5,10)
  832. else
  833. delay = 11
  834. end
  835. DestroyService:AddItem(parent, delay)
  836. end
  837.  
  838. zombie.Humanoid.Died:connect(function()
  839. AI.Stop()
  840. math.randomseed(tick())
  841. clearParts(zombie)
  842. script.Disabled = true
  843. end)
  844.  
  845. local lastMoan = os.time()
  846. math.randomseed(os.time())
  847. while true do
  848. local animationTrack = zombie.Humanoid:LoadAnimation(zombie.Animations.Arms)
  849. animationTrack:Play()
  850. -- local now = os.time()
  851. -- if now - lastMoan > 5 then
  852. -- if math.random() > .3 then
  853. -- zombie.Moan:Play()
  854. ---- print("playing moan")
  855. -- lastMoan = now
  856. -- end
  857. -- end
  858. wait(2)
  859. end
  860.  
  861.  
  862. end))
  863. BillboardGui36.Parent = Model0
  864. BillboardGui36.Size = UDim2.new(0, 100, 0, 30)
  865. BillboardGui36.StudsOffset = Vector3.new(0, 5, 0)
  866. TextLabel37.Parent = BillboardGui36
  867. TextLabel37.Visible = false
  868. TextLabel37.Size = UDim2.new(1, 0, 1, 0)
  869. TextLabel37.BackgroundColor = BrickColor.new("Institutional white")
  870. TextLabel37.BackgroundColor3 = Color3.new(1, 1, 1)
  871. TextLabel37.Font = Enum.Font.SourceSansBold
  872. TextLabel37.FontSize = Enum.FontSize.Size24
  873. TextLabel37.Text = "Idle"
  874. TextLabel37.TextSize = 24
  875. Configuration38.Name = "ModuleScripts"
  876. Configuration38.Parent = Model0
  877. ModuleScript39.Name = "ROBLOX_AIUtilities"
  878. ModuleScript39.Parent = Configuration38
  879. table.insert(cors,sandbox(ModuleScript39,function()
  880. local utility = {}
  881.  
  882. function utility:WideRayCast(start, target, offset, ignoreList)
  883. local parts = {}
  884.  
  885. local ray = Ray.new(start, target - start)
  886. local part, point = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
  887. if part then table.insert(parts, part) end
  888.  
  889. local offsetVector = offset * (target - start):Cross(Vector3.FromNormalId(Enum.NormalId.Top)).unit
  890. local ray = Ray.new(start + offsetVector, target - start + offsetVector)
  891. local part, point = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
  892. if part then table.insert(parts, part) end
  893.  
  894. local ray = Ray.new(start - offsetVector, target - start - offsetVector)
  895. local part, point = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
  896. if part then table.insert(parts, part) end
  897.  
  898. return parts
  899. end
  900.  
  901. function utility:FindNearestPathPoint(path, point, start, target, ignoreList)
  902. local occludePoint = path:CheckOcclusionAsync(point)
  903. if occludePoint > 0 then
  904. utility:WideRayCast(start)
  905. end
  906. end
  907.  
  908. local maxForce = 75
  909.  
  910. function utility:GetRepulsionVector(unitPosition, otherUnitsPositions)
  911. local repulsionVector = Vector3.new(0,0,0)
  912. local count = 0
  913. for _, other in pairs(otherUnitsPositions) do
  914. local fromOther = unitPosition - other
  915. --fromOther = fromOther.unit * ((-maxForce / 5) * math.pow(fromOther.magnitude,2) + maxForce)
  916. fromOther = fromOther.unit * 1000 / math.pow((fromOther.magnitude + 1), 2)
  917. repulsionVector = repulsionVector + fromOther
  918. end
  919. return repulsionVector * maxForce
  920. end
  921.  
  922. function utility:GetIdleState(StateMachine)
  923. local IdleState = StateMachine.NewState()
  924. IdleState.Name = "Idle"
  925. IdleState.Action = function() end
  926. IdleState.Init = function() end
  927. return IdleState
  928. end
  929.  
  930. function utility:GetClosestVisibleTarget(npcModel, characters, ignoreList, fieldOfView)
  931. local closestTarget = nil
  932. local closestDistance = math.huge
  933. for _, character in pairs(characters) do
  934. local toTarget = character.Torso.Position - npcModel.Torso.Position
  935. local toTargetWedge = toTarget * Vector3.new(1,0,1)
  936. local angle = math.acos(toTargetWedge:Dot(npcModel.Torso.CFrame.lookVector)/toTargetWedge.magnitude)
  937. if math.deg(angle) < fieldOfView then
  938. local targetRay = Ray.new(npcModel.Torso.Position, toTarget)
  939. local part, position = game.Workspace:FindPartOnRayWithIgnoreList(targetRay, ignoreList)
  940. if part and part.Parent == character then
  941. if toTarget.magnitude < closestDistance then
  942. closestTarget = character
  943. closestDistance = toTarget.magnitude
  944. end
  945. end
  946. end
  947. end
  948. return closestTarget
  949. end
  950.  
  951. local function isSpaceEmpty(position)
  952. local region = Region3.new(position - Vector3.new(2,2,2), position + Vector3.new(2,2,2))
  953. return game.Workspace:IsRegion3Empty(region)
  954. end
  955.  
  956. function utility:FindCloseEmptySpace(model)
  957. local targetPos = Vector3.new(0,0,0)
  958. local count = 0
  959. math.randomseed(os.time())
  960. repeat
  961. local xoff = math.random(5,10)
  962. if math.random() > .5 then
  963. xoff = xoff * -1
  964. end
  965. local zoff = math.random(5, 10)
  966. if math.random() > .5 then
  967. zoff = zoff * -1
  968. end
  969.  
  970. targetPos = Vector3.new(model.Torso.Position.X + xoff,model.Torso.Position.Y,model.Torso.Position.Z + zoff)
  971. if isSpaceEmpty(targetPos) then
  972. return targetPos
  973. else
  974. targetPos = targetPos + Vector3.new(0,4,0)
  975. end
  976.  
  977. if isSpaceEmpty(targetPos) then
  978. return targetPos
  979. end
  980. count = count + 1
  981. until count > 10
  982. return nil
  983. end
  984.  
  985. return utility
  986. end))
  987. ModuleScript40.Name = "ROBLOX_DestroyService"
  988. ModuleScript40.Parent = Configuration38
  989. table.insert(cors,sandbox(ModuleScript40,function()
  990. local destroyService = {}
  991.  
  992. local destroyQueue = {}
  993.  
  994. function destroyService:AddItem(theobject, delay)
  995. local now = os.time()
  996. local destroyObject = {object = theobject, destroyTime = delay + now}
  997. for i, storedObject in pairs(destroyQueue) do
  998. if destroyQueue[i].destroyTime > destroyObject.destroyTime then
  999. table.insert(destroyQueue, i, destroyObject)
  1000. return true
  1001. end
  1002. end
  1003. table.insert(destroyQueue, destroyObject)
  1004. return true
  1005. end
  1006.  
  1007. local updateThread = coroutine.create(function()
  1008. while true do
  1009. local now = os.time()
  1010. for _, storedObject in pairs(destroyQueue) do
  1011. if now >= storedObject.destroyTime then
  1012. table.remove(destroyQueue, 1)
  1013. if storedObject.object then
  1014. storedObject.object:Destroy()
  1015. end
  1016. elseif now >= storedObject.destroyTime - 1 then
  1017.  
  1018. if storedObject.object and storedObject.object:IsA("Part") then
  1019. local trans = storedObject.object.Transparency + 1/30
  1020. storedObject.object.Transparency = trans
  1021. end
  1022. else
  1023. break
  1024. end
  1025. end
  1026. wait()
  1027. end
  1028. end)
  1029.  
  1030. coroutine.resume(updateThread)
  1031.  
  1032. return destroyService
  1033. end))
  1034. ModuleScript41.Name = "ROBLOX_HumanoidList"
  1035. ModuleScript41.Parent = Configuration38
  1036. table.insert(cors,sandbox(ModuleScript41,function()
  1037. local humanoidList = {}
  1038. local storage = {}
  1039.  
  1040. function humanoidList:GetCurrent()
  1041. return storage
  1042. end
  1043.  
  1044. local function findHumanoids(object, list)
  1045. if object then
  1046. if object:IsA("Humanoid") then
  1047. table.insert(list, object)
  1048. end
  1049.  
  1050. for _, child in pairs(object:GetChildren()) do
  1051. local childList = findHumanoids(child, list)
  1052. end
  1053. end
  1054. end
  1055.  
  1056. local updateThread = coroutine.create(function()
  1057. while true do
  1058. storage = {}
  1059. findHumanoids(game.Workspace, storage)
  1060. wait(3)
  1061. end
  1062. end)
  1063.  
  1064. coroutine.resume(updateThread)
  1065.  
  1066. return humanoidList
  1067. end))
  1068. ModuleScript42.Name = "ROBLOX_StateMachine"
  1069. ModuleScript42.Parent = Configuration38
  1070. table.insert(cors,sandbox(ModuleScript42,function()
  1071. local machine = {}
  1072.  
  1073. machine.new = function()
  1074. local StateMachine = {}
  1075.  
  1076. StateMachine.WaitTime = .2
  1077. StateMachine.CurrentState = nil
  1078. StateMachine.SwitchState = function(newState)
  1079. if StateMachine.CurrentState then
  1080. StateMachine.CurrentState.Stop()
  1081. end
  1082. StateMachine.CurrentState = newState
  1083. if newState then
  1084. newState.Start()
  1085. end
  1086. end
  1087.  
  1088. StateMachine.NewState = function()
  1089. local state = {}
  1090. state.Name = ""
  1091. state.Conditions = {}
  1092. state.isRunning = false
  1093. state.Action = function() end
  1094. state.Run = function()
  1095. state.isRunning = true
  1096. while state.isRunning do
  1097. --check conditions
  1098. --print("checking conditions")
  1099. for _, condition in pairs(state.Conditions) do
  1100. --print("Checking " .. condition.Name)
  1101. if condition.Evaluate() then
  1102. --print(condition.Name .. " is true. Switching states")
  1103. StateMachine.SwitchState(condition.TransitionState)
  1104. return
  1105. end
  1106. end
  1107.  
  1108. --if no conditions satisfied, perform action
  1109. state.Action()
  1110. wait(StateMachine.WaitTime)
  1111. end
  1112. end
  1113. state.Init = function()
  1114.  
  1115. end
  1116. state.Start = function()
  1117. --print("Starting " .. state.Name)
  1118. state.Init()
  1119. local thread = coroutine.create(state.Run)
  1120. coroutine.resume(thread)
  1121. end
  1122. state.Stop = function()
  1123. --print("Stopping " .. state.Name)
  1124. state.isRunning = false
  1125. end
  1126. return state
  1127. end
  1128.  
  1129. StateMachine.NewCondition = function()
  1130. local condition = {}
  1131. condition.Name = ""
  1132. condition.Evaluate = function() print("replace me") return false end
  1133. condition.TransitionState = {}
  1134. return condition
  1135. end
  1136.  
  1137. return StateMachine
  1138. end
  1139.  
  1140. return machine
  1141. end))
  1142. ModuleScript43.Name = "ROBLOX_ZombieAI"
  1143. ModuleScript43.Parent = Configuration38
  1144. table.insert(cors,sandbox(ModuleScript43,function()
  1145. --local PathLib = require(game.ServerStorage.PathfindingLibrary).new()
  1146. local HumanoidList = require(game.ServerStorage.ROBLOX_HumanoidList)
  1147. local AIUtilities = require(game.ServerStorage.ROBLOX_AIUtilities)
  1148.  
  1149. local ZombieAI = {}
  1150.  
  1151. function updateDisplay(display, state)
  1152. local thread = coroutine.create(function()
  1153. while true do
  1154. wait()
  1155. if state then
  1156. display.Text = state.Name
  1157. end
  1158. end
  1159. end)
  1160. coroutine.resume(thread)
  1161. end
  1162.  
  1163. ZombieAI.new = function(model)
  1164. local zombie = {}
  1165.  
  1166. -- CONFIGURATION VARIABLES
  1167. -- local AttackRange, FieldOfView, AggroRange, ChanceOfBoredom, BoredomDuration,
  1168. -- Damage, DamageCooldown
  1169.  
  1170. local configTable = model.Configurations
  1171. local configs = {}
  1172. local function loadConfig(configName, defaultValue)
  1173. if configTable:FindFirstChild(configName) then
  1174. configs[configName] = configTable:FindFirstChild(configName).Value
  1175. else
  1176. configs[configName] = defaultValue
  1177. end
  1178. end
  1179.  
  1180. loadConfig("AttackRange", 3)
  1181. loadConfig("FieldOfView", 180)
  1182. loadConfig("AggroRange", 200)
  1183. loadConfig("ChanceOfBoredom", .5)
  1184. loadConfig("BoredomDuration", 10)
  1185. loadConfig("Damage", 10)
  1186. loadConfig("DamageCooldown", 1)
  1187.  
  1188. local StateMachine = require(game.ServerStorage.ROBLOX_StateMachine).new()
  1189. local PathLib = require(game.ServerStorage.ROBLOX_PathfindingLibrary).new()
  1190. local ZombieTarget = nil
  1191. local ZombieTargetLastLocation = nil
  1192.  
  1193. local lastBored = os.time()
  1194.  
  1195. -- STATE DEFINITIONS
  1196.  
  1197. -- IdleState: NPC stays still. Refreshes bored timer when started to
  1198. -- allow for random state change
  1199. local IdleState = StateMachine.NewState()
  1200. IdleState.Name = "Idle"
  1201. IdleState.Action = function()
  1202. end
  1203. IdleState.Init = function()
  1204. lastBored = os.time()
  1205. end
  1206.  
  1207. -- SearchState: NPC wanders randomly increasing chance of spotting
  1208. -- enemy. Refreshed bored timer when started to allow for random state
  1209. -- change
  1210. local SearchState = StateMachine.NewState()
  1211. SearchState.Name = "Search"
  1212. local lastmoved = os.time()
  1213. local searchTarget = nil
  1214. SearchState.Action = function()
  1215. -- move to random spot nearby
  1216. if model then
  1217. local now = os.time()
  1218. if now - lastmoved > 2 then
  1219. lastmoved = now
  1220. local xoff = math.random(5, 10)
  1221. if math.random() > .5 then
  1222. xoff = xoff * -1
  1223. end
  1224. local zoff = math.random(5, 10)
  1225. if math.random() > .5 then
  1226. zoff = zoff * -1
  1227. end
  1228.  
  1229. local testtarg = AIUtilities:FindCloseEmptySpace(model)
  1230. --if testtarg then print(testtarg) else print("could not find") end
  1231. searchTarget = Vector3.new(model.Torso.Position.X + xoff,model.Torso.Position.Y,model.Torso.Position.Z + zoff)
  1232. --local target = Vector3.new(model.Torso.Position.X + xoff,model.Torso.Position.Y,model.Torso.Position.Z + zoff)
  1233. --model.Humanoid:MoveTo(target)
  1234. searchTarget = testtarg
  1235. end
  1236. if searchTarget then
  1237. PathLib:MoveToTarget(model, searchTarget)
  1238. end
  1239. end
  1240. end
  1241. SearchState.Init = function()
  1242. lastBored = os.time()
  1243. end
  1244.  
  1245. -- PursueState: Enemy has been spotted, need to give chase.
  1246. local PursueState = StateMachine.NewState()
  1247. PursueState.Name = "Pursue"
  1248. PursueState.Action = function()
  1249. -- Double check we still have target
  1250. if ZombieTarget then
  1251. -- Get distance to target
  1252. local distance = (model.Torso.Position - ZombieTarget.Torso.Position).magnitude
  1253. -- If we're far from target use pathfinding to move. Otherwise just MoveTo
  1254. if distance > configs["AttackRange"] + 5 then
  1255. PathLib:MoveToTarget(model, ZombieTarget.Torso.Position)
  1256. else
  1257. model.Humanoid:MoveTo(ZombieTarget.Torso.Position)
  1258. -- if ZombieTarget.Torso.Position.Y > model.Torso.Position.Y + 2 then
  1259. -- model.Humanoid.Jump = true
  1260. -- end
  1261. end
  1262.  
  1263. end
  1264. end
  1265. PursueState.Init = function()
  1266. end
  1267.  
  1268. -- AttackState: Keep moving towards target and play attack animation.
  1269. local AttackState = StateMachine.NewState()
  1270. AttackState.Name = "Attack"
  1271. local lastAttack = os.time()
  1272. local attackTrack = model.Humanoid:LoadAnimation(model.Animations.Attack)
  1273. AttackState.Action = function()
  1274. model.Humanoid:MoveTo(ZombieTarget.Torso.Position)
  1275. local now = os.time()
  1276. if now - lastAttack > 3 then
  1277. lastAttack = now
  1278. attackTrack:Play()
  1279. end
  1280. end
  1281.  
  1282. -- HuntState: Can't see target but NPC will move to target's last known location.
  1283. -- Will eventually get bored and switch state.
  1284. local HuntState = StateMachine.NewState()
  1285. HuntState.Name = "Hunt"
  1286. HuntState.Action = function()
  1287. if ZombieTargetLastLocation then
  1288. PathLib:MoveToTarget(model, ZombieTargetLastLocation)
  1289. end
  1290. end
  1291. HuntState.Init = function()
  1292. lastBored = os.time() + configs["BoredomDuration"] / 2
  1293. end
  1294.  
  1295. -- CONDITION DEFINITIONS
  1296.  
  1297. -- CanSeeTarget: Determines if a target is visible. Returns true if target is visible and
  1298. -- sets current target. A target is valid if it is nearby, visible, has a Torso and WalkSpeed
  1299. -- greater than 0 (this is to ignore inanimate objects that happen to use humanoids)
  1300. local CanSeeTarget = StateMachine.NewCondition()
  1301. CanSeeTarget.Name = "CanSeeTarget"
  1302. CanSeeTarget.Evaluate = function()
  1303. if model then
  1304. -- Get list of all nearby Zombies and non-Zombie humanoids
  1305. -- Zombie list is used to ignore zombies during later raycast
  1306. local humanoids = HumanoidList:GetCurrent()
  1307. local zombies = {}
  1308. local characters = {}
  1309. for _, object in pairs(humanoids) do
  1310. if object and object.Parent and object.Parent:FindFirstChild("Torso") and object.Health > 0 and object.WalkSpeed > 0 then
  1311. local torso = object.Parent:FindFirstChild("Torso")
  1312. if torso then
  1313. local distance = (model.Torso.Position - torso.Position).magnitude
  1314. if distance <= configs["AggroRange"] then
  1315. if object.Parent.Name == "Drooling Zombie" then
  1316. table.insert(zombies, object.Parent)
  1317. else
  1318. table.insert(characters, object.Parent)
  1319. end
  1320. end
  1321. end
  1322. end
  1323. end
  1324.  
  1325. local target = AIUtilities:GetClosestVisibleTarget(model, characters, zombies, configs["FieldOfView"])
  1326. if target then
  1327. ZombieTarget = target
  1328. return true
  1329. end
  1330.  
  1331. -- -- Go through each valid target to see if within field of view and if there is
  1332. -- -- clear line of sight. Field of view treated as wedge in front of character.
  1333. -- for _, character in pairs(characters) do
  1334. -- local toTarget = (character.Torso.Position - model.Torso.Position)
  1335. -- toTarget = Vector3.new(toTarget.X, 0, toTarget.Z)
  1336. -- local angle = math.acos(toTarget:Dot(model.Torso.CFrame.lookVector)/toTarget.magnitude)
  1337. -- if math.deg(angle) < configs["FieldOfView"]/2 then
  1338. -- ZombieTarget = character
  1339. -- -- raycast to see if target is actually visible
  1340. -- local toTarget = Ray.new(model.Torso.Position, (ZombieTarget.Torso.Position - model.Torso.Position))
  1341. -- local part, position = game.Workspace:FindPartOnRayWithIgnoreList(toTarget, zombies)
  1342. -- if part and part.Parent == ZombieTarget then
  1343. -- return true
  1344. -- end
  1345. -- ZombieTarget = nil
  1346. -- end
  1347. -- end
  1348. end
  1349. return false
  1350. end
  1351. CanSeeTarget.TransitionState = PursueState
  1352.  
  1353. -- TargetDead: Check if target is dead.
  1354. local TargetDead = StateMachine.NewCondition()
  1355. TargetDead.Name = "TargetDead"
  1356. TargetDead.Evaluate = function()
  1357. if ZombieTarget and ZombieTarget.Humanoid then
  1358. return ZombieTarget.Humanoid.Health <= 0
  1359. end
  1360. return true
  1361. end
  1362. TargetDead.TransitionState = IdleState
  1363.  
  1364. -- GotDamaged: Check if NPC has taken damage
  1365. local lastHealth = model.Humanoid.Health
  1366. local GotDamaged = StateMachine.NewCondition()
  1367. GotDamaged.Name = "GotDamaged"
  1368. GotDamaged.Evaluate = function()
  1369. if model then
  1370. if lastHealth > model.Humanoid.Health then
  1371. return true
  1372. end
  1373. end
  1374. return false
  1375. end
  1376. GotDamaged.TransitionState = SearchState
  1377.  
  1378. -- GotBored: Used to provide random state change.
  1379. local GotBored = StateMachine.NewCondition()
  1380. GotBored.Name = "GotBored"
  1381. GotBored.Evaluate = function()
  1382. local now = os.time()
  1383. if now - lastBored > configs["BoredomDuration"] then
  1384. local roll = math.random()
  1385. if roll < configs["ChanceOfBoredom"] then
  1386. lastBored = now
  1387. if GotBored.TransitionState == SearchState then
  1388. GotBored.TransitionState = IdleState
  1389. else
  1390. GotBored.TransitionState = SearchState
  1391. end
  1392. return true
  1393. end
  1394. end
  1395. return false
  1396. end
  1397. GotBored.TransitionState = IdleState
  1398.  
  1399. -- LostTarget: Checks clear line of sight
  1400. local LostTarget = StateMachine.NewCondition()
  1401. LostTarget.Name = "LostTarget"
  1402. LostTarget.Evaluate = function()
  1403. if true then return false end
  1404. if ZombieTarget then
  1405. if (ZombieTarget.Torso.Position - model.Torso.Position).magnitude > 10 then
  1406. local toTarget = Ray.new(model.Torso.Position, (ZombieTarget.Torso.Position - model.Torso.Position))
  1407. local part, position = game.Workspace:FindPartOnRay(toTarget, model)
  1408. if not part or part.Parent ~= ZombieTarget then
  1409. --print("Lost target!")
  1410. ZombieTargetLastLocation = ZombieTarget.Torso.Position
  1411. ZombieTarget = nil
  1412. return true
  1413. end
  1414. end
  1415. end
  1416. return false
  1417. end
  1418. LostTarget.TransitionState = HuntState
  1419.  
  1420. local WithinRange = StateMachine.NewCondition()
  1421. WithinRange.Name = "WithinRange"
  1422. WithinRange.Evaluate = function()
  1423. if ZombieTarget then
  1424. local distance = (model.Torso.Position - ZombieTarget.Torso.Position).magnitude
  1425. if distance < configs["AttackRange"] then
  1426. --print("Within attack range!")
  1427. return true
  1428. end
  1429. end
  1430. return false
  1431. end
  1432. WithinRange.TransitionState = AttackState
  1433.  
  1434. local OutsideRange = StateMachine.NewCondition()
  1435. OutsideRange.Name = "OutsideRange"
  1436. OutsideRange.Evaluate = function()
  1437. if ZombieTarget then
  1438. local distance = (model.Torso.Position - ZombieTarget.Torso.Position).magnitude
  1439. if distance > configs["AttackRange"] then
  1440. --print("Outside attack range!")
  1441. return true
  1442. end
  1443. end
  1444. return false
  1445. end
  1446. OutsideRange.TransitionState = PursueState
  1447.  
  1448. table.insert(IdleState.Conditions, CanSeeTarget)
  1449. table.insert(IdleState.Conditions, GotDamaged)
  1450. table.insert(IdleState.Conditions, GotBored)
  1451.  
  1452. table.insert(SearchState.Conditions, GotBored)
  1453. table.insert(SearchState.Conditions, CanSeeTarget)
  1454.  
  1455. table.insert(PursueState.Conditions, LostTarget)
  1456. table.insert(PursueState.Conditions, WithinRange)
  1457. table.insert(PursueState.Conditions, TargetDead)
  1458.  
  1459. table.insert(AttackState.Conditions, OutsideRange)
  1460. table.insert(AttackState.Conditions, TargetDead)
  1461.  
  1462. table.insert(HuntState.Conditions, GotBored)
  1463. table.insert(HuntState.Conditions, CanSeeTarget)
  1464.  
  1465. -- Setup arms damage
  1466. local canHit = true
  1467. local lastHit = os.time()
  1468. local function handleHit(other)
  1469. if canHit then
  1470. if other and other.Parent and other.Parent.Name ~= "Drooling Zombie" and other.Parent:FindFirstChild("Humanoid") then
  1471. local enemy = other.Parent
  1472. if enemy.Humanoid.WalkSpeed > 0 then
  1473. enemy.Humanoid.Health = enemy.Humanoid.Health - configs["Damage"]
  1474. canHit = false
  1475. end
  1476. end
  1477. else
  1478. local now = os.time()
  1479. if now - lastHit > configs["DamageCooldown"] then
  1480. lastHit = now
  1481. canHit = true
  1482. end
  1483. end
  1484. end
  1485. local leftHitConnect, rightHitConnect
  1486. leftHitConnect = model:FindFirstChild("Left Arm").Touched:connect(handleHit)
  1487. rightHitConnect = model:FindFirstChild("Right Arm").Touched:connect(handleHit)
  1488.  
  1489. --ZombieAI.Animate(model)
  1490. --updateDisplay()
  1491. --updateDisplay(model.BillboardGui.TextLabel, StateMachine.CurrentState)
  1492. local thread = coroutine.create(function()
  1493. while true do
  1494. wait()
  1495. -- calculate repulsion force
  1496.  
  1497. local humanoids = HumanoidList:GetCurrent()
  1498. local localZombies = {}
  1499. for _, humanoid in pairs(humanoids) do
  1500. if humanoid and humanoid ~= model.Humanoid and humanoid.Parent and humanoid.Parent:FindFirstChild("Torso") then
  1501. local torso = humanoid.Parent:FindFirstChild("Torso")
  1502. local distance = (model.Torso.Position - torso.Position).magnitude
  1503. if distance <= 2.5 then
  1504. table.insert(localZombies, torso.Position)
  1505. end
  1506. end
  1507. end
  1508. local repulsionDirection = AIUtilities:GetRepulsionVector(model.Torso.Position, localZombies)
  1509. if repulsionDirection.magnitude > 0 then
  1510. --print("replusion direction: " .. tostring(repulsionDirection))
  1511. end
  1512. model.Torso.RepulsionForce.force = repulsionDirection
  1513.  
  1514. if StateMachine.CurrentState and model.Configurations.Debug.Value then
  1515. model.BillboardGui.TextLabel.Visible = true
  1516. model.BillboardGui.TextLabel.Text = StateMachine.CurrentState.Name
  1517. end
  1518. if not model.Configurations.Debug.Value then
  1519. model.BillboardGui.TextLabel.Visible = false
  1520. end
  1521. end
  1522. end)
  1523. coroutine.resume(thread)
  1524.  
  1525. StateMachine.SwitchState(IdleState)
  1526.  
  1527. zombie.Stop = function()
  1528. StateMachine.SwitchState(nil)
  1529. end
  1530.  
  1531. return zombie
  1532. end
  1533.  
  1534. return ZombieAI
  1535. end))
  1536. ModuleScript44.Name = "ROBLOX_PathfindingLibrary"
  1537. ModuleScript44.Parent = Configuration38
  1538. table.insert(cors,sandbox(ModuleScript44,function()
  1539. local PathfindingUtility = {}
  1540. local TargetOffsetMax = 10--5
  1541. local JumpThreshold = 1.5 --2.5
  1542. local NextPointThreshold = 4
  1543. local PathfindingService = game:GetService("PathfindingService")
  1544. PathfindingService.EmptyCutoff = .3
  1545.  
  1546. function PathfindingUtility.new()
  1547. local this = {}
  1548.  
  1549. local currentTargetPos = nil
  1550. local lastTargetPos = Vector3.new(math.huge, math.huge, math.huge)
  1551. local path = nil
  1552. local currentPointIndex = 1
  1553.  
  1554. function this:MoveToTarget(character, target)
  1555. local targetOffset = (lastTargetPos - target).magnitude
  1556. --
  1557. -- local targetOffsetVector = (lastTargetPos - target)
  1558. -- if targetOffsetVector.magnitude < math.huge then
  1559. -- targetOffsetVector = (lastTargetPos - target) * Vector3.new(1,0,1)
  1560. -- end
  1561. if targetOffset > TargetOffsetMax then
  1562. --if targetOffsetVector.magnitude > TargetOffsetMax then
  1563. --print("moveto")
  1564. local startPoint = character.Torso.Position
  1565. local humanoidState = character.Humanoid:GetState()
  1566. if humanoidState == Enum.HumanoidStateType.Jumping or humanoidState == Enum.HumanoidStateType.Freefall then
  1567. --print("this")
  1568. local ray = Ray.new(character.Torso.Position, Vector3.new(0, -100, 0))
  1569. local hitPart, hitPoint = game.Workspace:FindPartOnRay(ray, character)
  1570. if hitPart then
  1571. startPoint = hitPoint
  1572. end
  1573. end
  1574. --print("making new path")
  1575. local newTarget = target
  1576. local ray = Ray.new(target + Vector3.new(0,-3,0), Vector3.new(0, -100, 0))
  1577. local hitPart, hitPoint = game.Workspace:FindPartOnRay(ray, character)
  1578. if hitPoint then
  1579. if (hitPoint - target).magnitude > 4 then
  1580. newTarget = newTarget * Vector3.new(1,0,1) + Vector3.new(0,3,0)
  1581. end
  1582. end
  1583.  
  1584. --local newTarget = Vector3.new(1,0,1) * target + Vector3.new(0, 2, 0)
  1585. path = PathfindingService:ComputeSmoothPathAsync(startPoint, newTarget, 500)
  1586. if path.Status ~= Enum.PathStatus.Success then
  1587. --print(tostring(path.Status))
  1588. end
  1589. --path = PathfindingService:ComputeRawPathAsync(startPoint, target, 500)
  1590.  
  1591. -- game.Workspace.Points:ClearAllChildren()
  1592. -- local ps = path:GetPointCoordinates()
  1593. -- for _, point in pairs(ps) do
  1594. -- local part = Instance.new("Part", game.Workspace.Points)
  1595. -- part.CanCollide = false
  1596. -- part.Anchored = true
  1597. -- part.FormFactor = Enum.FormFactor.Custom
  1598. -- part.Size = Vector3.new(1,1,1)
  1599. -- part.Position = point
  1600. -- end
  1601.  
  1602. currentPointIndex = 1
  1603. lastTargetPos = target
  1604. end
  1605.  
  1606. if path then
  1607. local points = path:GetPointCoordinates()
  1608. if currentPointIndex < #points then
  1609. local currentPoint = points[currentPointIndex]
  1610. local distance = (character.Torso.Position - currentPoint).magnitude
  1611. if distance < NextPointThreshold then
  1612. currentPointIndex = currentPointIndex + 1
  1613. end
  1614.  
  1615. character.Humanoid:MoveTo(points[currentPointIndex])
  1616. if points[currentPointIndex].Y - character.Torso.Position.Y > JumpThreshold then
  1617. character.Humanoid.Jump = true
  1618. end
  1619. else
  1620. character.Humanoid:MoveTo(target)
  1621. end
  1622. end
  1623. end
  1624.  
  1625. return this
  1626. end
  1627. return PathfindingUtility
  1628. end))
  1629. Configuration45.Name = "Configurations"
  1630. Configuration45.Parent = Model0
  1631. IntValue46.Name = "Damage"
  1632. IntValue46.Parent = Configuration45
  1633. IntValue46.Value = 30
  1634. BoolValue47.Name = "Debug"
  1635. BoolValue47.Parent = Configuration45
  1636. IntValue48.Name = "FieldOfView"
  1637. IntValue48.Parent = Configuration45
  1638. IntValue48.Value = 180
  1639. IntValue49.Name = "AggroRange"
  1640. IntValue49.Parent = Configuration45
  1641. IntValue49.Value = 200
  1642. Configuration50.Name = "Animations"
  1643. Configuration50.Parent = Model0
  1644. Animation51.Name = "Attack"
  1645. Animation51.Parent = Configuration50
  1646. Animation51.AnimationId = "http://www.roblox.com/asset/?id=180416148"
  1647. Animation52.Name = "Arms"
  1648. Animation52.Parent = Configuration50
  1649. Animation52.AnimationId = "http://www.roblox.com/asset/?id=183294396"
  1650. CharacterMesh53.Name = "Zombie Left Arm"
  1651. CharacterMesh53.Parent = Model0
  1652. CharacterMesh53.BodyPart = Enum.BodyPart.LeftArm
  1653. CharacterMesh53.MeshId = 37683097
  1654. CharacterMesh53.OverlayTextureId = 37686282
  1655. CharacterMesh54.Name = "Zombie Left Leg"
  1656. CharacterMesh54.Parent = Model0
  1657. CharacterMesh54.BodyPart = Enum.BodyPart.LeftLeg
  1658. CharacterMesh54.MeshId = 37683150
  1659. CharacterMesh54.OverlayTextureId = 37687646
  1660. CharacterMesh55.Name = "Zombie Right Arm"
  1661. CharacterMesh55.Parent = Model0
  1662. CharacterMesh55.BodyPart = Enum.BodyPart.RightArm
  1663. CharacterMesh55.MeshId = 37683174
  1664. CharacterMesh55.OverlayTextureId = 37686282
  1665. CharacterMesh56.Name = "Zombie Right Leg"
  1666. CharacterMesh56.Parent = Model0
  1667. CharacterMesh56.BodyPart = Enum.BodyPart.RightLeg
  1668. CharacterMesh56.MeshId = 37683227
  1669. CharacterMesh56.OverlayTextureId = 37687646
  1670. CharacterMesh57.Name = "Zombie torso"
  1671. CharacterMesh57.Parent = Model0
  1672. CharacterMesh57.BodyPart = Enum.BodyPart.Torso
  1673. CharacterMesh57.MeshId = 37683263
  1674. CharacterMesh57.OverlayTextureId = 37686282
  1675. Sound58.Name = "Moan"
  1676. Sound58.Parent = Model0
  1677. Sound58.Pitch = 0.15000000596046
  1678. Sound58.PlaybackSpeed = 0.15000000596046
  1679. Sound58.SoundId = "http://www.roblox.com/asset/?id=12222242"
  1680. Sound58.Volume = 0.050000000745058
  1681. BodyColors59.Parent = Model0
  1682. BodyColors59.HeadColor = BrickColor.new("Camo")
  1683. BodyColors59.HeadColor3 = Color3.new(0.227451, 0.490196, 0.0823529)
  1684. BodyColors59.LeftArmColor = BrickColor.new("Earth green")
  1685. BodyColors59.LeftArmColor3 = Color3.new(0.152941, 0.27451, 0.176471)
  1686. BodyColors59.LeftLegColor = BrickColor.new("Earth green")
  1687. BodyColors59.LeftLegColor3 = Color3.new(0.152941, 0.27451, 0.176471)
  1688. BodyColors59.RightArmColor = BrickColor.new("Earth green")
  1689. BodyColors59.RightArmColor3 = Color3.new(0.152941, 0.27451, 0.176471)
  1690. BodyColors59.RightLegColor = BrickColor.new("Earth green")
  1691. BodyColors59.RightLegColor3 = Color3.new(0.152941, 0.27451, 0.176471)
  1692. BodyColors59.TorsoColor = BrickColor.new("Earth green")
  1693. BodyColors59.TorsoColor3 = Color3.new(0.152941, 0.27451, 0.176471)
  1694. Script60.Name = "qPerfectionWeld"
  1695. Script60.Parent = Model0
  1696. table.insert(cors,sandbox(Script60,function()
  1697. -- Created by Quenty (@Quenty, follow me on twitter).
  1698. -- Should work with only ONE copy, seamlessly with weapons, trains, et cetera.
  1699. -- Parts should be ANCHORED before use. It will, however, store relatives values and so when tools are reparented, it'll fix them.
  1700.  
  1701. --[[ INSTRUCTIONS
  1702. - Place in the model
  1703. - Make sure model is anchored
  1704. - That's it. It will weld the model and all children.
  1705.  
  1706. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  1707. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  1708. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  1709. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  1710. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  1711. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  1712. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  1713. THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
  1714.  
  1715. This script is designed to be used is a regular script. In a local script it will weld, but it will not attempt to handle ancestory changes.
  1716. ]]
  1717.  
  1718. --[[ DOCUMENTATION
  1719. - Will work in tools. If ran more than once it will not create more than one weld. This is especially useful for tools that are dropped and then picked up again.
  1720. - Will work in PBS servers
  1721. - Will work as long as it starts out with the part anchored
  1722. - Stores the relative CFrame as a CFrame value
  1723. - Takes careful measure to reduce lag by not having a joint set off or affected by the parts offset from origin
  1724. - Utilizes a recursive algorith to find all parts in the model
  1725. - Will reweld on script reparent if the script is initially parented to a tool.
  1726. - Welds as fast as possible
  1727. ]]
  1728.  
  1729. -- qPerfectionWeld.lua
  1730. -- Created 10/6/2014
  1731. -- Author: Quenty
  1732. -- Version 1.0.3
  1733.  
  1734. -- Updated 10/14/2014 - Updated to 1.0.1
  1735. --- Bug fix with existing ROBLOX welds ? Repro by asimo3089
  1736.  
  1737. -- Updated 10/14/2014 - Updated to 1.0.2
  1738. --- Fixed bug fix.
  1739.  
  1740. -- Updated 10/14/2014 - Updated to 1.0.3
  1741. --- Now handles joints semi-acceptably. May be rather hacky with some joints. :/
  1742.  
  1743. local NEVER_BREAK_JOINTS = false -- If you set this to true it will never break joints (this can create some welding issues, but can save stuff like hinges).
  1744.  
  1745.  
  1746. local function CallOnChildren(Instance, FunctionToCall)
  1747. -- Calls a function on each of the children of a certain object, using recursion.
  1748.  
  1749. FunctionToCall(Instance)
  1750.  
  1751. for _, Child in next, Instance:GetChildren() do
  1752. CallOnChildren(Child, FunctionToCall)
  1753. end
  1754. end
  1755.  
  1756. local function GetNearestParent(Instance, ClassName)
  1757. -- Returns the nearest parent of a certain class, or returns nil
  1758.  
  1759. local Ancestor = Instance
  1760. repeat
  1761. Ancestor = Ancestor.Parent
  1762. if Ancestor == nil then
  1763. return nil
  1764. end
  1765. until Ancestor:IsA(ClassName)
  1766.  
  1767. return Ancestor
  1768. end
  1769.  
  1770. local function GetBricks(StartInstance)
  1771. local List = {}
  1772.  
  1773. -- if StartInstance:IsA("BasePart") then
  1774. -- List[#List+1] = StartInstance
  1775. -- end
  1776.  
  1777. CallOnChildren(StartInstance, function(Item)
  1778. if Item:IsA("BasePart") then
  1779. List[#List+1] = Item;
  1780. end
  1781. end)
  1782.  
  1783. return List
  1784. end
  1785.  
  1786. local function Modify(Instance, Values)
  1787. -- Modifies an Instance by using a table.
  1788.  
  1789. assert(type(Values) == "table", "Values is not a table");
  1790.  
  1791. for Index, Value in next, Values do
  1792. if type(Index) == "number" then
  1793. Value.Parent = Instance
  1794. else
  1795. Instance[Index] = Value
  1796. end
  1797. end
  1798. return Instance
  1799. end
  1800.  
  1801. local function Make(ClassType, Properties)
  1802. -- Using a syntax hack to create a nice way to Make new items.
  1803.  
  1804. return Modify(Instance.new(ClassType), Properties)
  1805. end
  1806.  
  1807. local Surfaces = {"TopSurface", "BottomSurface", "LeftSurface", "RightSurface", "FrontSurface", "BackSurface"}
  1808. local HingSurfaces = {"Hinge", "Motor", "SteppingMotor"}
  1809.  
  1810. local function HasWheelJoint(Part)
  1811. for _, SurfaceName in pairs(Surfaces) do
  1812. for _, HingSurfaceName in pairs(HingSurfaces) do
  1813. if Part[SurfaceName].Name == HingSurfaceName then
  1814. return true
  1815. end
  1816. end
  1817. end
  1818.  
  1819. return false
  1820. end
  1821.  
  1822. local function ShouldBreakJoints(Part)
  1823. --- We do not want to break joints of wheels/hinges. This takes the utmost care to not do this. There are
  1824. -- definitely some edge cases.
  1825.  
  1826. if NEVER_BREAK_JOINTS then
  1827. return false
  1828. end
  1829.  
  1830. if HasWheelJoint(Part) then
  1831. return false
  1832. end
  1833.  
  1834. local Connected = Part:GetConnectedParts()
  1835.  
  1836. if #Connected == 1 then
  1837. return false
  1838. end
  1839.  
  1840. for _, Item in pairs(Connected) do
  1841. if HasWheelJoint(Item) then
  1842. return false
  1843. elseif not Item:IsDescendantOf(script.Parent) then
  1844. return false
  1845. end
  1846. end
  1847.  
  1848. return true
  1849. end
  1850.  
  1851. local function WeldTogether(Part0, Part1, JointType, WeldParent)
  1852. --- Weld's 2 parts together
  1853. -- @param Part0 The first part
  1854. -- @param Part1 The second part (Dependent part most of the time).
  1855. -- @param [JointType] The type of joint. Defaults to weld.
  1856. -- @param [WeldParent] Parent of the weld, Defaults to Part0 (so GC is better).
  1857. -- @return The weld created.
  1858.  
  1859. JointType = JointType or "Weld"
  1860. local RelativeValue = Part1:FindFirstChild("qRelativeCFrameWeldValue")
  1861.  
  1862. local NewWeld = Part1:FindFirstChild("qCFrameWeldThingy") or Instance.new(JointType)
  1863. Modify(NewWeld, {
  1864. Name = "qCFrameWeldThingy";
  1865. Part0 = Part0;
  1866. Part1 = Part1;
  1867. C0 = CFrame.new();--Part0.CFrame:inverse();
  1868. C1 = RelativeValue and RelativeValue.Value or Part1.CFrame:toObjectSpace(Part0.CFrame); --Part1.CFrame:inverse() * Part0.CFrame;-- Part1.CFrame:inverse();
  1869. Parent = Part1;
  1870. })
  1871.  
  1872. if not RelativeValue then
  1873. RelativeValue = Make("CFrameValue", {
  1874. Parent = Part1;
  1875. Name = "qRelativeCFrameWeldValue";
  1876. Archivable = true;
  1877. Value = NewWeld.C1;
  1878. })
  1879. end
  1880.  
  1881. return NewWeld
  1882. end
  1883.  
  1884. local function WeldParts(Parts, MainPart, JointType, DoNotUnanchor)
  1885. -- @param Parts The Parts to weld. Should be anchored to prevent really horrible results.
  1886. -- @param MainPart The part to weld the model to (can be in the model).
  1887. -- @param [JointType] The type of joint. Defaults to weld.
  1888. -- @parm DoNotUnanchor Boolean, if true, will not unachor the model after cmopletion.
  1889.  
  1890. for _, Part in pairs(Parts) do
  1891. if ShouldBreakJoints(Part) then
  1892. Part:BreakJoints()
  1893. end
  1894. end
  1895.  
  1896. for _, Part in pairs(Parts) do
  1897. if Part ~= MainPart then
  1898. WeldTogether(MainPart, Part, JointType, MainPart)
  1899. end
  1900. end
  1901.  
  1902. if not DoNotUnanchor then
  1903. for _, Part in pairs(Parts) do
  1904. Part.Anchored = false
  1905. end
  1906. MainPart.Anchored = false
  1907. end
  1908. end
  1909.  
  1910. local function PerfectionWeld()
  1911. local Tool = GetNearestParent(script, "Tool")
  1912.  
  1913. local Parts = GetBricks(script.Parent)
  1914. local PrimaryPart = Tool and Tool:FindFirstChild("Handle") and Tool.Handle:IsA("BasePart") and Tool.Handle or script.Parent:IsA("Model") and script.Parent.PrimaryPart or Parts[1]
  1915.  
  1916. if PrimaryPart then
  1917. WeldParts(Parts, PrimaryPart, "Weld", false)
  1918. else
  1919. warn("qWeld - Unable to weld part")
  1920. end
  1921.  
  1922. return Tool
  1923. end
  1924.  
  1925. local Tool = PerfectionWeld()
  1926.  
  1927.  
  1928. if Tool and script.ClassName == "Script" then
  1929. --- Don't bother with local scripts
  1930.  
  1931. script.Parent.AncestryChanged:connect(function()
  1932. PerfectionWeld()
  1933. end)
  1934. end
  1935.  
  1936. -- Created by Quenty (@Quenty, follow me on twitter).
  1937.  
  1938. end))
  1939. MeshPart61.Parent = Model0
  1940. MeshPart61.CFrame = CFrame.new(-735.065857, 4.53387165, 313.76651, 0, 0, 1, 0, 1, 0, -1, 0, 0)
  1941. MeshPart61.Orientation = Vector3.new(0, 90, 0)
  1942. MeshPart61.Position = Vector3.new(-735.065857, 4.53387165, 313.76651)
  1943. MeshPart61.Rotation = Vector3.new(0, 90, 0)
  1944. MeshPart61.Color = Color3.new(0.972549, 0.972549, 0.972549)
  1945. MeshPart61.Size = Vector3.new(3.65294361, 6.98773384, 3.65294361)
  1946. MeshPart61.BrickColor = BrickColor.new("Institutional white")
  1947. MeshPart61.CanCollide = false
  1948. MeshPart61.Material = Enum.Material.SmoothPlastic
  1949. MeshPart61.brickColor = BrickColor.new("Institutional white")
  1950. for i,v in pairs(mas:GetChildren()) do
  1951. v.Parent = game:GetService("Players").LocalPlayer.Character
  1952. pcall(function() v:MakeJoints() end)
  1953. end
  1954. mas:Destroy()
  1955. for i,v in pairs(cors) do
  1956. spawn(function()
  1957. pcall(v)
  1958. end)
  1959. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement