Advertisement
lafur

Untitled

Oct 27th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.51 KB | None | 0 0
  1. --Created by PenguinAnonymous (ttyyuu12345) Editied by Dittoide
  2. --What's Added To M2S with Dittoide's Edit?
  3. --/ Better dummy script function to improve compatibility (makes it like you are running the code inside the script.)
  4. --/ Removed Gui In Bottom-Left for when you are making guis.
  5. --/ Removed "Inserting Map Please Wait" gui when selected Workspace as Place to export.
  6. --Credit: PenguinAnonymous for making original script, i just wanted to iron it out to my liking.
  7. --Errors: Camera,Terrain
  8. local runDummyScript = function(f,scri)
  9. if (not scri:IsA('Script')) or (not scri:IsA('LocalScript')) then return false; end;
  10. local Dummy_CoRoutine = coroutine.create(function()
  11. getfenv().script = scri
  12. ypcall(function() f() end)
  13. end)
  14. table.insert(cors,Dummy_CoRoutine);
  15. coroutine.resume(Dummy_CoRoutine);
  16. end
  17. cors = {}
  18. mas = Instance.new("Model",game:GetService("Lighting"))
  19. mas.Name = "M2S_Model"
  20. o3 = Instance.new("Model")
  21. o4 = Instance.new("Model")
  22. o5 = Instance.new("Model")
  23. o6 = Instance.new("Model")
  24. o7 = Instance.new("Part")
  25. o8 = Instance.new("Motor6D")
  26. o9 = Instance.new("Part")
  27. o10 = Instance.new("Motor6D")
  28. o11 = Instance.new("Motor6D")
  29. o12 = Instance.new("Motor6D")
  30. o13 = Instance.new("Motor6D")
  31. o14 = Instance.new("Motor6D")
  32. o15 = Instance.new("Part")
  33. o16 = Instance.new("Part")
  34. o17 = Instance.new("Part")
  35. o18 = Instance.new("Part")
  36. o19 = Instance.new("Part")
  37. o20 = Instance.new("Decal")
  38. o21 = Instance.new("Humanoid")
  39. o22 = Instance.new("Script")
  40. o23 = Instance.new("Script")
  41. o24 = Instance.new("StringValue")
  42. o25 = Instance.new("Animation")
  43. o26 = Instance.new("StringValue")
  44. o27 = Instance.new("Animation")
  45. o28 = Instance.new("StringValue")
  46. o29 = Instance.new("Animation")
  47. o30 = Instance.new("NumberValue")
  48. o31 = Instance.new("Animation")
  49. o32 = Instance.new("NumberValue")
  50. o33 = Instance.new("StringValue")
  51. o34 = Instance.new("Animation")
  52. o35 = Instance.new("StringValue")
  53. o36 = Instance.new("Animation")
  54. o37 = Instance.new("StringValue")
  55. o38 = Instance.new("Animation")
  56. o39 = Instance.new("StringValue")
  57. o40 = Instance.new("Animation")
  58. o41 = Instance.new("StringValue")
  59. o42 = Instance.new("Animation")
  60. o3.Parent = mas
  61. o4.Parent = o3
  62. o5.Parent = o4
  63. o6.Name = "Dummy"
  64. o6.Parent = o5
  65. o6.PrimaryPart = o7
  66. o7.Name = "HumanoidRootPart"
  67. o7.Parent = o6
  68. o7.Material = Enum.Material.Neon
  69. o7.BrickColor = BrickColor.new("Plum")
  70. o7.Transparency = 0.5
  71. o7.Position = Vector3.new(53.5187378, 3.00001311, 33.3681335)
  72. o7.Size = Vector3.new(2, 2, 1)
  73. o7.CFrame = CFrame.new(53.5187378, 3.00001311, 33.3681335, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  74. o7.BottomSurface = Enum.SurfaceType.Smooth
  75. o7.TopSurface = Enum.SurfaceType.Smooth
  76. o7.Color = Color3.new(0.482353, 0.184314, 0.482353)
  77. o7.Position = Vector3.new(53.5187378, 3.00001311, 33.3681335)
  78. o8.Name = "Root Hip"
  79. o8.Parent = o7
  80. o8.C0 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  81. o8.C1 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  82. o8.Part0 = o7
  83. o8.Part1 = o9
  84. o8.MaxVelocity = 0.10000000149012
  85. o9.Name = "Torso"
  86. o9.Parent = o6
  87. o9.Material = Enum.Material.Neon
  88. o9.BrickColor = BrickColor.new("Plum")
  89. o9.Position = Vector3.new(53.5187378, 3.00001311, 33.3681335)
  90. o9.CanCollide = false
  91. o9.Size = Vector3.new(2, 2, 1)
  92. o9.CFrame = CFrame.new(53.5187378, 3.00001311, 33.3681335, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  93. o9.BottomSurface = Enum.SurfaceType.Smooth
  94. o9.TopSurface = Enum.SurfaceType.Smooth
  95. o9.Color = Color3.new(0.482353, 0.184314, 0.482353)
  96. o9.Position = Vector3.new(53.5187378, 3.00001311, 33.3681335)
  97. o10.Name = "Left Hip"
  98. o10.Parent = o9
  99. o10.C0 = CFrame.new(-1, -1, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
  100. o10.C1 = CFrame.new(-0.5, 1, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
  101. o10.Part0 = o9
  102. o10.Part1 = o15
  103. o10.MaxVelocity = 0.10000000149012
  104. o11.Name = "Right Hip"
  105. o11.Parent = o9
  106. o11.C0 = CFrame.new(1, -1, 0, -4.37113883e-08, 0, 1, -0, 0.99999994, 0, -1, 0, -4.37113883e-08)
  107. o11.C1 = CFrame.new(0.5, 1, 0, -4.37113883e-08, 0, 1, 0, 0.99999994, 0, -1, 0, -4.37113883e-08)
  108. o11.Part0 = o9
  109. o11.Part1 = o16
  110. o11.MaxVelocity = 0.10000000149012
  111. o12.Name = "Left Shoulder"
  112. o12.Parent = o9
  113. o12.C0 = CFrame.new(-1, 0.5, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
  114. o12.C1 = CFrame.new(0.5, 0.5, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
  115. o12.Part0 = o9
  116. o12.Part1 = o17
  117. o12.MaxVelocity = 0.10000000149012
  118. o13.Name = "Right Shoulder"
  119. o13.Parent = o9
  120. o13.C0 = CFrame.new(1, 0.5, 0, -4.37113883e-08, 0, 1, -0, 0.99999994, 0, -1, 0, -4.37113883e-08)
  121. o13.C1 = CFrame.new(-0.5, 0.5, 0, -4.37113883e-08, 0, 1, 0, 0.99999994, 0, -1, 0, -4.37113883e-08)
  122. o13.Part0 = o9
  123. o13.Part1 = o18
  124. o13.MaxVelocity = 0.10000000149012
  125. o14.Name = "Neck"
  126. o14.Parent = o9
  127. o14.C0 = CFrame.new(0, 1, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  128. o14.C1 = CFrame.new(0, -0.5, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  129. o14.Part0 = o9
  130. o14.Part1 = o19
  131. o14.MaxVelocity = 0.10000000149012
  132. o15.Name = "Left Leg"
  133. o15.Parent = o6
  134. o15.Material = Enum.Material.Neon
  135. o15.BrickColor = BrickColor.new("Plum")
  136. o15.Position = Vector3.new(53.0187378, 1.00001323, 33.3681335)
  137. o15.CanCollide = false
  138. o15.Size = Vector3.new(1, 2, 1)
  139. o15.CFrame = CFrame.new(53.0187378, 1.00001323, 33.3681335, 1, 0, 0, 0, 0.999999881, 0, 0, 0, 1)
  140. o15.BottomSurface = Enum.SurfaceType.Smooth
  141. o15.TopSurface = Enum.SurfaceType.Smooth
  142. o15.Color = Color3.new(0.482353, 0.184314, 0.482353)
  143. o15.Position = Vector3.new(53.0187378, 1.00001323, 33.3681335)
  144. o16.Name = "Right Leg"
  145. o16.Parent = o6
  146. o16.Material = Enum.Material.Neon
  147. o16.BrickColor = BrickColor.new("Plum")
  148. o16.Position = Vector3.new(54.0187378, 1.00001323, 33.3681335)
  149. o16.CanCollide = false
  150. o16.Size = Vector3.new(1, 2, 1)
  151. o16.CFrame = CFrame.new(54.0187378, 1.00001323, 33.3681335, 1, 0, 0, 0, 0.999999881, 0, 0, 0, 1)
  152. o16.BottomSurface = Enum.SurfaceType.Smooth
  153. o16.TopSurface = Enum.SurfaceType.Smooth
  154. o16.Color = Color3.new(0.482353, 0.184314, 0.482353)
  155. o16.Position = Vector3.new(54.0187378, 1.00001323, 33.3681335)
  156. o17.Name = "Left Arm"
  157. o17.Parent = o6
  158. o17.Material = Enum.Material.Neon
  159. o17.BrickColor = BrickColor.new("Plum")
  160. o17.Position = Vector3.new(52.0187378, 3.00001311, 33.3681335)
  161. o17.CanCollide = false
  162. o17.Size = Vector3.new(1, 2, 1)
  163. o17.CFrame = CFrame.new(52.0187378, 3.00001311, 33.3681335, 1, 0, 0, 0, 0.999999881, 0, 0, 0, 1)
  164. o17.BottomSurface = Enum.SurfaceType.Smooth
  165. o17.TopSurface = Enum.SurfaceType.Smooth
  166. o17.Color = Color3.new(0.482353, 0.184314, 0.482353)
  167. o17.Position = Vector3.new(52.0187378, 3.00001311, 33.3681335)
  168. o18.Name = "Right Arm"
  169. o18.Parent = o6
  170. o18.Material = Enum.Material.Neon
  171. o18.BrickColor = BrickColor.new("Plum")
  172. o18.Position = Vector3.new(55.0187378, 3.00001311, 33.3681335)
  173. o18.CanCollide = false
  174. o18.Size = Vector3.new(1, 2, 1)
  175. o18.CFrame = CFrame.new(55.0187378, 3.00001311, 33.3681335, 1, 0, 0, 0, 0.999999881, 0, 0, 0, 1)
  176. o18.BottomSurface = Enum.SurfaceType.Smooth
  177. o18.TopSurface = Enum.SurfaceType.Smooth
  178. o18.Color = Color3.new(0.482353, 0.184314, 0.482353)
  179. o18.Position = Vector3.new(55.0187378, 3.00001311, 33.3681335)
  180. o19.Name = "Head"
  181. o19.Parent = o6
  182. o19.Material = Enum.Material.Neon
  183. o19.BrickColor = BrickColor.new("Plum")
  184. o19.Position = Vector3.new(53.5187378, 4.50001335, 33.3681335)
  185. o19.Size = Vector3.new(2, 1, 1)
  186. o19.CFrame = CFrame.new(53.5187378, 4.50001335, 33.3681335, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  187. o19.BottomSurface = Enum.SurfaceType.Smooth
  188. o19.TopSurface = Enum.SurfaceType.Smooth
  189. o19.Color = Color3.new(0.482353, 0.184314, 0.482353)
  190. o19.Position = Vector3.new(53.5187378, 4.50001335, 33.3681335)
  191. o20.Name = "Face"
  192. o20.Parent = o19
  193. o20.Texture = "rbxasset://textures/face.png"
  194. o21.Parent = o6
  195. o21.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
  196. o21.RightLeg = o16
  197. o21.LeftLeg = o15
  198. o21.Torso = o7
  199. o21.WalkSpeed = 14
  200. o22.Name = "AI"
  201. o22.Parent = o6
  202.  
  203. runDummyScript(function()
  204. --DuruTeru
  205. --[[
  206.  
  207. ____________________________________________________________________________________________________________________
  208.  
  209. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  210. ____________________________________________________________________________________________________________________
  211. ___ ___
  212. ( ) ( ) .-.
  213. .--. .--. | |_ | |_ ( __) ___ .-. .--. .--.
  214. / _ \ / \ ( __) ( __) (''") ( ) \ / \ / _ \
  215. . .' `. ; | .-. ; | | | | | | | .-. . ; ,-. ' . .' `. ;
  216. | ' | | | | | | | | ___ | | ___ | | | | | | | | | | | ' | |
  217. _\_`.(___) | |/ | | |( ) | |( ) | | | | | | | | | | _\_`.(___)
  218. ( ). '. | ' _.' | | | | | | | | | | | | | | | | | | ( ). '.
  219. | | `\ | | .'.-. | ' | | | ' | | | | | | | | | ' | | | | `\ |
  220. ; '._,' ' ' `-' / ' `-' ; ' `-' ; | | | | | | ' `-' | ; '._,' '
  221. '.___.' `.__.' `.__. `.__. (___) (___)(___) `.__. | '.___.'
  222. ( `-' ;
  223. `.__.
  224. ____________________________________________________________________________________________________________________
  225.  
  226. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  227. ____________________________________________________________________________________________________________________
  228.  
  229. --]]
  230.  
  231.  
  232. local SearchDistance = 1500000 -- How far a player can be before it detects you
  233.  
  234. local ZombieDamage = 30 -- How much damage the Zombie inficts towards the player
  235.  
  236. --[[
  237.  
  238. ____________________________________________________________________________________________________________________
  239.  
  240. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  241. ____________________________________________________________________________________________________________________
  242.  
  243. -- OPTIONAL --]]
  244.  
  245. local canWander = false
  246. local WanderX, WanderZ = 30, 30
  247. -- How many studs the zombie can wander on the x and z axis in studs
  248.  
  249. --]]
  250.  
  251.  
  252. function getHumanoid(model)
  253. for _, v in pairs(model:GetChildren()) do
  254. if v:IsA'Humanoid' then
  255. return v
  256. end
  257. end
  258. end
  259.  
  260.  
  261. local zombie = script.Parent
  262. local human = getHumanoid(zombie)
  263. local hroot = zombie.HumanoidRootPart
  264. local zspeed = hroot.Velocity.magnitude
  265.  
  266.  
  267. local pfs = game:GetService("PathfindingService")
  268.  
  269. function GetPlayerNames()
  270. local players = game:GetService('Players'):GetChildren()
  271. local name = nil
  272. for _, v in pairs(players) do
  273. if v:IsA'Player' then
  274. name = tostring(v.Name)
  275. end
  276. end
  277. return name
  278. end
  279.  
  280. function GetPlayersBodyParts(t)
  281. local torso = t
  282. if torso then
  283. local form = torso.Parent
  284. for _, v in pairs(form:GetChildren()) do
  285. if v:IsA'Part' then
  286. return v.Name
  287. end
  288. end
  289. else
  290. return "HumanoidRootPart"
  291. end
  292. end
  293.  
  294. function GetTorso(part)
  295. local chars = game.Workspace:GetChildren()
  296. local torso = nil
  297. for _, v in pairs(chars) do
  298. if v:IsA'Model' and v ~= script.Parent and v.Name == GetPlayerNames() then
  299. local charRoot = v:FindFirstChild'HumanoidRootPart'
  300. if (charRoot.Position - part).magnitude < SearchDistance then
  301. torso = charRoot
  302. end
  303. end
  304. end
  305. return torso
  306. end
  307.  
  308. for _, zambieparts in pairs(zombie:GetChildren()) do
  309. if zambieparts:IsA'Part' then
  310. zambieparts.Touched:connect(function(p)
  311. if p.Parent.Name == GetPlayerNames() and p.Parent.Name ~= zombie.Name then -- damage
  312. local enemy = p.Parent
  313. local enemyhuman = getHumanoid(enemy)
  314. enemyhuman:TakeDamage(ZombieDamage)
  315. end
  316. end)
  317. end
  318. end
  319.  
  320. -- no touchy
  321. local path
  322. local waypoint
  323. local oldpoints
  324. local isWandering = 0
  325.  
  326. if canWander then
  327. spawn(function()
  328. while isWandering == 0 do
  329. isWandering = 1
  330. local desgx, desgz = hroot.Position.x + math.random(-WanderX, WanderX), hroot.Position.z + math.random(-WanderZ, WanderZ)
  331. human:MoveTo( Vector3.new(desgx, 0, desgz) )
  332. wait(math.random(4, 6))
  333. isWandering = 0
  334. end
  335. end)
  336. end
  337.  
  338. while wait() do
  339. local enemytorso = GetTorso(hroot.Position)
  340. if enemytorso ~= nil then -- if player detected
  341. isWandering = 1
  342. local function checkw(t)
  343. local ci = 3
  344. if ci > #t then
  345. ci = 3
  346. end
  347. if t[ci] == nil and ci < #t then
  348. repeat
  349. ci = ci + 1
  350. wait()
  351. until t[ci] ~= nil
  352. return Vector3.new(1, 0, 0) + t[ci]
  353. else
  354. ci = 3
  355. return t[ci]
  356. end
  357. end
  358.  
  359. path = pfs:FindPathAsync(hroot.Position, enemytorso.Position)
  360. waypoint = path:GetWaypoints()
  361. oldpoints = waypoint
  362. local connection;
  363.  
  364. local direct = Vector3.FromNormalId(Enum.NormalId.Front)
  365. local ncf = hroot.CFrame * CFrame.new(direct)
  366. direct = ncf.p.unit
  367. local rootr = Ray.new(hroot.Position, direct)
  368. local phit, ppos = game.Workspace:FindPartOnRay(rootr, hroot)
  369.  
  370. if path and waypoint or checkw(waypoint) then
  371. if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Walk then
  372. human:MoveTo( checkw(waypoint).Position )
  373. human.Jump = false
  374. end
  375.  
  376. if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Jump then
  377. human.Jump = true
  378. connection = human.Changed:connect(function()
  379. human.Jump = true
  380. end)
  381. human:MoveTo( checkw(waypoint).Position )
  382. else
  383. human.Jump = false
  384. end
  385.  
  386. hroot.Touched:connect(function(p)
  387. local bodypartnames = GetPlayersBodyParts(enemytorso)
  388. if p:IsA'Part' and not p.Name == bodypartnames and phit and phit.Name ~= bodypartnames and phit:IsA'Part' and rootr:Distance(phit.Position) < 5 then
  389. connection = human.Changed:connect(function()
  390. human.Jump = true
  391. end)
  392. else
  393. human.Jump = false
  394. end
  395. end)
  396.  
  397. if connection then
  398. connection:Disconnect()
  399. end
  400.  
  401. else
  402. for i = 3, #oldpoints do
  403. human:MoveTo( oldpoints[i].Position )
  404. end
  405. end
  406. elseif enemytorso == nil and canWander then -- if player not detected
  407. isWandering = 0
  408. path = nil
  409. waypoint = nil
  410. human.MoveToFinished:Wait()
  411. end
  412. end
  413. end,o22)
  414.  
  415. o23.Name = "Animate"
  416. o23.Parent = o6
  417.  
  418. runDummyScript(function()
  419. -- This is in charge of the animations for the character. Pretty much stole it from the default character. Removed emote stuff.
  420. function waitForChild(parent, childName)
  421. local child = parent:findFirstChild(childName)
  422. if child then return child end
  423. while true do
  424. child = parent.ChildAdded:wait()
  425. if child.Name==childName then return child end
  426. end
  427. end
  428.  
  429. local Figure = script.Parent
  430. local Torso = waitForChild(Figure, "Torso")
  431. local RightShoulder = waitForChild(Torso, "Right Shoulder")
  432. local LeftShoulder = waitForChild(Torso, "Left Shoulder")
  433. local RightHip = waitForChild(Torso, "Right Hip")
  434. local LeftHip = waitForChild(Torso, "Left Hip")
  435. local Neck = waitForChild(Torso, "Neck")
  436. local Humanoid = waitForChild(Figure, "Humanoid")
  437. local pose = "Standing"
  438.  
  439. local currentAnim = ""
  440. local currentAnimInstance = nil
  441. local currentAnimTrack = nil
  442. local currentAnimKeyframeHandler = nil
  443. local currentAnimSpeed = 1.0
  444. local animTable = {}
  445. local animNames = {
  446. idle = {
  447. { id = "http://www.roblox.com/asset/?id=180435571", weight = 9 },
  448. { id = "http://www.roblox.com/asset/?id=180435792", weight = 1 }
  449. },
  450. walk = {
  451. { id = "http://www.roblox.com/asset/?id=180426354", weight = 10 }
  452. },
  453. run = {
  454. { id = "run.xml", weight = 10 }
  455. },
  456. jump = {
  457. { id = "http://www.roblox.com/asset/?id=125750702", weight = 10 }
  458. },
  459. fall = {
  460. { id = "http://www.roblox.com/asset/?id=180436148", weight = 10 }
  461. },
  462. climb = {
  463. { id = "http://www.roblox.com/asset/?id=180436334", weight = 10 }
  464. },
  465. sit = {
  466. { id = "http://www.roblox.com/asset/?id=178130996", weight = 10 }
  467. },
  468. toolnone = {
  469. { id = "http://www.roblox.com/asset/?id=182393478", weight = 10 }
  470. },
  471. toolslash = {
  472. { id = "http://www.roblox.com/asset/?id=129967390", weight = 10 }
  473. -- { id = "slash.xml", weight = 10 }
  474. },
  475. toollunge = {
  476. { id = "http://www.roblox.com/asset/?id=129967478", weight = 10 }
  477. },
  478. wave = {
  479. { id = "http://www.roblox.com/asset/?id=128777973", weight = 10 }
  480. },
  481. point = {
  482. { id = "http://www.roblox.com/asset/?id=128853357", weight = 10 }
  483. },
  484. dance = {
  485. { id = "http://www.roblox.com/asset/?id=182435998", weight = 10 },
  486. { id = "http://www.roblox.com/asset/?id=182491037", weight = 10 },
  487. { id = "http://www.roblox.com/asset/?id=182491065", weight = 10 }
  488. },
  489. dance2 = {
  490. { id = "http://www.roblox.com/asset/?id=182436842", weight = 10 },
  491. { id = "http://www.roblox.com/asset/?id=182491248", weight = 10 },
  492. { id = "http://www.roblox.com/asset/?id=182491277", weight = 10 }
  493. },
  494. dance3 = {
  495. { id = "http://www.roblox.com/asset/?id=182436935", weight = 10 },
  496. { id = "http://www.roblox.com/asset/?id=182491368", weight = 10 },
  497. { id = "http://www.roblox.com/asset/?id=182491423", weight = 10 }
  498. },
  499. laugh = {
  500. { id = "http://www.roblox.com/asset/?id=129423131", weight = 10 }
  501. },
  502. cheer = {
  503. { id = "http://www.roblox.com/asset/?id=129423030", weight = 10 }
  504. },
  505. }
  506.  
  507. math.randomseed(tick())
  508.  
  509. function configureAnimationSet(name, fileList)
  510. if (animTable[name] ~= nil) then
  511. for _, connection in pairs(animTable[name].connections) do
  512. connection:disconnect()
  513. end
  514. end
  515. animTable[name] = {}
  516. animTable[name].count = 0
  517. animTable[name].totalWeight = 0
  518. animTable[name].connections = {}
  519.  
  520. -- check for config values
  521. local config = script:FindFirstChild(name)
  522. if (config ~= nil) then
  523. -- print("Loading anims " .. name)
  524. table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
  525. table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
  526. local idx = 1
  527. for _, childPart in pairs(config:GetChildren()) do
  528. if (childPart:IsA("Animation")) then
  529. table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
  530. animTable[name][idx] = {}
  531. animTable[name][idx].anim = childPart
  532. local weightObject = childPart:FindFirstChild("Weight")
  533. if (weightObject == nil) then
  534. animTable[name][idx].weight = 1
  535. else
  536. animTable[name][idx].weight = weightObject.Value
  537. end
  538. animTable[name].count = animTable[name].count + 1
  539. animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  540. -- print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
  541. idx = idx + 1
  542. end
  543. end
  544. end
  545.  
  546. -- fallback to defaults
  547. if (animTable[name].count <= 0) then
  548. for idx, anim in pairs(fileList) do
  549. animTable[name][idx] = {}
  550. animTable[name][idx].anim = Instance.new("Animation")
  551. animTable[name][idx].anim.Name = name
  552. animTable[name][idx].anim.AnimationId = anim.id
  553. animTable[name][idx].weight = anim.weight
  554. animTable[name].count = animTable[name].count + 1
  555. animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  556. -- print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
  557. end
  558. end
  559. end
  560.  
  561. -- Setup animation objects
  562. function scriptChildModified(child)
  563. local fileList = animNames[child.Name]
  564. if (fileList ~= nil) then
  565. configureAnimationSet(child.Name, fileList)
  566. end
  567. end
  568.  
  569. script.ChildAdded:connect(scriptChildModified)
  570. script.ChildRemoved:connect(scriptChildModified)
  571.  
  572.  
  573. for name, fileList in pairs(animNames) do
  574. configureAnimationSet(name, fileList)
  575. end
  576.  
  577. -- ANIMATION
  578.  
  579. -- declarations
  580. local toolAnim = "None"
  581. local toolAnimTime = 0
  582.  
  583. local jumpAnimTime = 0
  584. local jumpAnimDuration = 0.3
  585.  
  586. local toolTransitionTime = 0.1
  587. local fallTransitionTime = 0.3
  588. local jumpMaxLimbVelocity = 0.75
  589.  
  590. -- functions
  591.  
  592. function stopAllAnimations()
  593. local oldAnim = currentAnim
  594.  
  595. currentAnim = ""
  596. currentAnimInstance = nil
  597. if (currentAnimKeyframeHandler ~= nil) then
  598. currentAnimKeyframeHandler:disconnect()
  599. end
  600.  
  601. if (currentAnimTrack ~= nil) then
  602. currentAnimTrack:Stop()
  603. currentAnimTrack:Destroy()
  604. currentAnimTrack = nil
  605. end
  606. return oldAnim
  607. end
  608.  
  609. function setAnimationSpeed(speed)
  610. if speed ~= currentAnimSpeed then
  611. currentAnimSpeed = speed
  612. currentAnimTrack:AdjustSpeed(currentAnimSpeed)
  613. end
  614. end
  615.  
  616. function keyFrameReachedFunc(frameName)
  617. if (frameName == "End") then
  618. -- print("Keyframe : ".. frameName)
  619.  
  620. local repeatAnim = currentAnim
  621.  
  622. local animSpeed = currentAnimSpeed
  623. playAnimation(repeatAnim, 0.0, Humanoid)
  624. setAnimationSpeed(animSpeed)
  625. end
  626. end
  627.  
  628. -- Preload animations
  629. function playAnimation(animName, transitionTime, humanoid)
  630.  
  631. local roll = math.random(1, animTable[animName].totalWeight)
  632. local origRoll = roll
  633. local idx = 1
  634. while (roll > animTable[animName][idx].weight) do
  635. roll = roll - animTable[animName][idx].weight
  636. idx = idx + 1
  637. end
  638. -- print(animName .. " " .. idx .. " [" .. origRoll .. "]")
  639. local anim = animTable[animName][idx].anim
  640.  
  641. -- switch animation
  642. if (anim ~= currentAnimInstance) then
  643.  
  644. if (currentAnimTrack ~= nil) then
  645. currentAnimTrack:Stop(transitionTime)
  646. currentAnimTrack:Destroy()
  647. end
  648.  
  649. currentAnimSpeed = 1.0
  650.  
  651. -- load it to the humanoid; get AnimationTrack
  652. currentAnimTrack = humanoid:LoadAnimation(anim)
  653.  
  654. -- play the animation
  655. currentAnimTrack:Play(transitionTime)
  656. currentAnim = animName
  657. currentAnimInstance = anim
  658.  
  659. -- set up keyframe name triggers
  660. if (currentAnimKeyframeHandler ~= nil) then
  661. currentAnimKeyframeHandler:disconnect()
  662. end
  663. currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
  664.  
  665. end
  666.  
  667. end
  668.  
  669. -------------------------------------------------------------------------------------------
  670. -------------------------------------------------------------------------------------------
  671.  
  672. local toolAnimName = ""
  673. local toolAnimTrack = nil
  674. local toolAnimInstance = nil
  675. local currentToolAnimKeyframeHandler = nil
  676.  
  677. function toolKeyFrameReachedFunc(frameName)
  678. if (frameName == "End") then
  679. -- print("Keyframe : ".. frameName)
  680. playToolAnimation(toolAnimName, 0.0, Humanoid)
  681. end
  682. end
  683.  
  684.  
  685. function playToolAnimation(animName, transitionTime, humanoid)
  686.  
  687. local roll = math.random(1, animTable[animName].totalWeight)
  688. local origRoll = roll
  689. local idx = 1
  690. while (roll > animTable[animName][idx].weight) do
  691. roll = roll - animTable[animName][idx].weight
  692. idx = idx + 1
  693. end
  694. -- print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
  695. local anim = animTable[animName][idx].anim
  696.  
  697. if (toolAnimInstance ~= anim) then
  698.  
  699. if (toolAnimTrack ~= nil) then
  700. toolAnimTrack:Stop()
  701. toolAnimTrack:Destroy()
  702. transitionTime = 0
  703. end
  704.  
  705. -- load it to the humanoid; get AnimationTrack
  706. toolAnimTrack = humanoid:LoadAnimation(anim)
  707.  
  708. -- play the animation
  709. toolAnimTrack:Play(transitionTime)
  710. toolAnimName = animName
  711. toolAnimInstance = anim
  712.  
  713. currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
  714. end
  715. end
  716.  
  717. function stopToolAnimations()
  718. local oldAnim = toolAnimName
  719.  
  720. if (currentToolAnimKeyframeHandler ~= nil) then
  721. currentToolAnimKeyframeHandler:disconnect()
  722. end
  723.  
  724. toolAnimName = ""
  725. toolAnimInstance = nil
  726. if (toolAnimTrack ~= nil) then
  727. toolAnimTrack:Stop()
  728. toolAnimTrack:Destroy()
  729. toolAnimTrack = nil
  730. end
  731.  
  732.  
  733. return oldAnim
  734. end
  735.  
  736. -------------------------------------------------------------------------------------------
  737. -------------------------------------------------------------------------------------------
  738.  
  739.  
  740. function onRunning(speed)
  741. if speed>0.01 then
  742. playAnimation("walk", 0.1, Humanoid)
  743. pose = "Running"
  744. else
  745. playAnimation("idle", 0.1, Humanoid)
  746. pose = "Standing"
  747. end
  748. end
  749.  
  750. function onDied()
  751. pose = "Dead"
  752. end
  753.  
  754. function onJumping()
  755. playAnimation("jump", 0.1, Humanoid)
  756. jumpAnimTime = jumpAnimDuration
  757. pose = "Jumping"
  758. end
  759.  
  760. function onClimbing(speed)
  761. playAnimation("climb", 0.1, Humanoid)
  762. setAnimationSpeed(speed / 12.0)
  763. pose = "Climbing"
  764. end
  765.  
  766. function onGettingUp()
  767. pose = "GettingUp"
  768. end
  769.  
  770. function onFreeFall()
  771. if (jumpAnimTime <= 0) then
  772. playAnimation("fall", fallTransitionTime, Humanoid)
  773. end
  774. pose = "FreeFall"
  775. end
  776.  
  777. function onFallingDown()
  778. pose = "FallingDown"
  779. end
  780.  
  781. function onSeated()
  782. pose = "Seated"
  783. end
  784.  
  785. function onPlatformStanding()
  786. pose = "PlatformStanding"
  787. end
  788.  
  789. function onSwimming(speed)
  790. if speed>0 then
  791. pose = "Running"
  792. else
  793. pose = "Standing"
  794. end
  795. end
  796.  
  797. function getTool()
  798. for _, kid in ipairs(Figure:GetChildren()) do
  799. if kid.className == "Tool" then return kid end
  800. end
  801. return nil
  802. end
  803.  
  804. function getToolAnim(tool)
  805. for _, c in ipairs(tool:GetChildren()) do
  806. if c.Name == "toolanim" and c.className == "StringValue" then
  807. return c
  808. end
  809. end
  810. return nil
  811. end
  812.  
  813. function animateTool()
  814.  
  815. if (toolAnim == "None") then
  816. playToolAnimation("toolnone", toolTransitionTime, Humanoid)
  817. return
  818. end
  819.  
  820. if (toolAnim == "Slash") then
  821. playToolAnimation("toolslash", 0, Humanoid)
  822. return
  823. end
  824.  
  825. if (toolAnim == "Lunge") then
  826. playToolAnimation("toollunge", 0, Humanoid)
  827. return
  828. end
  829. end
  830.  
  831. function moveSit()
  832. RightShoulder.MaxVelocity = 0.15
  833. LeftShoulder.MaxVelocity = 0.15
  834. RightShoulder:SetDesiredAngle(3.14 /2)
  835. LeftShoulder:SetDesiredAngle(-3.14 /2)
  836. RightHip:SetDesiredAngle(3.14 /2)
  837. LeftHip:SetDesiredAngle(-3.14 /2)
  838. end
  839.  
  840. local lastTick = 0
  841.  
  842. function move(time)
  843. local amplitude = 1
  844. local frequency = 1
  845. local deltaTime = time - lastTick
  846. lastTick = time
  847.  
  848. local climbFudge = 0
  849. local setAngles = false
  850.  
  851. if (jumpAnimTime > 0) then
  852. jumpAnimTime = jumpAnimTime - deltaTime
  853. end
  854.  
  855. if (pose == "FreeFall" and jumpAnimTime <= 0) then
  856. playAnimation("fall", fallTransitionTime, Humanoid)
  857. elseif (pose == "Seated") then
  858. playAnimation("sit", 0.5, Humanoid)
  859. return
  860. elseif (pose == "Running") then
  861. playAnimation("walk", 0.1, Humanoid)
  862. elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
  863. -- print("Wha " .. pose)
  864. stopAllAnimations()
  865. amplitude = 0.1
  866. frequency = 1
  867. setAngles = true
  868. end
  869.  
  870. if (setAngles) then
  871. desiredAngle = amplitude * math.sin(time * frequency)
  872.  
  873. RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
  874. LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
  875. RightHip:SetDesiredAngle(-desiredAngle)
  876. LeftHip:SetDesiredAngle(-desiredAngle)
  877. end
  878.  
  879. -- Tool Animation handling
  880. local tool = getTool()
  881. if tool then
  882.  
  883. animStringValueObject = getToolAnim(tool)
  884.  
  885. if animStringValueObject then
  886. toolAnim = animStringValueObject.Value
  887. -- message recieved, delete StringValue
  888. animStringValueObject.Parent = nil
  889. toolAnimTime = time + .3
  890. end
  891.  
  892. if time > toolAnimTime then
  893. toolAnimTime = 0
  894. toolAnim = "None"
  895. end
  896.  
  897. animateTool()
  898. else
  899. stopToolAnimations()
  900. toolAnim = "None"
  901. toolAnimInstance = nil
  902. toolAnimTime = 0
  903. end
  904. end
  905.  
  906. -- connect events
  907. Humanoid.Died:connect(onDied)
  908. Humanoid.Running:connect(onRunning)
  909. Humanoid.Jumping:connect(onJumping)
  910. Humanoid.Climbing:connect(onClimbing)
  911. Humanoid.GettingUp:connect(onGettingUp)
  912. Humanoid.FreeFalling:connect(onFreeFall)
  913. Humanoid.FallingDown:connect(onFallingDown)
  914. Humanoid.Seated:connect(onSeated)
  915. Humanoid.PlatformStanding:connect(onPlatformStanding)
  916. Humanoid.Swimming:connect(onSwimming)
  917.  
  918.  
  919. -- main program
  920.  
  921. local runService = game:service("RunService");
  922.  
  923. -- initialize to idle
  924. playAnimation("idle", 0.1, Humanoid)
  925. pose = "Standing"
  926.  
  927. while Figure.Parent~=nil do
  928. local _, time = wait(0.1)
  929. move(time)
  930. end
  931.  
  932.  
  933.  
  934. end,o23)
  935.  
  936. o24.Name = "climb"
  937. o24.Parent = o23
  938. o25.Name = "ClimbAnim"
  939. o25.Parent = o24
  940. o25.AnimationId = "http://www.roblox.com/asset/?id=180436334"
  941. o26.Name = "fall"
  942. o26.Parent = o23
  943. o27.Name = "FallAnim"
  944. o27.Parent = o26
  945. o27.AnimationId = "http://www.roblox.com/asset/?id=180436148"
  946. o28.Name = "idle"
  947. o28.Parent = o23
  948. o29.Name = "Animation1"
  949. o29.Parent = o28
  950. o29.AnimationId = "http://www.roblox.com/asset/?id=180435571"
  951. o30.Name = "Weight"
  952. o30.Parent = o29
  953. o30.Value = 9
  954. o31.Name = "Animation2"
  955. o31.Parent = o28
  956. o31.AnimationId = "http://www.roblox.com/asset/?id=180435792"
  957. o32.Name = "Weight"
  958. o32.Parent = o31
  959. o32.Value = 1
  960. o33.Name = "jump"
  961. o33.Parent = o23
  962. o34.Name = "JumpAnim"
  963. o34.Parent = o33
  964. o34.AnimationId = "http://www.roblox.com/asset/?id=125750702"
  965. o35.Name = "run"
  966. o35.Parent = o23
  967. o36.Name = "RunAnim"
  968. o36.Parent = o35
  969. o36.AnimationId = "http://www.roblox.com/asset/?id=180426354"
  970. o37.Name = "sit"
  971. o37.Parent = o23
  972. o38.Name = "SitAnim"
  973. o38.Parent = o37
  974. o38.AnimationId = "http://www.roblox.com/asset/?id=178130996"
  975. o39.Name = "toolnone"
  976. o39.Parent = o23
  977. o40.Name = "ToolNoneAnim"
  978. o40.Parent = o39
  979. o40.AnimationId = "http://www.roblox.com/asset/?id=182393478"
  980. o41.Name = "walk"
  981. o41.Parent = o23
  982. o42.Name = "WalkAnim"
  983. o42.Parent = o41
  984. o42.AnimationId = "http://www.roblox.com/asset/?id=180426354"
  985. mas.Parent = workspace
  986. mas:MakeJoints()
  987. local mas1 = mas:GetChildren()
  988. for i=1,#mas1 do
  989. mas1[i].Parent = script
  990. ypcall(function() mas1[i]:MakeJoints() end)
  991. end
  992. mas:Destroy()
  993. for i=1,#cors do
  994. coroutine.resume(cors[i])
  995. end
  996. mess_handle.Text = "Resetting"
  997. for i,v in pairs(game:GetService("Players"):GetPlayers()) do
  998. v:LoadCharacter()
  999. end
  1000. wait(1)
  1001. mess_handle:Remove()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement