Advertisement
D_rawest16

Untitled

Jan 18th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. local module = {}
  2. function module:Movement(list)
  3. local hum = list.Hum
  4. local npctype = list.NpcType
  5. local root = list.Root
  6. local dist = list.Dist
  7. local AttackDist = list.AttackDist
  8. local StopDist = list.StopDist
  9. local ComboNum = list.MaxComboNum
  10. local torso = nil
  11. local clone = hum:Clone()
  12. local pos = root.Position
  13. local function AttackMethod(details)
  14. local find = script:FindFirstChild(npctype)
  15. if find then
  16. local mod2 = require(find)
  17. mod2:Attack(details)
  18. end
  19. end
  20. -- Adding Combat Values
  21. local DFV = Instance.new("Folder",hum.Parent)
  22. local function newins(name,typ,val)
  23. local new = Instance.new(typ)
  24. new.Name = name
  25. new.Value = val
  26. new.Parent = DFV
  27. return new
  28. end
  29.  
  30. local CanAttck = newins('CanAttack','BoolValue',true)
  31.  
  32. --attackin anim(only need 1 i can just keep updating the animid)
  33. local anim = Instance.new("Animation")
  34.  
  35. -- Animation tracking stuff
  36. local num = 0
  37. local ComboCoolDown = 1
  38. local function NumSystem()
  39. if npctype == 'CloseCombat' then
  40. if CanAttck.Value == true then
  41. if num >= ComboNum then
  42. CanAttck.Value = false
  43. delay(ComboCoolDown,function()
  44. CanAttck.Value = true
  45. end)
  46. else
  47. num = num + 1
  48. end
  49. else
  50. num = 0
  51. end
  52. end
  53. end
  54. local function move()
  55. NumSystem()
  56. local enemyhum = nil
  57. local enemyroot = nil
  58. local Funcdb = false
  59. for i,v in pairs(game.Workspace:GetChildren()) do
  60. if v:IsA("Model") then
  61. enemyhum = v:FindFirstChild("Humanoid")
  62. enemyroot = v:FindFirstChild("HumanoidRootPart")
  63. if enemyhum and enemyroot and enemyhum ~= hum then
  64. if enemyhum.Health ~= 0 and hum.Health ~= 0 then
  65. if torso == nil then
  66. if (enemyroot.Position - root.Position).Magnitude <= dist then
  67. torso = enemyroot
  68. AttackMethod(
  69. {
  70. ['Hum'] = hum;
  71. ['Dist'] = dist;
  72. ['AttackDist'] = AttackDist;
  73. ['StopDist'] = StopDist;
  74. ['Far'] = (torso.Position - root.Position).Magnitude;
  75. ['Num'] = num;
  76. ['AttackAnim'] = anim;
  77. ['CanAttack'] = CanAttck.Value
  78. }
  79. )
  80. end
  81. elseif torso ~= nil then
  82. if (enemyroot.Position - root.Position).Magnitude < (root.Position - torso.Position).Magnitude and not Funcdb then
  83. Funcdb = false
  84. torso = enemyroot
  85. AttackMethod(
  86. {
  87. ['Hum'] = hum;
  88. ['Dist'] = dist;
  89. ['AttackDist'] = AttackDist;
  90. ['StopDist'] = StopDist;
  91. ['Far'] = (torso.Position - root.Position).Magnitude;
  92. ['Num'] = num;
  93. ['AttackAnim'] = anim;
  94. ['CanAttack'] = CanAttck.Value
  95. }
  96. )
  97. end
  98. end
  99. end
  100. end
  101. end
  102. end
  103. if torso ~= nil then
  104. if (root.Position - torso.Position).Magnitude > dist then
  105. torso = nil
  106. end
  107. if not Funcdb then
  108. AttackMethod(
  109. {
  110. ['Hum'] = hum;
  111. ['Dist'] = dist;
  112. ['AttackDist'] = AttackDist;
  113. ['StopDist'] = StopDist;
  114. ['Far'] = (torso.Position - root.Position).Magnitude;
  115. ['Num'] = num;
  116. ['AttackAnim'] = anim;
  117. ['CanAttack'] = CanAttck.Value
  118. }
  119. )
  120.  
  121. end
  122. end
  123. return torso
  124. end
  125. local mod2 = require(game.ServerScriptService.ModuleScripts.CollisionGroup.CantTouchModels)
  126. mod2:phy(hum.Parent)
  127. hum.Died:Connect(function()
  128. wait(2)
  129. hum.Parent:Destroy()
  130. wait(5)
  131. clone:WaitForChild("HumanoidRootPart").Position = pos
  132. clone.Parent = hum.Parent
  133. end)
  134. while wait(0.3) do
  135. local target = move()
  136. if move ~= nil then
  137. hum:MoveTo(target.Position,target)
  138. else
  139. hum:MoveTo(root.Position)
  140. end
  141. end
  142. end
  143. return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement