Advertisement
spacemonkey3591

Untitled

Jul 8th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.42 KB | None | 0 0
  1.  
  2. local runDummyScript = function(f,scri)
  3. local oldenv = getfenv(f)
  4. local newenv = setmetatable({}, {
  5. __index = function(_, k)
  6. if k:lower() == 'script' then
  7. return scri
  8. else
  9. return oldenv[k]
  10. end
  11. end
  12. })
  13. setfenv(f, newenv)
  14. ypcall(function() f() end)
  15. end
  16. cors = {}
  17. mas = Instance.new("Model",game:GetService("Lighting"))
  18. mas.Name = "CompiledModel"
  19. o1 = Instance.new("Model")
  20. o2 = Instance.new("Part")
  21. o3 = Instance.new("Motor6D")
  22. o4 = Instance.new("Part")
  23. o5 = Instance.new("Motor6D")
  24. o6 = Instance.new("Motor6D")
  25. o7 = Instance.new("Motor6D")
  26. o8 = Instance.new("Motor6D")
  27. o9 = Instance.new("Motor6D")
  28. o10 = Instance.new("Script")
  29. o11 = Instance.new("Part")
  30. o12 = Instance.new("Part")
  31. o13 = Instance.new("Part")
  32. o14 = Instance.new("Part")
  33. o15 = Instance.new("Part")
  34. o16 = Instance.new("Decal")
  35. o17 = Instance.new("SpecialMesh")
  36. o18 = Instance.new("Humanoid")
  37. o19 = Instance.new("Script")
  38. o20 = Instance.new("StringValue")
  39. o21 = Instance.new("Animation")
  40. o22 = Instance.new("StringValue")
  41. o23 = Instance.new("Animation")
  42. o24 = Instance.new("StringValue")
  43. o25 = Instance.new("Animation")
  44. o26 = Instance.new("NumberValue")
  45. o27 = Instance.new("Animation")
  46. o28 = Instance.new("NumberValue")
  47. o29 = Instance.new("StringValue")
  48. o30 = Instance.new("Animation")
  49. o31 = Instance.new("StringValue")
  50. o32 = Instance.new("Animation")
  51. o33 = Instance.new("StringValue")
  52. o34 = Instance.new("Animation")
  53. o35 = Instance.new("StringValue")
  54. o36 = Instance.new("Animation")
  55. o37 = Instance.new("StringValue")
  56. o38 = Instance.new("Animation")
  57. o39 = Instance.new("BindableEvent")
  58. o40 = Instance.new("Script")
  59. o41 = Instance.new("Animation")
  60. o42 = Instance.new("Configuration")
  61. o43 = Instance.new("NumberValue")
  62. o44 = Instance.new("BoolValue")
  63. o45 = Instance.new("BoolValue")
  64. o46 = Instance.new("Vector3Value")
  65. o47 = Instance.new("BoolValue")
  66. o48 = Instance.new("BrickColorValue")
  67. o49 = Instance.new("NumberValue")
  68. o50 = Instance.new("NumberValue")
  69. o51 = Instance.new("NumberValue")
  70. o52 = Instance.new("Configuration")
  71. o53 = Instance.new("ObjectValue")
  72. o54 = Instance.new("BindableEvent")
  73. o55 = Instance.new("BindableFunction")
  74. o56 = Instance.new("BindableEvent")
  75. o1.Name = "PathFinder"
  76. o1.Parent = mas
  77. o2.Name = "HumanoidRootPart"
  78. o2.Parent = o1
  79. o2.BrickColor = BrickColor.new("Light stone grey")
  80. o2.Transparency = 1
  81. o2.Position = Vector3.new(20.7900028, 8.00001526, 3.98998308)
  82. o2.Rotation = Vector3.new(-180, 0, -180)
  83. o2.FormFactor = Enum.FormFactor.Symmetric
  84. o2.Size = Vector3.new(2, 2, 1)
  85. o2.CFrame = CFrame.new(20.7900028, 8.00001526, 3.98998308, -1, 0, 0, 0, 1, 0, 0, 0, -1)
  86. o2.BottomSurface = Enum.SurfaceType.Smooth
  87. o2.TopSurface = Enum.SurfaceType.Smooth
  88. o2.Color = Color3.new(0.898039, 0.894118, 0.87451)
  89. o2.Position = Vector3.new(20.7900028, 8.00001526, 3.98998308)
  90. o2.Orientation = Vector3.new(0, 180, 0)
  91. o2.Color = Color3.new(0.898039, 0.894118, 0.87451)
  92. o3.Name = "Root Hip"
  93. o3.Parent = o2
  94. o3.C0 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  95. o3.C1 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  96. o3.Part0 = o2
  97. o3.Part1 = o4
  98. o3.MaxVelocity = 0.10000000149012
  99. o4.Name = "Torso"
  100. o4.Parent = o1
  101. o4.BrickColor = BrickColor.new("Dark green")
  102. o4.Position = Vector3.new(20.7900028, 8.00001526, 3.98998308)
  103. o4.Rotation = Vector3.new(-180, 0, -180)
  104. o4.FormFactor = Enum.FormFactor.Symmetric
  105. o4.Size = Vector3.new(2, 2, 1)
  106. o4.CFrame = CFrame.new(20.7900028, 8.00001526, 3.98998308, -1, 0, 0, 0, 1, 0, 0, 0, -1)
  107. o4.BottomSurface = Enum.SurfaceType.Smooth
  108. o4.TopSurface = Enum.SurfaceType.Smooth
  109. o4.Color = Color3.new(0.156863, 0.498039, 0.278431)
  110. o4.Position = Vector3.new(20.7900028, 8.00001526, 3.98998308)
  111. o4.Orientation = Vector3.new(0, 180, 0)
  112. o4.Color = Color3.new(0.156863, 0.498039, 0.278431)
  113. o5.Name = "Left Hip"
  114. o5.Parent = o4
  115. o5.C0 = CFrame.new(-1, -1, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
  116. o5.C1 = CFrame.new(-0.5, 1, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
  117. o5.Part0 = o4
  118. o5.Part1 = o11
  119. o5.MaxVelocity = 0.10000000149012
  120. o6.Name = "Right Hip"
  121. o6.Parent = o4
  122. o6.C0 = CFrame.new(1, -1, 0, -4.37113883e-08, 0, 1, -0, 0.99999994, 0, -1, 0, -4.37113883e-08)
  123. o6.C1 = CFrame.new(0.5, 1, 0, -4.37113883e-08, 0, 1, 0, 0.99999994, 0, -1, 0, -4.37113883e-08)
  124. o6.Part0 = o4
  125. o6.Part1 = o12
  126. o6.MaxVelocity = 0.10000000149012
  127. o7.Name = "Left Shoulder"
  128. o7.Parent = o4
  129. o7.C0 = CFrame.new(-1, 0.5, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
  130. o7.C1 = CFrame.new(0.5, 0.5, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
  131. o7.Part0 = o4
  132. o7.Part1 = o13
  133. o7.MaxVelocity = 0.10000000149012
  134. o8.Name = "Right Shoulder"
  135. o8.Parent = o4
  136. o8.C0 = CFrame.new(1, 0.5, 0, -4.37113883e-08, 0, 1, -0, 0.99999994, 0, -1, 0, -4.37113883e-08)
  137. o8.C1 = CFrame.new(-0.5, 0.5, 0, -4.37113883e-08, 0, 1, 0, 0.99999994, 0, -1, 0, -4.37113883e-08)
  138. o8.Part0 = o4
  139. o8.Part1 = o14
  140. o8.MaxVelocity = 0.10000000149012
  141. o9.Name = "Neck"
  142. o9.Parent = o4
  143. o9.C0 = CFrame.new(0, 1, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  144. o9.C1 = CFrame.new(0, -0.5, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  145. o9.Part0 = o4
  146. o9.Part1 = o15
  147. o9.MaxVelocity = 0.10000000149012
  148. o10.Parent = o4
  149. table.insert(cors,coroutine.create(function()
  150. wait()
  151. runDummyScript(function()
  152. local color = script.Parent.Parent.Configurations.FriendlyTeam.Value
  153. print(color)
  154. script.Parent.BrickColor = color
  155. end,o10)
  156. end))
  157. o11.Name = "Left Leg"
  158. o11.Parent = o1
  159. o11.BrickColor = BrickColor.new("Pastel Blue")
  160. o11.Position = Vector3.new(21.2900028, 6.00001526, 3.98998308)
  161. o11.Rotation = Vector3.new(-180, 0, -180)
  162. o11.FormFactor = Enum.FormFactor.Symmetric
  163. o11.Size = Vector3.new(1, 2, 1)
  164. o11.CFrame = CFrame.new(21.2900028, 6.00001526, 3.98998308, -1, 0, 0, 0, 0.999999881, 0, 0, 0, -1)
  165. o11.BottomSurface = Enum.SurfaceType.Smooth
  166. o11.TopSurface = Enum.SurfaceType.Smooth
  167. o11.Color = Color3.new(0.501961, 0.733333, 0.858824)
  168. o11.Position = Vector3.new(21.2900028, 6.00001526, 3.98998308)
  169. o11.Orientation = Vector3.new(0, 180, 0)
  170. o11.Color = Color3.new(0.501961, 0.733333, 0.858824)
  171. o12.Name = "Right Leg"
  172. o12.Parent = o1
  173. o12.BrickColor = BrickColor.new("Pastel Blue")
  174. o12.Position = Vector3.new(20.2900028, 6.00001526, 3.98998308)
  175. o12.Rotation = Vector3.new(-180, 0, -180)
  176. o12.FormFactor = Enum.FormFactor.Symmetric
  177. o12.Size = Vector3.new(1, 2, 1)
  178. o12.CFrame = CFrame.new(20.2900028, 6.00001526, 3.98998308, -1, 0, 0, 0, 0.999999881, 0, 0, 0, -1)
  179. o12.BottomSurface = Enum.SurfaceType.Smooth
  180. o12.TopSurface = Enum.SurfaceType.Smooth
  181. o12.Color = Color3.new(0.501961, 0.733333, 0.858824)
  182. o12.Position = Vector3.new(20.2900028, 6.00001526, 3.98998308)
  183. o12.Orientation = Vector3.new(0, 180, 0)
  184. o12.Color = Color3.new(0.501961, 0.733333, 0.858824)
  185. o13.Name = "Left Arm"
  186. o13.Parent = o1
  187. o13.BrickColor = BrickColor.new("Light stone grey")
  188. o13.Position = Vector3.new(22.2900028, 8.00001526, 3.98998308)
  189. o13.Rotation = Vector3.new(-180, 0, -180)
  190. o13.FormFactor = Enum.FormFactor.Symmetric
  191. o13.Size = Vector3.new(1, 2, 1)
  192. o13.CFrame = CFrame.new(22.2900028, 8.00001526, 3.98998308, -1, 0, 0, 0, 0.999999881, 0, 0, 0, -1)
  193. o13.BottomSurface = Enum.SurfaceType.Smooth
  194. o13.TopSurface = Enum.SurfaceType.Smooth
  195. o13.Color = Color3.new(0.898039, 0.894118, 0.87451)
  196. o13.Position = Vector3.new(22.2900028, 8.00001526, 3.98998308)
  197. o13.Orientation = Vector3.new(0, 180, 0)
  198. o13.Color = Color3.new(0.898039, 0.894118, 0.87451)
  199. o14.Name = "Right Arm"
  200. o14.Parent = o1
  201. o14.BrickColor = BrickColor.new("Light stone grey")
  202. o14.Position = Vector3.new(19.2900028, 8.00001526, 3.98998308)
  203. o14.Rotation = Vector3.new(-180, 0, -180)
  204. o14.FormFactor = Enum.FormFactor.Symmetric
  205. o14.Size = Vector3.new(1, 2, 1)
  206. o14.CFrame = CFrame.new(19.2900028, 8.00001526, 3.98998308, -1, 0, 0, 0, 0.999999881, 0, 0, 0, -1)
  207. o14.BottomSurface = Enum.SurfaceType.Smooth
  208. o14.TopSurface = Enum.SurfaceType.Smooth
  209. o14.Color = Color3.new(0.898039, 0.894118, 0.87451)
  210. o14.Position = Vector3.new(19.2900028, 8.00001526, 3.98998308)
  211. o14.Orientation = Vector3.new(0, 180, 0)
  212. o14.Color = Color3.new(0.898039, 0.894118, 0.87451)
  213. o15.Name = "Head"
  214. o15.Parent = o1
  215. o15.BrickColor = BrickColor.new("Light stone grey")
  216. o15.Position = Vector3.new(20.7900028, 9.50001526, 3.98998308)
  217. o15.Rotation = Vector3.new(-180, 0, -180)
  218. o15.FormFactor = Enum.FormFactor.Symmetric
  219. o15.Size = Vector3.new(2, 1, 1)
  220. o15.CFrame = CFrame.new(20.7900028, 9.50001526, 3.98998308, -1, 0, 0, 0, 1, 0, 0, 0, -1)
  221. o15.BottomSurface = Enum.SurfaceType.Smooth
  222. o15.TopSurface = Enum.SurfaceType.Smooth
  223. o15.Color = Color3.new(0.898039, 0.894118, 0.87451)
  224. o15.Position = Vector3.new(20.7900028, 9.50001526, 3.98998308)
  225. o15.Orientation = Vector3.new(0, 180, 0)
  226. o15.Color = Color3.new(0.898039, 0.894118, 0.87451)
  227. o16.Name = "Face"
  228. o16.Parent = o15
  229. o16.Texture = "rbxasset://textures/face.png"
  230. o17.Parent = o15
  231. o17.Scale = Vector3.new(1.25, 1.25, 1.25)
  232. o17.Scale = Vector3.new(1.25, 1.25, 1.25)
  233. o18.Parent = o1
  234. o18.NameOcclusion = Enum.NameOcclusion.NoOcclusion
  235. o18.RightLeg = o12
  236. o18.LeftLeg = o11
  237. o18.Torso = o2
  238. o19.Name = "Animate"
  239. o19.Parent = o1
  240. table.insert(cors,coroutine.create(function()
  241. wait()
  242. runDummyScript(function()
  243. -- This is in charge of the animations for the character. Pretty much stole it from the default character. Removed emote stuff.
  244. function waitForChild(parent, childName)
  245. local child = parent:findFirstChild(childName)
  246. if child then return child end
  247. while true do
  248. child = parent.ChildAdded:wait()
  249. if child.Name==childName then return child end
  250. end
  251. end
  252.  
  253. local Figure = script.Parent
  254. local Torso = waitForChild(Figure, "Torso")
  255. local RightShoulder = waitForChild(Torso, "Right Shoulder")
  256. local LeftShoulder = waitForChild(Torso, "Left Shoulder")
  257. local RightHip = waitForChild(Torso, "Right Hip")
  258. local LeftHip = waitForChild(Torso, "Left Hip")
  259. local Neck = waitForChild(Torso, "Neck")
  260. local Humanoid = waitForChild(Figure, "Humanoid")
  261. local pose = "Standing"
  262.  
  263. local currentAnim = ""
  264. local currentAnimInstance = nil
  265. local currentAnimTrack = nil
  266. local currentAnimKeyframeHandler = nil
  267. local currentAnimSpeed = 1.0
  268. local animTable = {}
  269. local animNames = {
  270. idle = {
  271. { id = "http://www.roblox.com/asset/?id=180435571", weight = 9 },
  272. { id = "http://www.roblox.com/asset/?id=180435792", weight = 1 }
  273. },
  274. walk = {
  275. { id = "http://www.roblox.com/asset/?id=180426354", weight = 10 }
  276. },
  277. run = {
  278. { id = "run.xml", weight = 10 }
  279. },
  280. jump = {
  281. { id = "http://www.roblox.com/asset/?id=125750702", weight = 10 }
  282. },
  283. fall = {
  284. { id = "http://www.roblox.com/asset/?id=180436148", weight = 10 }
  285. },
  286. climb = {
  287. { id = "http://www.roblox.com/asset/?id=180436334", weight = 10 }
  288. },
  289. sit = {
  290. { id = "http://www.roblox.com/asset/?id=178130996", weight = 10 }
  291. },
  292. toolnone = {
  293. { id = "http://www.roblox.com/asset/?id=182393478", weight = 10 }
  294. },
  295. toolslash = {
  296. { id = "http://www.roblox.com/asset/?id=129967390", weight = 10 }
  297. -- { id = "slash.xml", weight = 10 }
  298. },
  299. toollunge = {
  300. { id = "http://www.roblox.com/asset/?id=129967478", weight = 10 }
  301. },
  302. wave = {
  303. { id = "http://www.roblox.com/asset/?id=128777973", weight = 10 }
  304. },
  305. point = {
  306. { id = "http://www.roblox.com/asset/?id=128853357", weight = 10 }
  307. },
  308. dance = {
  309. { id = "http://www.roblox.com/asset/?id=182435998", weight = 10 },
  310. { id = "http://www.roblox.com/asset/?id=182491037", weight = 10 },
  311. { id = "http://www.roblox.com/asset/?id=182491065", weight = 10 }
  312. },
  313. dance2 = {
  314. { id = "http://www.roblox.com/asset/?id=182436842", weight = 10 },
  315. { id = "http://www.roblox.com/asset/?id=182491248", weight = 10 },
  316. { id = "http://www.roblox.com/asset/?id=182491277", weight = 10 }
  317. },
  318. dance3 = {
  319. { id = "http://www.roblox.com/asset/?id=182436935", weight = 10 },
  320. { id = "http://www.roblox.com/asset/?id=182491368", weight = 10 },
  321. { id = "http://www.roblox.com/asset/?id=182491423", weight = 10 }
  322. },
  323. laugh = {
  324. { id = "http://www.roblox.com/asset/?id=129423131", weight = 10 }
  325. },
  326. cheer = {
  327. { id = "http://www.roblox.com/asset/?id=129423030", weight = 10 }
  328. },
  329. }
  330.  
  331. math.randomseed(tick())
  332.  
  333. function configureAnimationSet(name, fileList)
  334. if (animTable[name] ~= nil) then
  335. for _, connection in pairs(animTable[name].connections) do
  336. connection:disconnect()
  337. end
  338. end
  339. animTable[name] = {}
  340. animTable[name].count = 0
  341. animTable[name].totalWeight = 0
  342. animTable[name].connections = {}
  343.  
  344. -- check for config values
  345. local config = script:FindFirstChild(name)
  346. if (config ~= nil) then
  347. -- print("Loading anims " .. name)
  348. table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
  349. table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
  350. local idx = 1
  351. for _, childPart in pairs(config:GetChildren()) do
  352. if (childPart:IsA("Animation")) then
  353. table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
  354. animTable[name][idx] = {}
  355. animTable[name][idx].anim = childPart
  356. local weightObject = childPart:FindFirstChild("Weight")
  357. if (weightObject == nil) then
  358. animTable[name][idx].weight = 1
  359. else
  360. animTable[name][idx].weight = weightObject.Value
  361. end
  362. animTable[name].count = animTable[name].count + 1
  363. animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  364. -- print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
  365. idx = idx + 1
  366. end
  367. end
  368. end
  369.  
  370. -- fallback to defaults
  371. if (animTable[name].count <= 0) then
  372. for idx, anim in pairs(fileList) do
  373. animTable[name][idx] = {}
  374. animTable[name][idx].anim = Instance.new("Animation")
  375. animTable[name][idx].anim.Name = name
  376. animTable[name][idx].anim.AnimationId = anim.id
  377. animTable[name][idx].weight = anim.weight
  378. animTable[name].count = animTable[name].count + 1
  379. animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  380. -- print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
  381. end
  382. end
  383. end
  384.  
  385. -- Setup animation objects
  386. function scriptChildModified(child)
  387. local fileList = animNames[child.Name]
  388. if (fileList ~= nil) then
  389. configureAnimationSet(child.Name, fileList)
  390. end
  391. end
  392.  
  393. script.ChildAdded:connect(scriptChildModified)
  394. script.ChildRemoved:connect(scriptChildModified)
  395.  
  396.  
  397. for name, fileList in pairs(animNames) do
  398. configureAnimationSet(name, fileList)
  399. end
  400.  
  401. -- ANIMATION
  402.  
  403. -- declarations
  404. local toolAnim = "None"
  405. local toolAnimTime = 0
  406.  
  407. local jumpAnimTime = 0
  408. local jumpAnimDuration = 0.3
  409.  
  410. local toolTransitionTime = 0.1
  411. local fallTransitionTime = 0.3
  412. local jumpMaxLimbVelocity = 0.75
  413.  
  414. -- functions
  415.  
  416. function stopAllAnimations()
  417. local oldAnim = currentAnim
  418.  
  419. currentAnim = ""
  420. currentAnimInstance = nil
  421. if (currentAnimKeyframeHandler ~= nil) then
  422. currentAnimKeyframeHandler:disconnect()
  423. end
  424.  
  425. if (currentAnimTrack ~= nil) then
  426. currentAnimTrack:Stop()
  427. currentAnimTrack:Destroy()
  428. currentAnimTrack = nil
  429. end
  430. return oldAnim
  431. end
  432.  
  433. function setAnimationSpeed(speed)
  434. if speed ~= currentAnimSpeed then
  435. currentAnimSpeed = speed
  436. currentAnimTrack:AdjustSpeed(currentAnimSpeed)
  437. end
  438. end
  439.  
  440. function keyFrameReachedFunc(frameName)
  441. if (frameName == "End") then
  442. -- print("Keyframe : ".. frameName)
  443.  
  444. local repeatAnim = currentAnim
  445.  
  446. local animSpeed = currentAnimSpeed
  447. playAnimation(repeatAnim, 0.0, Humanoid)
  448. setAnimationSpeed(animSpeed)
  449. end
  450. end
  451.  
  452. -- Preload animations
  453. function playAnimation(animName, transitionTime, humanoid)
  454.  
  455. local roll = math.random(1, animTable[animName].totalWeight)
  456. local origRoll = roll
  457. local idx = 1
  458. while (roll > animTable[animName][idx].weight) do
  459. roll = roll - animTable[animName][idx].weight
  460. idx = idx + 1
  461. end
  462. -- print(animName .. " " .. idx .. " [" .. origRoll .. "]")
  463. local anim = animTable[animName][idx].anim
  464.  
  465. -- switch animation
  466. if (anim ~= currentAnimInstance) then
  467.  
  468. if (currentAnimTrack ~= nil) then
  469. currentAnimTrack:Stop(transitionTime)
  470. currentAnimTrack:Destroy()
  471. end
  472.  
  473. currentAnimSpeed = 1.0
  474.  
  475. -- load it to the humanoid; get AnimationTrack
  476. currentAnimTrack = humanoid:LoadAnimation(anim)
  477.  
  478. -- play the animation
  479. currentAnimTrack:Play(transitionTime)
  480. currentAnim = animName
  481. currentAnimInstance = anim
  482.  
  483. -- set up keyframe name triggers
  484. if (currentAnimKeyframeHandler ~= nil) then
  485. currentAnimKeyframeHandler:disconnect()
  486. end
  487. currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
  488.  
  489. end
  490.  
  491. end
  492.  
  493. -------------------------------------------------------------------------------------------
  494. -------------------------------------------------------------------------------------------
  495.  
  496. local toolAnimName = ""
  497. local toolAnimTrack = nil
  498. local toolAnimInstance = nil
  499. local currentToolAnimKeyframeHandler = nil
  500.  
  501. function toolKeyFrameReachedFunc(frameName)
  502. if (frameName == "End") then
  503. -- print("Keyframe : ".. frameName)
  504. playToolAnimation(toolAnimName, 0.0, Humanoid)
  505. end
  506. end
  507.  
  508.  
  509. function playToolAnimation(animName, transitionTime, humanoid)
  510.  
  511. local roll = math.random(1, animTable[animName].totalWeight)
  512. local origRoll = roll
  513. local idx = 1
  514. while (roll > animTable[animName][idx].weight) do
  515. roll = roll - animTable[animName][idx].weight
  516. idx = idx + 1
  517. end
  518. -- print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
  519. local anim = animTable[animName][idx].anim
  520.  
  521. if (toolAnimInstance ~= anim) then
  522.  
  523. if (toolAnimTrack ~= nil) then
  524. toolAnimTrack:Stop()
  525. toolAnimTrack:Destroy()
  526. transitionTime = 0
  527. end
  528.  
  529. -- load it to the humanoid; get AnimationTrack
  530. toolAnimTrack = humanoid:LoadAnimation(anim)
  531.  
  532. -- play the animation
  533. toolAnimTrack:Play(transitionTime)
  534. toolAnimName = animName
  535. toolAnimInstance = anim
  536.  
  537. currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
  538. end
  539. end
  540.  
  541. function stopToolAnimations()
  542. local oldAnim = toolAnimName
  543.  
  544. if (currentToolAnimKeyframeHandler ~= nil) then
  545. currentToolAnimKeyframeHandler:disconnect()
  546. end
  547.  
  548. toolAnimName = ""
  549. toolAnimInstance = nil
  550. if (toolAnimTrack ~= nil) then
  551. toolAnimTrack:Stop()
  552. toolAnimTrack:Destroy()
  553. toolAnimTrack = nil
  554. end
  555.  
  556.  
  557. return oldAnim
  558. end
  559.  
  560. -------------------------------------------------------------------------------------------
  561. -------------------------------------------------------------------------------------------
  562.  
  563.  
  564. function onRunning(speed)
  565. if speed>0.01 then
  566. playAnimation("walk", 0.1, Humanoid)
  567. pose = "Running"
  568. else
  569. playAnimation("idle", 0.1, Humanoid)
  570. pose = "Standing"
  571. end
  572. end
  573.  
  574. function onDied()
  575. pose = "Dead"
  576. end
  577.  
  578. function onJumping()
  579. playAnimation("jump", 0.1, Humanoid)
  580. jumpAnimTime = jumpAnimDuration
  581. pose = "Jumping"
  582. end
  583.  
  584. function onClimbing(speed)
  585. playAnimation("climb", 0.1, Humanoid)
  586. setAnimationSpeed(speed / 12.0)
  587. pose = "Climbing"
  588. end
  589.  
  590. function onGettingUp()
  591. pose = "GettingUp"
  592. end
  593.  
  594. function onFreeFall()
  595. if (jumpAnimTime <= 0) then
  596. playAnimation("fall", fallTransitionTime, Humanoid)
  597. end
  598. pose = "FreeFall"
  599. end
  600.  
  601. function onFallingDown()
  602. pose = "FallingDown"
  603. end
  604.  
  605. function onSeated()
  606. pose = "Seated"
  607. end
  608.  
  609. function onPlatformStanding()
  610. pose = "PlatformStanding"
  611. end
  612.  
  613. function onSwimming(speed)
  614. if speed>0 then
  615. pose = "Running"
  616. else
  617. pose = "Standing"
  618. end
  619. end
  620.  
  621. function getTool()
  622. for _, kid in ipairs(Figure:GetChildren()) do
  623. if kid.className == "Tool" then return kid end
  624. end
  625. return nil
  626. end
  627.  
  628. function getToolAnim(tool)
  629. for _, c in ipairs(tool:GetChildren()) do
  630. if c.Name == "toolanim" and c.className == "StringValue" then
  631. return c
  632. end
  633. end
  634. return nil
  635. end
  636.  
  637. function animateTool()
  638.  
  639. if (toolAnim == "None") then
  640. playToolAnimation("toolnone", toolTransitionTime, Humanoid)
  641. return
  642. end
  643.  
  644. if (toolAnim == "Slash") then
  645. playToolAnimation("toolslash", 0, Humanoid)
  646. return
  647. end
  648.  
  649. if (toolAnim == "Lunge") then
  650. playToolAnimation("toollunge", 0, Humanoid)
  651. return
  652. end
  653. end
  654.  
  655. function moveSit()
  656. RightShoulder.MaxVelocity = 0.15
  657. LeftShoulder.MaxVelocity = 0.15
  658. RightShoulder:SetDesiredAngle(3.14 /2)
  659. LeftShoulder:SetDesiredAngle(-3.14 /2)
  660. RightHip:SetDesiredAngle(3.14 /2)
  661. LeftHip:SetDesiredAngle(-3.14 /2)
  662. end
  663.  
  664. local lastTick = 0
  665.  
  666. function move(time)
  667. local amplitude = 1
  668. local frequency = 1
  669. local deltaTime = time - lastTick
  670. lastTick = time
  671.  
  672. local climbFudge = 0
  673. local setAngles = false
  674.  
  675. if (jumpAnimTime > 0) then
  676. jumpAnimTime = jumpAnimTime - deltaTime
  677. end
  678.  
  679. if (pose == "FreeFall" and jumpAnimTime <= 0) then
  680. playAnimation("fall", fallTransitionTime, Humanoid)
  681. elseif (pose == "Seated") then
  682. playAnimation("sit", 0.5, Humanoid)
  683. return
  684. elseif (pose == "Running") then
  685. playAnimation("walk", 0.1, Humanoid)
  686. elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
  687. -- print("Wha " .. pose)
  688. stopAllAnimations()
  689. amplitude = 0.1
  690. frequency = 1
  691. setAngles = true
  692. end
  693.  
  694. if (setAngles) then
  695. desiredAngle = amplitude * math.sin(time * frequency)
  696.  
  697. RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
  698. LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
  699. RightHip:SetDesiredAngle(-desiredAngle)
  700. LeftHip:SetDesiredAngle(-desiredAngle)
  701. end
  702.  
  703. -- Tool Animation handling
  704. local tool = getTool()
  705. if tool then
  706.  
  707. animStringValueObject = getToolAnim(tool)
  708.  
  709. if animStringValueObject then
  710. toolAnim = animStringValueObject.Value
  711. -- message recieved, delete StringValue
  712. animStringValueObject.Parent = nil
  713. toolAnimTime = time + .3
  714. end
  715.  
  716. if time > toolAnimTime then
  717. toolAnimTime = 0
  718. toolAnim = "None"
  719. end
  720.  
  721. animateTool()
  722. else
  723. stopToolAnimations()
  724. toolAnim = "None"
  725. toolAnimInstance = nil
  726. toolAnimTime = 0
  727. end
  728. end
  729.  
  730. -- connect events
  731. Humanoid.Died:connect(onDied)
  732. Humanoid.Running:connect(onRunning)
  733. Humanoid.Jumping:connect(onJumping)
  734. Humanoid.Climbing:connect(onClimbing)
  735. Humanoid.GettingUp:connect(onGettingUp)
  736. Humanoid.FreeFalling:connect(onFreeFall)
  737. Humanoid.FallingDown:connect(onFallingDown)
  738. Humanoid.Seated:connect(onSeated)
  739. Humanoid.PlatformStanding:connect(onPlatformStanding)
  740. Humanoid.Swimming:connect(onSwimming)
  741.  
  742.  
  743. -- main program
  744.  
  745. local runService = game:service("RunService");
  746.  
  747. -- initialize to idle
  748. playAnimation("idle", 0.1, Humanoid)
  749. pose = "Standing"
  750.  
  751. while Figure.Parent~=nil do
  752. local _, time = wait(0.1)
  753. move(time)
  754. end
  755.  
  756.  
  757.  
  758. end,o19)
  759. end))
  760. o20.Name = "climb"
  761. o20.Parent = o19
  762. o21.Name = "ClimbAnim"
  763. o21.Parent = o20
  764. o21.AnimationId = "http://www.roblox.com/asset/?id=180436334"
  765. o22.Name = "fall"
  766. o22.Parent = o19
  767. o23.Name = "FallAnim"
  768. o23.Parent = o22
  769. o23.AnimationId = "http://www.roblox.com/asset/?id=180436148"
  770. o24.Name = "idle"
  771. o24.Parent = o19
  772. o25.Name = "Animation1"
  773. o25.Parent = o24
  774. o25.AnimationId = "http://www.roblox.com/asset/?id=180435571"
  775. o26.Name = "Weight"
  776. o26.Parent = o25
  777. o26.Value = 9
  778. o27.Name = "Animation2"
  779. o27.Parent = o24
  780. o27.AnimationId = "http://www.roblox.com/asset/?id=180435792"
  781. o28.Name = "Weight"
  782. o28.Parent = o27
  783. o28.Value = 1
  784. o29.Name = "jump"
  785. o29.Parent = o19
  786. o30.Name = "JumpAnim"
  787. o30.Parent = o29
  788. o30.AnimationId = "http://www.roblox.com/asset/?id=125750702"
  789. o31.Name = "run"
  790. o31.Parent = o19
  791. o32.Name = "RunAnim"
  792. o32.Parent = o31
  793. o32.AnimationId = "http://www.roblox.com/asset/?id=180426354"
  794. o33.Name = "sit"
  795. o33.Parent = o19
  796. o34.Name = "SitAnim"
  797. o34.Parent = o33
  798. o34.AnimationId = "http://www.roblox.com/asset/?id=178130996"
  799. o35.Name = "toolnone"
  800. o35.Parent = o19
  801. o36.Name = "ToolNoneAnim"
  802. o36.Parent = o35
  803. o36.AnimationId = "http://www.roblox.com/asset/?id=182393478"
  804. o37.Name = "walk"
  805. o37.Parent = o19
  806. o38.Name = "WalkAnim"
  807. o38.Parent = o37
  808. o38.AnimationId = "http://www.roblox.com/asset/?id=180426354"
  809. o39.Name = "Attacked"
  810. o39.Parent = o1
  811. o40.Name = "MonsterScript"
  812. o40.Parent = o1
  813. table.insert(cors,coroutine.create(function()
  814. wait()
  815. runDummyScript(function()
  816. --[[
  817. Basic Monster by ArceusInator
  818.  
  819. Information:
  820. Configurations.MaximumDetectionDistance (default 200)
  821. The monster will not detect players past this point. If you set it to a negative number then the monster will be able to chase from any distance.
  822.  
  823. Configurations.CanGiveUp (default true)
  824. If true, the monster will give up if its target goes past the MaximumDetectionDistance. This is a pretty good idea if you have people teleporting around.
  825.  
  826. Configurations.CanRespawn (default true)
  827. If true, the monster will respawn after it dies
  828.  
  829. Configurations.AutoDetectSpawnPoint (default true)
  830. If true, the spawn point will be auto detected based on where the monster is when it starts
  831.  
  832. Configurations.SpawnPoint (default 0,0,0)
  833. If Settings.AutoDetectSpawnPoint is disabled, this will be set to the monster's initial position. This value will be used when the monster auto respawns to tell it where to spawn next.
  834.  
  835. Configurations.FriendlyTeam (default Really black)
  836. The monster will not attack players on this team
  837.  
  838.  
  839.  
  840. Mind.CurrentTargetHumanoid (Humanoid objects only)
  841. You can force the monster to follow a certain humanoid by setting this to that humanoid
  842.  
  843.  
  844.  
  845. Monster.Respawn (Function)
  846. Arguments are: Vector3 point
  847. Info: Respawns the monster at the given point, or at the SpawnPoint setting if none if provided
  848.  
  849. Monster.Died (Event)
  850. Info: Fired when the monster dies
  851.  
  852. Monster.Respawned (Event)
  853. Info: Fired when the monster respawns
  854. --]]
  855.  
  856. local Self = script.Parent
  857. local Settings = Self:FindFirstChild'Configurations' -- Points to the settings.
  858. local Mind = Self:FindFirstChild'Mind' -- Points to the monster's mind. You can edit parts of this from other scripts in-game to change the monster's behavior. Advanced users only.
  859.  
  860. --
  861. -- Verify that everything is where it should be
  862. assert(Self:FindFirstChild'Humanoid' ~= nil, 'Monster does not have a humanoid')
  863. assert(Settings ~= nil, 'Monster does not have a Configurations object')
  864. assert(Settings:FindFirstChild'MaximumDetectionDistance' ~= nil and Settings.MaximumDetectionDistance:IsA'NumberValue', 'Monster does not have a MaximumDetectionDistance (NumberValue) setting')
  865. assert(Settings:FindFirstChild'CanGiveUp' ~= nil and Settings.CanGiveUp:IsA'BoolValue', 'Monster does not have a CanGiveUp (BoolValue) setting')
  866. assert(Settings:FindFirstChild'CanRespawn' ~= nil and Settings.CanRespawn:IsA'BoolValue', 'Monster does not have a CanRespawn (BoolValue) setting')
  867. assert(Settings:FindFirstChild'SpawnPoint' ~= nil and Settings.SpawnPoint:IsA'Vector3Value', 'Monster does not have a SpawnPoint (Vector3Value) setting')
  868. assert(Settings:FindFirstChild'AutoDetectSpawnPoint' ~= nil and Settings.AutoDetectSpawnPoint:IsA'BoolValue', 'Monster does not have a AutoDetectSpawnPoint (BoolValue) setting')
  869. assert(Settings:FindFirstChild'FriendlyTeam' ~= nil and Settings.FriendlyTeam:IsA'BrickColorValue', 'Monster does not have a FriendlyTeam (BrickColorValue) setting')
  870. assert(Settings:FindFirstChild'AttackDamage' ~= nil and Settings.AttackDamage:IsA'NumberValue', 'Monster does not have a AttackDamage (NumberValue) setting')
  871. assert(Settings:FindFirstChild'AttackFrequency' ~= nil and Settings.AttackFrequency:IsA'NumberValue', 'Monster does not have a AttackFrequency (NumberValue) setting')
  872. assert(Settings:FindFirstChild'AttackRange' ~= nil and Settings.AttackRange:IsA'NumberValue', 'Monster does not have a AttackRange (NumberValue) setting')
  873. assert(Mind ~= nil, 'Monster does not have a Mind object')
  874. assert(Mind:FindFirstChild'CurrentTargetHumanoid' ~= nil and Mind.CurrentTargetHumanoid:IsA'ObjectValue', 'Monster does not have a CurrentTargetHumanoid (ObjectValue) mind setting')
  875. assert(Self:FindFirstChild'Respawn' and Self.Respawn:IsA'BindableFunction', 'Monster does not have a Respawn BindableFunction')
  876. assert(Self:FindFirstChild'Died' and Self.Died:IsA'BindableEvent', 'Monster does not have a Died BindableEvent')
  877. assert(Self:FindFirstChild'Respawned' and Self.Died:IsA'BindableEvent', 'Monster does not have a Respawned BindableEvent')
  878. assert(Self:FindFirstChild'Attacked' and Self.Died:IsA'BindableEvent', 'Monster does not have a Attacked BindableEvent')
  879. assert(script:FindFirstChild'Attack' and script.Attack:IsA'Animation', 'Monster does not have a MonsterScript.Attack Animation')
  880.  
  881.  
  882. --
  883. --
  884. local Info = {
  885. -- These are constant values. Don't change them unless you know what you're doing.
  886.  
  887. -- Services
  888. Players = Game:GetService 'Players',
  889. PathfindingService = Game:GetService 'PathfindingService',
  890.  
  891. -- Advanced settings
  892. RecomputePathFrequency = 1, -- The monster will recompute its path this many times per second
  893. RespawnWaitTime = 5, -- How long to wait before the monster respawns
  894. JumpCheckFrequency = 1, -- How many times per second it will do a jump check
  895. }
  896. local Data = {
  897. -- These are variable values used internally by the script. Advanced users only.
  898.  
  899. LastRecomputePath = 0,
  900. Recomputing = false, -- Reocmputing occurs async, meaning this script will still run while it's happening. This variable will prevent the script from running two recomputes at once.
  901. PathCoords = {},
  902. IsDead = false,
  903. TimeOfDeath = 0,
  904. CurrentNode = nil,
  905. CurrentNodeIndex = 1,
  906. AutoRecompute = true,
  907. LastJumpCheck = 0,
  908. LastAttack = 0,
  909.  
  910. BaseMonster = Self:Clone(),
  911. AttackTrack = nil,
  912. }
  913.  
  914. --
  915. --
  916. local Monster = {} -- Create the monster class
  917.  
  918.  
  919. function Monster:GetCFrame()
  920. -- Returns the CFrame of the monster's humanoidrootpart
  921.  
  922. local humanoidRootPart = Self:FindFirstChild('HumanoidRootPart')
  923.  
  924. if humanoidRootPart ~= nil and humanoidRootPart:IsA('BasePart') then
  925. return humanoidRootPart.CFrame
  926. else
  927. return CFrame.new()
  928. end
  929. end
  930.  
  931. function Monster:GetMaximumDetectionDistance()
  932. -- Returns the maximum detection distance
  933.  
  934. local setting = Settings.MaximumDetectionDistance.Value
  935.  
  936. if setting < 0 then
  937. return math.huge
  938. else
  939. return setting
  940. end
  941. end
  942.  
  943. function Monster:SearchForTarget()
  944. -- Finds the closest player and sets the target
  945.  
  946. local players = Info.Players:GetPlayers()
  947. local closestCharacter, closestCharacterDistance
  948.  
  949. for i=1, #players do
  950. local player = players[i]
  951.  
  952. if player.Neutral or player.TeamColor ~= Settings.FriendlyTeam.Value then
  953. local character = player.Character
  954.  
  955. if character ~= nil and character:FindFirstChild('Humanoid') ~= nil and character.Humanoid:IsA('Humanoid') then
  956. local distance = player:DistanceFromCharacter(Monster:GetCFrame().p)
  957.  
  958. if distance < Monster:GetMaximumDetectionDistance() then
  959. if closestCharacter == nil then
  960. closestCharacter, closestCharacterDistance = character, distance
  961. else
  962. if closestCharacterDistance > distance then
  963. closestCharacter, closestCharacterDistance = character, distance
  964. end
  965. end
  966. end
  967. end
  968. end
  969. end
  970.  
  971.  
  972. if closestCharacter ~= nil then
  973. Mind.CurrentTargetHumanoid.Value = closestCharacter.Humanoid
  974. end
  975. end
  976.  
  977. function Monster:TryRecomputePath()
  978. if Data.AutoRecompute or tick() - Data.LastRecomputePath > 1/Info.RecomputePathFrequency then
  979. Monster:RecomputePath()
  980. end
  981. end
  982.  
  983. function Monster:GetTargetCFrame()
  984. local targetHumanoid = Mind.CurrentTargetHumanoid.Value
  985.  
  986. if Monster:TargetIsValid() then
  987. return targetHumanoid.Torso.CFrame
  988. else
  989. return CFrame.new()
  990. end
  991. end
  992.  
  993. function Monster:IsAlive()
  994. return Self.Humanoid.Health > 0 and Self.Humanoid.Torso ~= nil
  995. end
  996.  
  997. function Monster:TargetIsValid()
  998. local targetHumanoid = Mind.CurrentTargetHumanoid.Value
  999.  
  1000. if targetHumanoid ~= nil and targetHumanoid:IsA 'Humanoid' and targetHumanoid.Torso ~= nil and targetHumanoid.Torso:IsA 'BasePart' then
  1001. return true
  1002. else
  1003. return false
  1004. end
  1005. end
  1006.  
  1007. function Monster:HasClearLineOfSight()
  1008. -- Going to cast a ray to see if I can just see my target
  1009. local myPos, targetPos = Monster:GetCFrame().p, Monster:GetTargetCFrame().p
  1010.  
  1011. local hit, pos = Workspace:FindPartOnRayWithIgnoreList(
  1012. Ray.new(
  1013. myPos,
  1014. targetPos - myPos
  1015. ),
  1016. {
  1017. Self,
  1018. Mind.CurrentTargetHumanoid.Value.Parent
  1019. }
  1020. )
  1021.  
  1022.  
  1023. if hit == nil then
  1024. return true
  1025. else
  1026. return false
  1027. end
  1028. end
  1029.  
  1030. function Monster:RecomputePath()
  1031. if not Data.Recomputing then
  1032. if Monster:IsAlive() and Monster:TargetIsValid() then
  1033. if Monster:HasClearLineOfSight() then
  1034. Data.AutoRecompute = true
  1035. Data.PathCoords = {
  1036. Monster:GetCFrame().p,
  1037. Monster:GetTargetCFrame().p
  1038. }
  1039.  
  1040. Data.LastRecomputePath = tick()
  1041. Data.CurrentNode = nil
  1042. Data.CurrentNodeIndex = 2 -- Starts chasing the target without evaluating its current position
  1043. else
  1044. -- Do pathfinding since you can't walk straight
  1045. Data.Recomputing = true -- Basically a debounce.
  1046. Data.AutoRecompute = false
  1047.  
  1048.  
  1049. local path = Info.PathfindingService:ComputeSmoothPathAsync(
  1050. Monster:GetCFrame().p,
  1051. Monster:GetTargetCFrame().p,
  1052. 500
  1053. )
  1054. Data.PathCoords = path:GetPointCoordinates()
  1055.  
  1056.  
  1057. Data.Recomputing = false
  1058. Data.LastRecomputePath = tick()
  1059. Data.CurrentNode = nil
  1060. Data.CurrentNodeIndex = 1
  1061. end
  1062. end
  1063. end
  1064. end
  1065.  
  1066. function Monster:Update()
  1067. Monster:ReevaluateTarget()
  1068. Monster:SearchForTarget()
  1069. Monster:TryRecomputePath()
  1070. Monster:TravelPath()
  1071. end
  1072.  
  1073. function Monster:TravelPath()
  1074. local closest, closestDistance, closestIndex
  1075. local myPosition = Monster:GetCFrame().p
  1076. local skipCurrentNode = Data.CurrentNode ~= nil and (Data.CurrentNode - myPosition).magnitude < 3
  1077.  
  1078. for i=Data.CurrentNodeIndex, #Data.PathCoords do
  1079. local coord = Data.PathCoords[i]
  1080. if not (skipCurrentNode and coord == Data.CurrentNode) then
  1081. local distance = (coord - myPosition).magnitude
  1082.  
  1083. if closest == nil then
  1084. closest, closestDistance, closestIndex = coord, distance, i
  1085. else
  1086. if distance < closestDistance then
  1087. closest, closestDistance, closestIndex = coord, distance, i
  1088. else
  1089. break
  1090. end
  1091. end
  1092. end
  1093. end
  1094.  
  1095.  
  1096. --
  1097. if closest ~= nil then
  1098. Data.CurrentNode = closest
  1099. Data.CurrentNodeIndex = closestIndex
  1100.  
  1101. local humanoid = Self:FindFirstChild 'Humanoid'
  1102.  
  1103. if humanoid ~= nil and humanoid:IsA'Humanoid' then
  1104. humanoid:MoveTo(closest)
  1105. end
  1106.  
  1107. if Monster:IsAlive() and Monster:TargetIsValid() then
  1108. Monster:TryJumpCheck()
  1109. Monster:TryAttack()
  1110. end
  1111.  
  1112. if closestIndex == #Data.PathCoords then
  1113. -- Reached the end of the path, force a new check
  1114. Data.AutoRecompute = true
  1115. end
  1116. end
  1117. end
  1118.  
  1119. function Monster:TryJumpCheck()
  1120. if tick() - Data.LastJumpCheck > 1/Info.JumpCheckFrequency then
  1121. Monster:JumpCheck()
  1122. end
  1123. end
  1124.  
  1125. function Monster:TryAttack()
  1126. if tick() - Data.LastAttack > 1/Settings.AttackFrequency.Value then
  1127. Monster:Attack()
  1128. end
  1129. end
  1130.  
  1131. function Monster:Attack()
  1132. local myPos, targetPos = Monster:GetCFrame().p, Monster:GetTargetCFrame().p
  1133.  
  1134. if (myPos - targetPos).magnitude <= Settings.AttackRange.Value then
  1135. Mind.CurrentTargetHumanoid.Value:TakeDamage(Settings.AttackDamage.Value)
  1136. Data.LastAttack = tick()
  1137. Data.AttackTrack:Play()
  1138. end
  1139. end
  1140.  
  1141. function Monster:JumpCheck()
  1142. -- Do a raycast to check if we need to jump
  1143. local myCFrame = Monster:GetCFrame()
  1144. local checkVector = (Monster:GetTargetCFrame().p - myCFrame.p).unit*2
  1145.  
  1146. local hit, pos = Workspace:FindPartOnRay(
  1147. Ray.new(
  1148. myCFrame.p + Vector3.new(0, -2.4, 0),
  1149. checkVector
  1150. ),
  1151. Self
  1152. )
  1153.  
  1154. if hit ~= nil and not hit:IsDescendantOf(Mind.CurrentTargetHumanoid.Value.Parent) then
  1155. -- Do a slope check to make sure we're not walking up a ramp
  1156.  
  1157. local hit2, pos2 = Workspace:FindPartOnRay(
  1158. Ray.new(
  1159. myCFrame.p + Vector3.new(0, -2.3, 0),
  1160. checkVector
  1161. ),
  1162. Self
  1163. )
  1164.  
  1165. if hit2 == hit then
  1166. if ((pos2 - pos)*Vector3.new(1,0,1)).magnitude < 0.05 then -- Will pass for any ramp with <2 slope
  1167. Self.Humanoid.Jump = true
  1168. end
  1169. end
  1170. end
  1171.  
  1172. Data.LastJumpCheck = tick()
  1173. end
  1174.  
  1175. function Monster:Connect()
  1176. Mind.CurrentTargetHumanoid.Changed:connect(function(humanoid)
  1177. if humanoid ~= nil then
  1178. assert(humanoid:IsA'Humanoid', 'Monster target must be a humanoid')
  1179.  
  1180. Monster:RecomputePath()
  1181. end
  1182. end)
  1183.  
  1184. Self.Respawn.OnInvoke = function(point)
  1185. Monster:Respawn(point)
  1186. end
  1187. end
  1188.  
  1189. function Monster:Initialize()
  1190. Monster:Connect()
  1191.  
  1192. if Settings.AutoDetectSpawnPoint.Value then
  1193. Settings.SpawnPoint.Value = Monster:GetCFrame().p
  1194. end
  1195. end
  1196.  
  1197. function Monster:Respawn(point)
  1198. local point = point or Settings.SpawnPoint.Value
  1199.  
  1200. for index, obj in next, Data.BaseMonster:Clone():GetChildren() do
  1201. if obj.Name == 'Configurations' or obj.Name == 'Mind' or obj.Name == 'Respawned' or obj.Name == 'Died' or obj.Name == 'MonsterScript' or obj.Name == 'Respawn' then
  1202. obj:Destroy()
  1203. else
  1204. Self[obj.Name]:Destroy()
  1205. obj.Parent = Self
  1206. end
  1207. end
  1208.  
  1209. Monster:InitializeUnique()
  1210.  
  1211. Self.Parent = Workspace
  1212.  
  1213. Self.HumanoidRootPart.CFrame = CFrame.new(point)
  1214. Settings.SpawnPoint.Value = point
  1215. Self.Respawned:Fire()
  1216. end
  1217.  
  1218. function Monster:InitializeUnique()
  1219. Data.AttackTrack = Self.Humanoid:LoadAnimation(script.Attack)
  1220. end
  1221.  
  1222. function Monster:ReevaluateTarget()
  1223. local currentTarget = Mind.CurrentTargetHumanoid.Value
  1224.  
  1225. if currentTarget ~= nil and currentTarget:IsA'Humanoid' then
  1226. local character = currentTarget.Parent
  1227.  
  1228. if character ~= nil then
  1229. local player = Info.Players:GetPlayerFromCharacter(character)
  1230.  
  1231. if player ~= nil then
  1232. if not player.Neutral and player.TeamColor == Settings.FriendlyTeam.Value then
  1233. Mind.CurrentTargetHumanoid.Value = nil
  1234. end
  1235. end
  1236. end
  1237.  
  1238.  
  1239. if currentTarget == Mind.CurrentTargetHumanoid.Value then
  1240. local torso = currentTarget.Torso
  1241.  
  1242. if torso ~= nil and torso:IsA 'BasePart' then
  1243. if Settings.CanGiveUp.Value and (torso.Position - Monster:GetCFrame().p).magnitude > Monster:GetMaximumDetectionDistance() then
  1244. Mind.CurrentTargetHumanoid.Value = nil
  1245. end
  1246. end
  1247. end
  1248. end
  1249. end
  1250.  
  1251. --
  1252. --
  1253. Monster:Initialize()
  1254. Monster:InitializeUnique()
  1255.  
  1256. while true do
  1257. if not Monster:IsAlive() then
  1258. if Data.IsDead == false then
  1259. Data.IsDead = true
  1260. Data.TimeOfDeath = tick()
  1261. Self.Died:Fire()
  1262. end
  1263. if Data.IsDead == true then
  1264. if tick()-Data.TimeOfDeath > Info.RespawnWaitTime then
  1265. Monster:Respawn()
  1266. end
  1267. end
  1268. end
  1269.  
  1270. if Monster:IsAlive() then
  1271. Monster:Update()
  1272. end
  1273.  
  1274. wait()
  1275. end
  1276. end,o40)
  1277. end))
  1278. o41.Name = "Attack"
  1279. o41.Parent = o40
  1280. o41.AnimationId = "http://www.roblox.com/asset?id=190149431"
  1281. o42.Name = "Configurations"
  1282. o42.Parent = o1
  1283. o43.Name = "MaximumDetectionDistance"
  1284. o43.Parent = o42
  1285. o43.Value = 200
  1286. o44.Name = "CanGiveUp"
  1287. o44.Parent = o42
  1288. o44.Value = true
  1289. o45.Name = "CanRespawn"
  1290. o45.Parent = o42
  1291. o45.Value = true
  1292. o46.Name = "SpawnPoint"
  1293. o46.Parent = o42
  1294. o47.Name = "AutoDetectSpawnPoint"
  1295. o47.Parent = o42
  1296. o47.Value = true
  1297. o48.Name = "FriendlyTeam"
  1298. o48.Parent = o42
  1299. o48.Value = BrickColor.new("Dark green")
  1300. o49.Name = "AttackDamage"
  1301. o49.Parent = o42
  1302. o50.Name = "AttackFrequency"
  1303. o50.Parent = o42
  1304. o50.Value = 2
  1305. o51.Name = "AttackRange"
  1306. o51.Parent = o42
  1307. o51.Value = 3
  1308. o52.Name = "Mind"
  1309. o52.Parent = o1
  1310. o53.Name = "CurrentTargetHumanoid"
  1311. o53.Parent = o52
  1312. o54.Name = "Died"
  1313. o54.Parent = o1
  1314. o55.Name = "Respawn"
  1315. o55.Parent = o1
  1316. o56.Name = "Respawned"
  1317. o56.Parent = o1
  1318. mas.Parent = workspace
  1319. mas:MakeJoints()
  1320. local mas1 = mas:GetChildren()
  1321. for i=1,#mas1 do
  1322. mas1[i].Parent = script
  1323. ypcall(function() mas1[i]:MakeJoints() end)
  1324. end
  1325. mas:Destroy()
  1326. for i=1,#cors do
  1327. coroutine.resume(cors[i])
  1328. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement