Hasli4

Untitled

Oct 4th, 2026
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 KB | None | 0 0
  1. local pirate = script.Parent
  2. local humanoid = pirate:WaitForChild("Humanoid")
  3. local rootPart = pirate:WaitForChild("HumanoidRootPart")
  4.  
  5. local npcFolder = workspace:WaitForChild("NPC")
  6. local dataFolder = workspace:WaitForChild("Data")
  7.  
  8. local attackSpeedValue = npcFolder:WaitForChild("Attackspeed")
  9. local playerValue = dataFolder:WaitForChild("Player")
  10.  
  11. local sword = pirate:WaitForChild("ClassicSword")
  12.  
  13. local ATTACK_DISTANCE = 6
  14. local DAMAGE = 10
  15. local HIT_DELAY = 0.25
  16.  
  17. --------------------------------------------------
  18. -- ANIMATOR
  19. --------------------------------------------------
  20.  
  21. local animator = humanoid:FindFirstChildOfClass("Animator")
  22.  
  23. if not animator then
  24. animator = Instance.new("Animator")
  25. animator.Parent = humanoid
  26. end
  27.  
  28. --------------------------------------------------
  29. -- ПОИСК АНИМАЦИИ АТАКИ
  30. --------------------------------------------------
  31.  
  32. local animateScript = pirate:FindFirstChild("Animate")
  33. local attackAnimation = nil
  34.  
  35. local function searchAttackAnimation()
  36.  
  37. if not animateScript then
  38. return nil
  39. end
  40.  
  41. -- Ищем объект toolslash
  42. local toolSlash = animateScript:FindFirstChild("toolslash")
  43.  
  44. if toolSlash then
  45.  
  46. -- Ищем Animation внутри toolslash
  47. for _, object in ipairs(toolSlash:GetDescendants()) do
  48.  
  49. if object:IsA("Animation") then
  50. return object
  51. end
  52.  
  53. end
  54.  
  55. end
  56.  
  57. -- Ищем Animation с подходящим названием
  58. for _, object in ipairs(animateScript:GetDescendants()) do
  59.  
  60. if object:IsA("Animation") then
  61.  
  62. local name = object.Name:lower()
  63.  
  64. if string.find(name, "slash")
  65. or string.find(name, "attack") then
  66.  
  67. return object
  68.  
  69. end
  70.  
  71. end
  72.  
  73. end
  74.  
  75. return nil
  76.  
  77. end
  78.  
  79. attackAnimation = searchAttackAnimation()
  80.  
  81. --------------------------------------------------
  82. -- ЗАГРУЖАЕМ АТАКУ
  83. --------------------------------------------------
  84.  
  85. local attackTrack = nil
  86.  
  87. if attackAnimation then
  88.  
  89. attackTrack = animator:LoadAnimation(attackAnimation)
  90.  
  91. attackTrack.Priority = Enum.AnimationPriority.Action
  92. attackTrack.Looped = false
  93.  
  94. print("Анимация атаки найдена у", pirate.Name)
  95. print("AnimationId:", attackAnimation.AnimationId)
  96.  
  97. else
  98.  
  99. warn("У Pirate не найдена стандартная R6-анимация атаки!")
  100.  
  101. end
  102.  
  103. --------------------------------------------------
  104. -- ЗВУК МЕЧА
  105. --------------------------------------------------
  106.  
  107. local slashSound = nil
  108.  
  109. local handle = sword:FindFirstChild("Handle")
  110.  
  111. if handle then
  112. slashSound = handle:FindFirstChild("SwordSlash")
  113. end
  114.  
  115. --------------------------------------------------
  116. -- АТАКА
  117. --------------------------------------------------
  118.  
  119. local function attack()
  120.  
  121. local player = playerValue.Value
  122.  
  123. if not player then
  124. return
  125. end
  126.  
  127. local character = player.Character
  128.  
  129. if not character then
  130. return
  131. end
  132.  
  133. local targetHumanoid = character:FindFirstChildOfClass("Humanoid")
  134. local targetRoot = character:FindFirstChild("HumanoidRootPart")
  135.  
  136. if not targetHumanoid or not targetRoot then
  137. return
  138. end
  139.  
  140. if targetHumanoid.Health <= 0 then
  141. return
  142. end
  143.  
  144. local distance = (
  145. targetRoot.Position - rootPart.Position
  146. ).Magnitude
  147.  
  148. if distance > ATTACK_DISTANCE then
  149. return
  150. end
  151.  
  152. --------------------------------------------------
  153. -- НАЧИНАЕМ АТАКУ
  154. --------------------------------------------------
  155.  
  156. pirate:SetAttribute("IsAttacking", true)
  157.  
  158. -- Поворачиваемся к игроку
  159. local lookPosition = Vector3.new(
  160. targetRoot.Position.X,
  161. rootPart.Position.Y,
  162. targetRoot.Position.Z
  163. )
  164.  
  165. rootPart.CFrame = CFrame.lookAt(
  166. rootPart.Position,
  167. lookPosition
  168. )
  169.  
  170. --------------------------------------------------
  171. -- АНИМАЦИЯ
  172. --------------------------------------------------
  173.  
  174. if attackTrack then
  175. attackTrack:Play(0.05)
  176. end
  177.  
  178. --------------------------------------------------
  179. -- ЗВУК
  180. --------------------------------------------------
  181.  
  182. if slashSound then
  183. slashSound:Play()
  184. end
  185.  
  186. --------------------------------------------------
  187. -- МОМЕНТ ПОПАДАНИЯ
  188. --------------------------------------------------
  189.  
  190. task.wait(HIT_DELAY)
  191.  
  192. -- Проверяем игрока ещё раз
  193. character = player.Character
  194.  
  195. if character then
  196.  
  197. targetHumanoid = character:FindFirstChildOfClass("Humanoid")
  198. targetRoot = character:FindFirstChild("HumanoidRootPart")
  199.  
  200. if targetHumanoid and targetRoot and targetHumanoid.Health > 0 then
  201.  
  202. local newDistance = (
  203. targetRoot.Position - rootPart.Position
  204. ).Magnitude
  205.  
  206. if newDistance <= ATTACK_DISTANCE then
  207.  
  208. targetHumanoid:TakeDamage(DAMAGE)
  209.  
  210. end
  211.  
  212. end
  213.  
  214. end
  215.  
  216. --------------------------------------------------
  217. -- ЖДЁМ КОНЕЦ АНИМАЦИИ
  218. --------------------------------------------------
  219.  
  220. if attackTrack then
  221.  
  222. local length = attackTrack.Length
  223.  
  224. if length > 0 then
  225. task.wait(math.max(length - HIT_DELAY, 0))
  226. else
  227. task.wait(0.4)
  228. end
  229.  
  230. else
  231.  
  232. task.wait(0.4)
  233.  
  234. end
  235.  
  236. pirate:SetAttribute("IsAttacking", false)
  237.  
  238. end
  239.  
  240. --------------------------------------------------
  241. -- ОСНОВНОЙ ЦИКЛ
  242. --------------------------------------------------
  243.  
  244. while pirate.Parent do
  245.  
  246. if humanoid.Health <= 0 then
  247. break
  248. end
  249.  
  250. local player = playerValue.Value
  251.  
  252. if not player then
  253. task.wait(0.2)
  254. continue
  255. end
  256.  
  257. local character = player.Character
  258.  
  259. if not character then
  260. task.wait(0.2)
  261. continue
  262. end
  263.  
  264. local targetHumanoid = character:FindFirstChildOfClass("Humanoid")
  265. local targetRoot = character:FindFirstChild("HumanoidRootPart")
  266.  
  267. if not targetHumanoid or not targetRoot then
  268. task.wait(0.2)
  269. continue
  270. end
  271.  
  272. if targetHumanoid.Health <= 0 then
  273. task.wait(0.2)
  274. continue
  275. end
  276.  
  277. local distance = (
  278. targetRoot.Position - rootPart.Position
  279. ).Magnitude
  280.  
  281. if distance <= ATTACK_DISTANCE then
  282.  
  283. attack()
  284.  
  285. --------------------------------------------------
  286. -- СКОРОСТЬ АТАКИ
  287. --------------------------------------------------
  288.  
  289. local attackSpeed = math.max(
  290. attackSpeedValue.Value,
  291. 1
  292. )
  293.  
  294. local cooldown = 1 / attackSpeed
  295.  
  296. task.wait(cooldown)
  297.  
  298. else
  299.  
  300. task.wait(0.1)
  301.  
  302. end
  303.  
  304. end
Advertisement
Add Comment
Please, Sign In to add comment